1
votes

A little while ago, I was having problems with drag n' drop and CKEditor. Turns out there is a bug (not yet solved) with the editor preventing me from working with the dragstart event without reattaching it every time I destroy and recreate an instance of CKEditor. For more details on the bug, please refer to this question

By doing this, the dragstart event ends up firing more and more times each time I recreate an editor instance.

I would like to know if is there a way to detach the event as I am recreating the editor instance, so it fires only once (since I have to reattach it every time), just as a workaround until the bug is fixed.

I was suggested to do the following:

You can put: CKEDITOR.document.getById('contactList').on('dragstart', ... ); inside the plugin init method. After such change drag and drop should work, but dragstart will be fired multiple times. You can detach the dragstart event, before you attach it again end everything should work fine.

I have searched the docs and found nothing about it, so I'd be glad if anyone could help me.

Thank you.

1

1 Answers

1
votes

You can always keep the listener object reference, and remove it when it's no longer needed using removeListener method of object returned by on method.

See following example:

var editor = CKEDITOR.instances.editor1;
var myKeyListener = editor.on('key', function(){ console.log( 'key pressed' ); });
// Once you don't need the listener just call removeListener() method.
myKeyListener.removeListener();