Hi,
I want to close the active instance of ckeditor and also perform an ajax request if the user presses the escape key. I have implemented a little plugin that registeres a command named 'discard' for that purpose. Now I want to execute this command when escape is pressed.
My first try looked like this:
It bascially worked but caused a problem: The escape key cancels active ajax-requests in firefox, so the request inititiated by the discard-command was initially canceled. I couln't figure out how to prevent the keypress event bubbling up, so I tried a different approach:
This fixes the ajax-issue but still causes a javascript-error: 'iframe is null' in the function 'getSnapshotData'.
I guess that this has something to do with the editor trying to take a snapshot of its content after the keypress, which fails because the discard-command has already destroyed the editor by this time.
The discard-command itself is set to canUndo=false and therefore does not try to create Snapshots. I can verify this because the same command can also be called with a menu button, in which case this error does not occur. So it has to have something to do with the key press.
Any Ideas?
I want to close the active instance of ckeditor and also perform an ajax request if the user presses the escape key. I have implemented a little plugin that registeres a command named 'discard' for that purpose. Now I want to execute this command when escape is pressed.
My first try looked like this:
editor.keystrokeHandler.keystrokes[27]='discard';
It bascially worked but caused a problem: The escape key cancels active ajax-requests in firefox, so the request inititiated by the discard-command was initially canceled. I couln't figure out how to prevent the keypress event bubbling up, so I tried a different approach:
editor.on('key', function(e){ if(e.data.keyCode==27){ e.cancel(); e.editor.execCommand('discard'); } });
This fixes the ajax-issue but still causes a javascript-error: 'iframe is null' in the function 'getSnapshotData'.
I guess that this has something to do with the editor trying to take a snapshot of its content after the keypress, which fails because the discard-command has already destroyed the editor by this time.
The discard-command itself is set to canUndo=false and therefore does not try to create Snapshots. I can verify this because the same command can also be called with a menu button, in which case this error does not occur. So it has to have something to do with the key press.
Any Ideas?
Re: Closing editor on escape-key press
This works but I'm still looking for a cleaner solution. Isn't it possible to prevent the editor from taking a snapshot after the key event has been triggered?