如何在CKeditor中的异步回调中添加加载程序

时间:2019-07-30 08:36:49

标签: javascript asynchronous ckeditor

我正在使用CKEditor版本:“ 4.5.5”。

我创建了一个插件,用于插入来自后端的带有特定ulr的iframe。

为此,我有一个对话框弹出窗口,要求输入要发送到后端的ID,并等待响应。

问题是我有一个async命令发出了调用,但是CKEditor并不等待我的回调打印结果。它只是创建没有我的URL的iFrame。

CKEDITOR.plugins.add(pluginName, {
    requires: 'widget',    
    icons: pluginName,    
    init: function (editor) {    
      CKEDITOR.dialog.add(pluginName, this.path + 'dialogs/dialog.js');    
      editor.addCommand( 'loadoptions', ajaxCallback); //async ajax
      editor.widgets.add(pluginName, {
                //some configs...

             data: function (event) {
                var id = this.data.santillana_id //id del input
                if (id) {
                  var obj = {
                    id,
                    idcourse : window.idcurso,
                    container : this.element, 
                    that: this          
                  }
                  editor.execCommand('loadoptions', obj);    
                }
              },

      }

这里有异步ajax。

var ajaxCallback = {
exec: function( editor, obj ) {
  var cmd = this;
  debugger //I get here after click ok in the dialog window
  // Asynchronous operation below.
  blink.ajax('/xads/ajax.php?op=aasdawy&url=' + obj.id , function (response) {
    debugger  //I get here after a while...         

    editor.fire( 'afterCommandExec', ()=>{
      debugger // I never get here, error Cannot read property 'canUndo' of undefined
      return {
        name: 'loadoptions',
        command: cmd
      }
    });

    //I get here after a while... 
    if (response.includes("ERROR")) {
      alert(response.substring(5));
      return;
    } else {
      url = response.substring(2); //el sendOk me devuelve un OK en el response...
      container.data( 'url', url); 
    }
  })
},
async: true, // The command needs some time to complete after the exec function returns.
canUndo: false

};

我想要什么? 单击对话框窗口后,我要加载。等到我的Ajax回应我。

有什么主意吗?

0 个答案:

没有答案