ckeditor blur and dialog

≡放荡痞女 提交于 2019-12-11 08:35:06

问题


I have a blur function attached to my ckeditor like so

editor = CKEDITOR.instances.fck;
editor.on("blur",function(e){
    alert("hello");
});

you with me ?

now when I click on the flash button the editor blurs and causes the alert to show.

how to I stop that from happening and still get the alert to appear other times like when the user leave the editor area

thanks again


回答1:


As long as we're working on hacks, here's what I like to use to solve this problem. The key is that CKE uses iFrames for their drop-down type controls (color picker and background color, font size, font type)

 editor.on("blur", function(e) {
  if ($(document.activeElement).get(0).tagName.toLowerCase() != "iframe") {
      // your code here for "real" blur event
  }
});



回答2:


The blur event is firing when you click on a button like flash after the up click when the dialog is presented. The blur event that you want on happens right after mouse down outside the editor. This is dirty but by tracking the mouse state you can achieve your goal.

$(function() {
    var mouseState = 0;
    $(document).mousedown(function(){ mouseState = 1; });
    $(document).mouseup(  function(){ mouseState = 0; });

    var editor = CKEDITOR.instances.editor1;
    editor.on("blur", function(e) {
        if (mouseState == 1) console.log("blur");
    });
});



回答3:


I had this problem now as well.

My solution was to wrap the editor inside a holder, let's call it id="holder", and bind this event:

var isMouseOverEditor = false;
$('#holder').hover(function(){
  isMouseOverEditor = (e.type=='mouseenter' ? true : false);
});

Later at the on blur event of the editor:

editor.on("blur", function(e) {
  if (!isMouseOverEditor) return;
  // your code here for "real" blur event
});

It's not the best solution, but it's a nice workaround that can be used. It seems that the blur event of the editor is binded to the editor itself. Meaning that when the editing area is blured, the event fired.

Hope this helps anyone has this problem.



来源:https://stackoverflow.com/questions/2601105/ckeditor-blur-and-dialog

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!