Could not fire ckeditor drop event

I can get the drop event triggered using basic javascript and html:

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

The above works just fine. However, when I omit the reference to the ckeditor object covering the textarea field, absolutely nothing happens:

  $(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");
      });
  })

This is the ckeditor object in the console output:

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 

What can i do wrong?

UPDATE:

I was able to get the dragoon and dragoon to work. But still, drops and dragdrops do nothing:

  $(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");
          });
      });


  })
+4
source share
1 answer

Finally, he worked. The Drop event was recognized, but not dragdrop. The latter did not cause dismissal.

  $(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);
          })
      });


  })
+1
source

Source: https://habr.com/ru/post/1570379/


All Articles