Refocus CKEditor at correct cursor position

Bavacrete

New Member
I am building a CMS system, where I use jQuery and CKEditor for editing content inline. When an editor is blurred, the user is requested to confirm that he/she wants to discard the edits. If 'no' is chosen, the blur event should be cancelled and the editor retain focus without changing the cursor position. Since it seems to me that this is not possible, I try to refocus the editor after the blur is done. The following code snippet is from the blur event handler:\[code\]var $this = $(this);if (confirm('Discard your changes?')) { $this.html($this.data('previous'));} else { // Optimally prevent the blur event, but alternatively // reintroduce focus at correct position... $this.data('editor').focus();}\[/code\]Note that the \[code\]focus\[/code\] call is done on the editor instance contained in \[code\]$this.data('editor')\[/code\], but the result seems to be the same as if I do it directly on \[code\]$this\[/code\].The problem with this solution is that although it reintroduces focus, the cursor is now positioned at the beginning of the text, which is very unintuitive and annoying to the end user, who thought nothing changed. On the other hand, just giving up focus is not an option, since I would not like the user to be able to prevent resetting content and then go on to make other changes, thinking that the changes are persisted.Therefore I would like a solution, where I can either prevent the blur altogether, or reintroduce the cursor at it's last position.
 
Back
Top