听Aloha编辑“aloha-smart-content-changed”活动?

时间:2012-07-02 23:10:25

标签: javascript events aloha-editor

根据Aloha Editor文档,你可以听取“aloha-smart-content-changed”事件的帮助,比如将数据保存到你正在使用的任何持久性机制中。这是我想要做的一个例子:

<html>
  <head>
    <title>Aloha Event Testing</title>
    <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js"></script>
    <script src="http://cdn.aloha-editor.org/current/lib/aloha.js" data-aloha-plugins="common/format, common/list, common/link, common/highlighteditables"></script>
    <link href="http://cdn.aloha-editor.org/current/css/aloha.css" rel="stylesheet" type="text/css" />
    <script type="text/javascript">
      Aloha.ready( function() {
        var $ = Aloha.jQuery;
        $('.editable').aloha();
      });
      $(document).ready(function() {
        $('.editable').bind('aloha-smart-content-changed', function() {
          console.log('Aloha smart event handled.');
        });
      });
    </script>
  </head>
  <body>
    <div class="editable"></div>
  </body>
</html>

但是处理程序永远不会触发。与Aloha合作过的人是否知道如何正确地听取这个事件?

1 个答案:

答案 0 :(得分:8)

哇,关于这方面的文件非常糟糕。但我想我得到了它的工作。看起来您将Aloha.ready()方法中的事件处理程序绑定到Aloha对象本身。

Aloha.ready( function() {
        var $ = Aloha.jQuery;
        $('.editable').aloha();

    Aloha.bind('aloha-smart-content-changed', function(event, editable) {
          console.log('Aloha smart event handled.');
        });        
});

找到关于它here的更多信息,这是我找到event being bound的示例。

还在 jsfiddle here

中对此进行了测试

希望有所帮助

相关问题