I'm writing some plug-ins for a site that I'm working on, I followed the guides on how to create a plug-in, and everything seems to be working fine, except I can't figure out how to properly destroy an instance of the editor from within the plug-in. One of the plug-ins is a simple "Cancel" button, all it should do is destroy the editor. Here's what I've got:
When I click the cancel button, the editor does get destroyed but I get a Javascript error that says "M is null" on line 100 of ckeditor.js and the rest of my code is ignored (in the case of some of my other plug-ins where there is more code beyond the destroy)
If anyone has any suggestions to fix this, I'd really appreciate it. I've Googled this and searched the forums, but I've had no luck. I'm stuck and I really need to find a way to fix it.
Thanks
Brian
CKEDITOR.plugins.add( 'cancel', { init: function( editor ) { editor.addCommand( 'cancelInstruction', { exec : function( editor ) { if (editor){ editor.destroy(); } } }); editor.ui.addButton( 'Cancel', { label: 'Cancel', command: 'cancelInstruction' } ); } } );
When I click the cancel button, the editor does get destroyed but I get a Javascript error that says "M is null" on line 100 of ckeditor.js and the rest of my code is ignored (in the case of some of my other plug-ins where there is more code beyond the destroy)
If anyone has any suggestions to fix this, I'd really appreciate it. I've Googled this and searched the forums, but I've had no luck. I'm stuck and I really need to find a way to fix it.
Thanks
Brian
Re: Destroy editor in plug in
Hi Brian,
I was having a similar problem. Since your exec function is being called from within the editor, it is natural that after the function returns, the various calling functions up the stack might be expecting the editor to still exist, and so your button's exec function should leave the editor intact until things have settled down:
If you are also using the onchange plugin (like I was), then you have to deal with how onchange calls its target after a delay of 100ms (to collect changes into batches), because the editor will be destroyed by the time the target is called, which will probably interfere with whatever your target is trying to do! To deal with this, use the new version of onchange, and/or see thread 23605.
-Matt
Re: Destroy editor in plug in
Thank you !!
I had to stop working on this project for a while, but I'm back into it now, and just wanted to say this worked perfectly for me!
Thanks for your help!
Re: Destroy editor in plug in
-Matt