ckeditor drop事件没有被解雇

时间:2015-01-08 00:21:00

标签: javascript ckeditor

我能够使用基本的javascript和html:

来解决drop事件
<div class="drop" style="width: 200px; height: 200px; background: red;"></div>
<a href="#" title="Drag Me">Drag Me</a>

<script>
    $('.drop').on('dragenter',function(e){
        e.preventDefault();
    })
    $('.drop').on('dragover',function(e){
        e.preventDefault();
    })
    $('.drop').on('drop dragdrop',function(){
        console.log("Element was dropped");
    });
</script>

以上工作完美无缺。但是,当我在包含textarea字段的ckeditor对象上放置一个链接时,绝对没有任何反应:

  $(document).ready(function(){
      var ckeditor = CKEDITOR.instances.quickdoc_editor;
      console.log(ckeditor);
      ckeditor.on('dragenter',function(e){
          e.preventDefault();
      })
      ckeditor.on('dragover',function(e){
          e.preventDefault();
      })
      ckeditor.on('drop dragdrop',function(){
          console.log("Element was dropped");
      });
  })

这是控制台输出中的ckeditor对象:

a {element: CKEDITOR.dom.element, elementMode: 1, name: "quickdoc_editor", _: Object, commands: Object…}_: ObjectactiveEnterMode: 1activeFilter: CKEDITOR.filteractiveShiftEnterMode: 2addMenuGroup: function (b,a){m[b]=a||100}addMenuItem: function (a,c){m[c.group]&&(l[a]=new CKEDITOR.menuItem(this,a,c))}addMenuItems: function (a){for(var c in a)this.addMenuItem(c,a[c])}blockless: falsecommands: Objectconfig: dcontainer: CKEDITOR.dom.elementcontextMenu: CKEDITOR.plugins.contextMenu.CKEDITOR.tools.createClass.$dataProcessor: CKEDITOR.htmlDataProcessordocument: CKEDITOR.dom.documentelement: CKEDITOR.dom.elementelementMode: 1enterMode: 1filter: CKEDITOR.filterfocusManager: CKEDITOR.focusManagergetClipboardData: function (a,d){function c(a){a.removeListener();a.cancel();d(a.data)}function j(a){a.removeListener();a.cancel();i=!0;d({type:f,dataValue:a.data})}function l(){this.customTitle=a&&a.title}var g=!1,f="auto",i=!1;d||(d=a,a=null);b.on("paste",c,null,null,0);b.on("beforePaste",function(a){a.removeListener();g=true;f=a.data.type},getColorFromDialog: function (c,f){var d=function(a){this.removeListener("ok",d);this.removeListener("cancel",d);a="ok"==a.name?this.getValueOf("picker","selectedColor"):null;c.call(f,a)},e=function(a){a.on("ok",d);a.on("cancel",d)};b.execCommand("colordialog");if(b._.storedDialogs&&getMenuItem: function (a){return l[a]}id: "cke_1"instanceReady: truekeystrokeHandler: CKEDITOR.keystrokeHandlerlang: dlangCode: "en"loaded: truemode: "wysiwyg"name: "quickdoc_editor"plugins: ObjectreadOnly: falseremoveMenuItem: function (a){delete l[a]}resetUndo: function (){b.reset();a.fire("saveSnapshot")}shiftEnterMode: 2status: "ready"tabIndex: 0templates: Objecttitle: "Rich Text Editor, quickdoc_editor"toolbar: Array[15]toolbox: uui: CKEDITOR.uiundoManager: gwindow: CKEDITOR.dom.window__proto__: CKEDITOR.editor.CKEDITOR.editor 

我可能做错了什么?

更新:

我能够让dragenter和dragover工作。但仍然下降和拖拽什么都不做:

  $(document).ready(function(){
      CKEDITOR.on('instanceReady', function (ev) {

          console.log(ev.editor);
          console.log(ev.editor.document);

          ev.editor.document.on('dragenter',function(ev){
              console.log("Yep we get here")
              ev.data.preventDefault(true);
          })

          ev.editor.document.on('dragover',function(ev){
              console.log("Yep we get here too")
              ev.data.preventDefault(true);
          })
          ev.editor.document.on('drop dragdrop',function(){
              console.log("Element was dropped");
          });
      });


  })

1 个答案:

答案 0 :(得分:1)

终于搞定了。删除事件已被识别,但没有被删除。后者不会被解雇。

  $(document).ready(function(){
      CKEDITOR.on('instanceReady', function (ev) {

          ev.editor.document.on('drop',function(){
              console.log("Element was dropped");
          });

          ev.editor.document.on('dragenter',function(ev){
          //    ev.data.preventDefault(true);
          })

          ev.editor.document.on('dragover',function(ev){
          //    ev.data.preventDefault(true);
          })
      });


  })