- Start by creating a folder called ajaxSave in the CKEditor\Plugins folder.
- Create a new JavaScript file called plugin.js in the ajaxSave folder
- Paste the following code:
(function() { var saveCmd = { modes: { wysiwyg: 1, source: 1 }, exec: function(editor) { showSaveDialog(); // my custom dialog function for doing the save. Uses JQuery UI } }; var pluginName = 'ajaxSave'; CKEDITOR.plugins.add(pluginName, { init: function(editor) { var command = editor.addCommand(pluginName, saveCmd); editor.ui.addButton('AjaxSave', { label: editor.lang.save, command: pluginName, icon: "/ckeditor/plugins/ajaxsave/save.png" }); } }); })();
- Notice the
icon: "/ckeditor/plugins/ajaxsave/save.png"
line? So far I haven't figured out how to reference the default save icon in the skin file so I had to make my own and store it in the same directory as the plugin. I did this by opening the skin icons.png file I was interested in a chopping out the save icon. - You have to tell CKEditor to load the plug-in. You can do this in your config section, either during CKEditor creation, or in a custom.js config file you load during CKEditor creation.
The config property looks like this:
extraPlugins : 'ajaxSave' - Lastly, you need to reference the plug-in in the toolbar. For example, in my CKConfig.js file that I load during editer creationg I have this
config.toolbar_Default = [ ['AjaxSave'], ['Cut', 'Copy', 'Paste', . . . .
That's it. At first it looks quite difficult, but once you wrap your head around all the bits it starts to make sense.
For those interested, I am pasting my function that creates my CKEditor instances. This is a work in process and I'm not even close to being done, but I figured it might help someone out there. I'm using the JQuery adapter to load CKEditor.
// load the CKEDITOR in the given div function loadCKEditor(Div) { var CSSFiles = []; CSSFiles[0] = "https://designer.wsu.edu/template/css2.aspx?key=" + $("#hfSiteKey").val(); CSSFiles[1] = "https://files.ba.wsu.edu/styles/additions" + $("#hfAdditionsVerNum").val() + ".min.css"; CSSFiles[2] = "https://files.ba.wsu.edu/styles/PageEditor_CKEditor.css"; $('#' + Div).ckeditor(function() { // this is the callback, // edMain, edSecondary and edAdditional are public vars at the top of the js file, this will assign them the instance of the editor we just created so I can manipulate it later. Note, I'm creating three different editors by calling loadCKEditor 3 times later on. if (Div === 'edMain') { edMain = $('#edMain').ckeditorGet(); } if (Div === 'edSecondary') { edSecondary = $('#edSecondary').ckeditorGet(); } if (Div === 'edAdditional') { edAdditional = $('#edAdditional').ckeditorGet(); } var e = $('#' + Div).ckeditorGet(); $(window).resize(function() { var eH = $(window).height() - winHeightSub; e.resize(e.config.width, eH); }); fckCompleteCount++; if (fckCompleteCount == 3) // since this gets' called for each FCKeditor_OnComplete (3 times) only want to load when compleatly done. { if ($("#hfIsDraft").val() == "true") // there is a draft to load, show the chooser dialog { // set AutoSave = false so it doesn't try to save when dialog is open AutoSave = false; $("#divLoadDraft").dialog("open"); } else { load(false); } // no draft to load, just load the main page text } }, { // settings customConfig: '/Masterpages/myFCKConfig.js', toolbarCanCollapse: false, toolbar: 'Default', sharedSpaces: { top: 'fckToolBar' }, bodyId: 'content', resize_enabled: false, contentsCss: CSSFiles, extraPlugins : 'ajaxSave', height: EditorHeight }); }
3 comments:
Hi, I am trying to do just that, but seems like ckeditor newest version syntax is a bit diferent than your sample.
if you have this code for ckeditor latest version I will be glad to have it :)
thx
Jay
Don't we need showSaveDialog(); to make it work?
Я решил проблему так:
CKEDITOR.on('instanceReady', function () { $('#cke_9').attr('onclick', 'saveContent()'); });
Где cke_9 это ид кнопки сохранить на панели.
Post a Comment