2010-07-28 10 views

उत्तर

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

आप सिर्फ एक उदाहरण के लिए बचाने आदेश ओवरराइड करना चाहते हैं, तो आप निम्न कोड की कोशिश कर सकते हैं:

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

यह किसी भी CKEditor आदेश के लिए काम करना चाहिए।

+0

यदि आप इस तरह के निष्पादन फ़ंक्शन को ओवरराइट करते हैं तो इसे किसी भी पैरामीटर के बिना बुलाया जाएगा। लेकिन चूंकि आपके पास आमतौर पर बाहरी दायरे में 'संपादक' चर होता है, फिर भी आप इसके साथ काम कर सकते हैं। बस अपनी फ़ंक्शन परिभाषा में 'संपादक' पैरामीटर को छोड़ना याद रखें क्योंकि यह अन्यथा आपके स्कॉप्ड 'एडिटर' चर को ओवरराइट करेगा। – flu

10

current top answer मेरे लिए टूलबार समूह को गड़बड़ कर दिया (अंत में सहेजें बटन डालें), और other answer ckeditor v4 में काम नहीं किया।

एचटीएमएल:

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

जावास्क्रिप्ट: रद्द करने योग्य होने के लिए

<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

बहुत अच्छा उदाहरण, धन्यवाद: डी – Zombyii

+0

यह मेरे लिए काम किया। – 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

CKEditor 4 में, बचाने प्लगइन का मतलब है

यहाँ कैसे CKEditor 4 में यह करने के लिए है । यदि अनिश्चित है, तो कोई भी source पर हमेशा देख सकता है। आप घटना को रद्द करने और अपने स्वयं के तर्क इस उदाहरण में की तरह, एक हैंडलर में आवेदन कर सकते हैं:

//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) 
}); 

मैं एक नया आदेश बनाने और इसके साथ डिफ़ॉल्ट की जगह के खिलाफ सलाह देंगे, के रूप में यह एक अनावश्यक समाधान नहीं है।

संबंधित मुद्दे