Listening to the Aloha Editor “aloha-smart-content-changed” Event?

风流意气都作罢 提交于 2019-12-08 19:53:32

问题


Accoriding to the Aloha Editor docs you can listen for the "aloha-smart-content-changed" event for help in, say, saving the data to whatever persistence mechanism you are using. Here is an example of what I am trying to do:

<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>

But the handler never fires. Would anyone that has worked with Aloha know how to properly listen for the event?


回答1:


Wow, the documenation on this was quite poor. But i think i got it to work. It looks like you bind the event handlers inside the Aloha.ready() method and to the Aloha object itself.

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

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

Found a little bit more info about it here and this is where i found an example of an event being bound.

Also tested this in jsfiddle here

Hope that helps



来源:https://stackoverflow.com/questions/11302385/listening-to-the-aloha-editor-aloha-smart-content-changed-event

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!