CKEditor plugin to close editor

Posted by David Lawson on Stack Overflow See other posts from Stack Overflow or by David Lawson
Published on 2010-12-31T00:33:37Z Indexed on 2011/01/08 1:53 UTC
Read the original article Hit count: 536

Filed under:
|

The problem with destroying the editor from within a plugin, is that certain code tries to use the editor after the destructive plugin code, when in fact the editor is no longer there, causing errors and instability.

I have come up with the following code for a plugin which closes the editor using both async:true and setTimeout:

 var cancelAddCmd =
 {
  modes : { wysiwyg:1, source:1 },
  async: true,
  exec : function( editor )
  {
   if(confirm('Are you sure you want to cancel editing and discard all content?')) setTimeout(function() { editor.destroy(); }, 100);
  }
 };

The problem I see is that it uses a dodgy setTimout call that would likely have mixed results depending on the computer's speed of execution - 100ms might not have passed by the time it would be OK to destroy the editor.

Is there a proper way to destroy the editor from within a plugin? Even with async: true; and no setTimeout errors are created.

Maybe a possible solution would be to stop any existing/any more code related to the editor from running afterwards, if possible?


I have tried using events, like on('afterCommandExec', function(){ editor.destroy(); }) and some other events, but that hasn't helped much... doesn't seem like there is an event for when the editor has jumped out of its stack call for handling the button.

And there is no way to stop execution by disposing of the CKEditor instance more properly?

© Stack Overflow or respective owner

Related posts about JavaScript

Related posts about ckeditor