CKEditor:如何破坏实例上的模糊? [英] CKEditor: HowTo destroy instance on blur?

查看:123
本文介绍了CKEditor:如何破坏实例上的模糊?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个html页面,其上有多个 div 元素。每次用户点击 div ,它会立即被替换为 CKEditor

  $('。editable')click(function(){
editor = CKEDITOR.replace(this);
});



现在,如果CKEditor实例失去了它的焦点(blur事件),我需要发布内容一个单独的脚本通过ajax(如果有改变)和销毁这个实例:

  $('editable' (){
editor = CKEDITOR.replace(this);
editor.on('blur',function(e)
{
if(e.editor.checkDirty )
//使用e.editor.getData()获取数据并做一些ajax魔术

e.editor.destroy();
});
} );

但是这个例子不行,因为我不知道为什么, destory()将在 checkDirty()之前调用。

解决方案

如果你把 destroy() if()语句中?你可以有一个else子句,如果没有更改,则调用destroy。如果有变化,你可以在数据传输后在if子句中调用 destroy()

  $('。editable')。click(function(){
editor = CKEDITOR.replace(this);
editor.on e)
{
if(e.editor.checkDirty()){
//使用e.editor.getData()获取数据并做一些ajax魔术
if(dataTransferComplete ){
e.editor.destroy();
}

} else {
e.editor.destroy();
}
});
});

或者你可以在调用 destroy()之前检查一个变量。在数据传输完成后,在else子句中设置该变量为true,那么 destroy()将不会被调用,直到您检查更改并转移任何更新的数据。

  $('。editable')。click(function(){
editor = CKEDITOR。 replace(this);
editor.on('blur',function(e)
{
var okToDestroy = false;

if(e.editor.checkDirty ()){
//使用e.editor.getData()获取数据并做一些ajax魔术
okToDestroy = true;
} else {
okToDestroy = true;
}

if(okToDestroy)
e.editor.destroy();

});
});

这是一个大纲,我没有测试的代码,但如果显示的概念。 p>

好,

Joe


i have a single html page with mulitple div elements on it. Each time a user clicks on on a div, it is replaced with an CKEditor on the fly:

$('.editable').click(function() {
    editor = CKEDITOR.replace(this);
});

Now, if the CKEditor instance loses its focus (blur event), i need to post the content to a separate script via ajax (if something changed) and destroy this instance:

$('.editable').click(function() {
    editor = CKEDITOR.replace(this);
    editor.on('blur', function(e)
    {
        if (e.editor.checkDirty())
           // get data with e.editor.getData() and do some ajax magic 

        e.editor.destroy();
    });
});

But this example won't work because, i don't know why, destory() will be called before checkDirty(). How can i get this working?

解决方案

How about if you put the destroy() inside the if() statement? You could have an else clause that invokes destroy if nothing has changed. If something has changed, you can invoke destroy() within the if clause once the data has been transfered.

$('.editable').click(function() {
  editor = CKEDITOR.replace(this);
  editor.on('blur', function(e)
  {
    if (e.editor.checkDirty()) {
       // get data with e.editor.getData() and do some ajax magic
       if ( dataTransferComplete ) {
         e.editor.destroy();
       }

     } else {
       e.editor.destroy();
     }
  });
});

Or you could check a variable before invoking destroy(). Set that variable to true after the data transfer has been completed and in the else clause, that way destroy() won't be invoked until you've checked for changes and transfered any updated data.

$('.editable').click(function() {
  editor = CKEDITOR.replace(this);
  editor.on('blur', function(e)
  {
    var okToDestroy = false;

    if (e.editor.checkDirty()) {
       // get data with e.editor.getData() and do some ajax magic
       okToDestroy = true;
     } else {
       okToDestroy = true;
     }

    if (okToDestroy )
      e.editor.destroy();

  });
});

This is an outline, I haven't tested the code, but if shows the concept.

Be Well,
Joe

这篇关于CKEditor:如何破坏实例上的模糊?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆