2010-07-28 31 views

cevap

4
CKEDITOR.plugins.registered['save']= 
    { 
    init : function(editor) 
    { 
     var command = editor.addCommand('save', 
      { 
       modes : { wysiwyg:1, source:1 }, 
       exec : function(editor) { 
       //YOUR CODE 
       } 
      } 
     ); 
     editor.ui.addButton('Save',{label : 'YOUR LABEL',command : 'save'}); 
    } 
    } 
2

, aşağıdaki kodu deneyebilirsiniz:

var editor = $('#myTextarea').ckeditorGet(); // Retrieving CKeditor instance with jQuery 
editor.getCommand('save').exec = function(editor) { 
    // Do whatever you need to 
    ... 
    return true; 
}; 

Bu, herhangi bir CKEditor komutu için çalışmalıdır.

+0

Bu gibi exec işlevinin üzerine yazarsanız, herhangi bir parametre olmadan çağrılır. Ancak, normalde normalde 'editor' değişkenine sahip olduğunuzdan, hala onunla çalışabilirsiniz. Sadece işlev tanımındaki 'editor' parametresini dışarıda bırakmayı unutmayın, çünkü aksi takdirde scoped' editor' değişkenini geçersiz kılar. – flu

10

current top answer, araç çubuğu gruplandırmasını benim için bozdu (kaydetme düğmesinin sonuna koydu) ve other answer, ckeditor v4'te çalışmadı.

html:

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

javascript: CKEditor 4'te

<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 editor = ev.editor; 
     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

çok iyi bir örnek, teşekkür ederim: D – Zombyii

+0

Bu benim için çalıştı. – devman81

0
function configureEditor(id) { 
    var editor = CKEDITOR.replace(id); 
    editor.on("instanceReady", function() { 
     // overwrite the default save function 
     editor.addCommand("save", { 
      modes: { wysiwyg: 1, source: 1 }, 
      exec: function() { 
       // get the editor content 
       var theData = editor.getData(); 
       alert("insert your code here"); 
      } 
     }); 
     editor.ui.addButton('Save', { label: 'My Save', command: 'save', enabled: 'true' }); 
     var saveButton = $('#cke_' + id).find('.cke_button__save'); 
     saveButton.removeClass('cke_button_disabled'); 
    }); 
} 
0

, kaydetmek eklenti kastedilmektedir iptal olması

İşte CKEditor 4 bunu yapmak için nasıl . Emin değilseniz, her zaman source'a bir göz atabilirsiniz. Sen etkinliği iptal etme ve bu örnekte olduğu gibi, bir işleyici kendi mantığı uygulayabilirsiniz:

//assuming editor is a CKEDITOR.editor instance 
editor.on('save', function (event) { 
    event.cancel(); 
    //your custom command logic 
    //(you can access the editor instance through event.editor) 
}); 
o gereksiz geçici çözüm olduğu gibi, yeni bir komut oluşturarak ve onunla varsayılan yerine karşı tavsiye ediyorum

.

İlgili konular