I'm using the lastest version of CKEditor, and there still seem to be issues with the blur event. (I've seen a lot of posts about this wqith 3.x.)
I'm loading these versions from CDN:
.script("//cdn.ckeditor.com/4.4.6/full-all/ckeditor.js")
.script("//cdn.ckeditor.com/4.4.6/full-all/adapters//jquery.js")
I'm seeing the blur event firing when I click on the toolbar itself (not one of the buttons/controls within it), and also when a dialog opens.I'm working in KnockoutJS, but I don't think it makes any difference in this case.
Here's some rough stuff I've been fiddling with. The issue is that the blur function fires wen I don't expect it to.
// Wire up the blur event to ensure our observable is properly updated
CKEDITOR.instances[elementId].focusManager.blur = function() {
// Hack to handle clicking into the editor or on the toolbar buttons
var activeElementName = $(document.activeElement).get(0).tagName.toLowerCase();
var activeElementClass = $(document.activeElement).get(0).className.toLowerCase();
console.log("activeElementName: " + activeElementName + " activeElementClass: " + activeElementClass);
// if(!CKEDITOR.instances[elementId].focusManager.hasFocus) {
if (activeElementName !== "iframe" && activeElementClass.indexOf("cke_dialog") === -1) {
// || activeElementClass.substr(0, 4) !== "cke_") {
var observable = valueAccessor();
observable($("#" + elementId).val());
if (typeof options.blurFunction === "function") {
options.blurFunction(options.dataItem());
}
}
};
I'm having a devil of a time trying to come up with a reliable test for whether a dialog is open/opening. The only one I'm dealing with right now is the "Link" dialog, but I'm guessing the same issue will apply to others.
What I'm trying to do is save the text when the user truly blurs out of the editor. That would mean leaving it to move to some other element in the page, but not by clicking on anything in the toolbar, which means they are still working on the text.
Is this a known issue? I see a lot of posts out there where people have come up with hacks, but none look reliable to me. I'm happy to provide more information if it would be helpful.
Thanks,
M.
p.s. I've also added this to an old thread here.