代码之家  ›  专栏  ›  技术社区  ›  Z. Zlatev

tinymce:tinymce.dom.selection事件

  •  1
  • Z. Zlatev  · 技术社区  · 15 年前

    有人在tinymce中使用tinymce.dom.selection类吗?尝试将函数应用于dom.selection.onBeforeSetContent或onSetContent失败。文档显示以下语法:

    event_callback(<tinymce.dom.Selection> ed, <Object> o)
    

    它的实现没有一个很好的例子。我很着急,想放弃。

    到目前为止我已经尝试过的是:

    $('#tinyMce').tinymce({
       ...
       setup: function(ed) {
          ed.dom.Selection.onSetContent.add(function(se,o){...});
       }
    });
    

    失败,显示“ed.dom is undefined”。我也尝试过:

    $('#tinyMce').tinymce({
       ...
       init_instance_callback : "CustomInitInstance"
    });
    
    function CustomInitInstance(inst){
     //inst.dom.Selection.on... fails with "inst.dom is undefined"
     tinymce.dom.Selection.onBeforeSetContent.add(function(se,o){...}); // fails with "tinymce.dom.Selection.onBeforeSetContent is undefined"
    }
    
    2 回复  |  直到 11 年前
        1
  •  2
  •   user229044    14 年前
    ed.selection.onBeforeSetContent.add(function(se, o) {
            alert(o.content);
    });
    

    如果将要插入的内容粘贴到第一个示例中,上面的内容将触发一个包含要插入内容的警报。

        2
  •  4
  •   makedon    14 年前
    $('#tinyMce').tinymce({
       ...
       setup: function(ed) {
          ed.onInit.add(function(ed, o) {
            ed.selection.onBeforeSetContent.add(function(se,o){
              alert(o.content);
            });
          });
       }
    });
    

    它在呼叫前工作 ed.selection.setContent('my text')

    alert (o.content); // display  'my text'