开发者

How can I listen for the drag/drop event in CKeditor?

开发者 https://www.devze.com 2023-01-17 12:09 出处:网络
I\'m building an application that requires the user to drag and drop html elements onto a CKeditor instance. I need to listen for the drop event so I can take action to remove the element that was dro

I'm building an application that requires the user to drag and drop html elements onto a CKeditor instance. I need to listen for the drop event so I can take action to remove the element that was dropped onto the editor. I see that there's a 'paste' event, but it's not triggered by the drop.

Here's my simple test, using the CKeditor jquery adapter:

// set up instance
$('#editor1').ckeditor();
var editor = $('#editor1').ckeditorGe开发者_高级运维t();

// this gets a list of all events that you can listen for
console.log(editor._.events);

// here's how you listen for an event
editor.on("someEvent", function(e) {
  console.log(e); 
});

I can't find anything in the documentation to shed light on this.

Any ideas?


See http://dev.ckeditor.com/ticket/5692


If possible, assign a unique attribute to the items you're dropping into the editor, then listen for selectionChange

editor.on('selectionChange', hookNewObjects);

Keep a register of all the objects you've already dropped and take action on new ones only.

You can access the recently dragged element using

ev.editor.getSelection().getStartElement().$
0

精彩评论

暂无评论...
验证码 换一张
取 消