2011-01-06 9 views
1

私はこのトピックで書かれた手順に従っていました:CKEditor, AJAX Save AjaxSaveボタンを押すと、カスタムの 'saved.ckeditor'イベントを発生させようとしました。しかし、私は成功しなかった。CKeditor save event

CKEditorバージョン/プラグイン/ ajaxsave/plugin.js:私は取得または機能のエディタのデータを設定した場合

(function(){ 
    var saveCmd = 
     { 
      modes : { wysiwyg:1, source:1 }, 
      exec : function(editor) 
      { 
       editor.fire('saved.ckeditor'); 
       $(editor).trigger('saved.ckeditor', editor.getData()); 
       alert(editor.getData()); 
      } 
      } 
    var pluginName = 'ajaxsave'; 
    CKEDITOR.plugins.add(pluginName, 
    { 
     init : function(editor) 
     { 
      var command = editor.addCommand(pluginName, saveCmd); 
      command.modes = { wysiwyg : !!(editor.element.$.form) }; 
      editor.ui.addButton('AjaxSave', 
      { 
       label : editor.lang.save, 
       command : pluginName, 
       className : 'cke_button_save' 
      }); 
     } 
    }); 
})(); 

、取得および設定のイベントが自動的に起動されます。しかし、私は "getData.ckeditor"イベントを手動で起動することさえできませんでした。

ヒント?

他のもの:最後に保存してからエディタの内容が変更されていない場合は、どうすればボタンを無効にできますか(汚れていません)。

+0

jqueryアダプタでは、これを実行します(少なくとも主に):var a = window.jQuery; a.extend(a.fn、{ckeditorGet:function(){...}}); var e = a(this); e.trigger( 'setData.ckeditor'、[j]); – BTakacs

答えて

0

回避策があります。

window.onload = function() 
{ 
    var ckparams={width: 500, height: 400, resize_enabled:false, extraPlugins: 'ajaxsave',toolbar:[['AjaxSave','Source','-','Bold','Italic','Underline','-','Undo','Redo','-','Find','Replace','-','SelectAll','-','SpellChecker','Scayt','-','About']]}; 
    //CKEDITOR.replace('editor', ckparams); 
    var editor = $('textarea.editor').ckeditor(ckparams); 
    $(editor).bind('setData.ckeditor', function() { 
     //do what I want 
    }); 
}; 

を...と、ボタンが押されたときに、その現在の値を使用してデータを設定します:

var saveCmd = 
    { 
    modes : { wysiwyg:1, source:1 }, 
    exec : function(editor) 
    { 
     editor.setData(editor.getData()); 
    } 
} 

この方法は、少なくとも私は、設定されたイベントに耳を傾けることができ、社外

イベントが発生しました... 手作業で外部からコンテンツを設定するときは注意してください。

0

exec()関数を終了する必要があります

(function() { 

    var saveCmd = { 
     modes:{wysiwyg:1,source:1 }, 
     readOnly: 1, 

     exec: function(editor) { 
      var data = editor.getData(); 
      console.info(data); 
     } 
    }; 

    var pluginName = 'ajaxSave'; 

    // Register a plugin named "save". 
    CKEDITOR.plugins.add(pluginName, { 
     lang: 'af,ar,bg,bn,bs,ca,cs,cy,da,de,el,en-au,en-ca,en-gb,en,eo,es,et,eu,fa,fi,fo,fr-ca,fr,gl,gu,he,hi,hr,hu,is,it,ja,ka,km,ko,ku,lt,lv,mk,mn,ms,nb,nl,no,pl,pt-br,pt,ro,ru,sk,sl,sq,sr-latn,sr,sv,th,tr,ug,uk,vi,zh-cn,zh', // %REMOVE_LINE_CORE% 
     icons: 'save', // %REMOVE_LINE_CORE% 
     init: function(editor) { 

      // Save plugin is for replace mode only. 
      if (editor.elementMode != CKEDITOR.ELEMENT_MODE_REPLACE) return; 

      editor.ui.addButton && editor.ui.addButton('Save', { 
       label: editor.lang.save.toolbar, 
       command: pluginName, 
       toolbar: 'document,10' 
      }); 
     } 
    }); 
})(); 

、あなたがやりたい

config.extraPlugins = 'ajaxSave'; 
0

あなたが定期的に保存ボタンの機能を編集することができますconfig.jsの中にプラグインを有効にすることを忘れないでください:

HTML:

<textarea id="CKEditor1"></textarea> 

のjavascript:

<script> 
    // Need to wait for the ckeditor instance to finish initialization 
    // because CKEDITOR.instances.editor.commands is an empty object 
    // if you try to use it immediately after CKEDITOR.replace('editor'); 
    CKEDITOR.on('instanceReady', function (ev) { 

     // Create a new command with the desired exec function 
     var overridecmd = new CKEDITOR.command(editor, { 
      exec: function(editor){ 
       // Replace this with your desired save button code 
       alert(editor.document.getBody().getHtml()); 
      } 
     }); 

     // Replace the old save's exec function with the new one 
     ev.editor.commands.save.exec = overridecmd.exec; 
    }); 

    CKEDITOR.replace('CKEditor1'); 

</script> 
+0

私のために働いていない - 保存ボタンを押しても以前のようにフォームがポストされる。 – HerrimanCoder