bgneal@45: /** bgneal@183: * editor_plugin_src.js bgneal@45: * bgneal@183: * Copyright 2009, Moxiecode Systems AB bgneal@183: * Released under LGPL License. bgneal@183: * bgneal@183: * License: http://tinymce.moxiecode.com/license bgneal@183: * Contributing: http://tinymce.moxiecode.com/contributing bgneal@45: */ bgneal@45: bgneal@45: (function() { bgneal@45: tinymce.create('tinymce.plugins.Save', { bgneal@45: init : function(ed, url) { bgneal@45: var t = this; bgneal@45: bgneal@45: t.editor = ed; bgneal@45: bgneal@45: // Register commands bgneal@45: ed.addCommand('mceSave', t._save, t); bgneal@45: ed.addCommand('mceCancel', t._cancel, t); bgneal@45: bgneal@45: // Register buttons bgneal@45: ed.addButton('save', {title : 'save.save_desc', cmd : 'mceSave'}); bgneal@45: ed.addButton('cancel', {title : 'save.cancel_desc', cmd : 'mceCancel'}); bgneal@45: bgneal@45: ed.onNodeChange.add(t._nodeChange, t); bgneal@45: ed.addShortcut('ctrl+s', ed.getLang('save.save_desc'), 'mceSave'); bgneal@45: }, bgneal@45: bgneal@45: getInfo : function() { bgneal@45: return { bgneal@45: longname : 'Save', bgneal@45: author : 'Moxiecode Systems AB', bgneal@45: authorurl : 'http://tinymce.moxiecode.com', bgneal@45: infourl : 'http://wiki.moxiecode.com/index.php/TinyMCE:Plugins/save', bgneal@45: version : tinymce.majorVersion + "." + tinymce.minorVersion bgneal@45: }; bgneal@45: }, bgneal@45: bgneal@45: // Private methods bgneal@45: bgneal@45: _nodeChange : function(ed, cm, n) { bgneal@45: var ed = this.editor; bgneal@45: bgneal@45: if (ed.getParam('save_enablewhendirty')) { bgneal@45: cm.setDisabled('save', !ed.isDirty()); bgneal@45: cm.setDisabled('cancel', !ed.isDirty()); bgneal@45: } bgneal@45: }, bgneal@45: bgneal@45: // Private methods bgneal@45: bgneal@45: _save : function() { bgneal@45: var ed = this.editor, formObj, os, i, elementId; bgneal@45: bgneal@45: formObj = tinymce.DOM.get(ed.id).form || tinymce.DOM.getParent(ed.id, 'form'); bgneal@45: bgneal@45: if (ed.getParam("save_enablewhendirty") && !ed.isDirty()) bgneal@45: return; bgneal@45: bgneal@45: tinyMCE.triggerSave(); bgneal@45: bgneal@45: // Use callback instead bgneal@45: if (os = ed.getParam("save_onsavecallback")) { bgneal@45: if (ed.execCallback('save_onsavecallback', ed)) { bgneal@45: ed.startContent = tinymce.trim(ed.getContent({format : 'raw'})); bgneal@45: ed.nodeChanged(); bgneal@45: } bgneal@45: bgneal@45: return; bgneal@45: } bgneal@45: bgneal@45: if (formObj) { bgneal@45: ed.isNotDirty = true; bgneal@45: bgneal@45: if (formObj.onsubmit == null || formObj.onsubmit() != false) bgneal@45: formObj.submit(); bgneal@45: bgneal@45: ed.nodeChanged(); bgneal@45: } else bgneal@45: ed.windowManager.alert("Error: No form element found."); bgneal@45: }, bgneal@45: bgneal@45: _cancel : function() { bgneal@45: var ed = this.editor, os, h = tinymce.trim(ed.startContent); bgneal@45: bgneal@45: // Use callback instead bgneal@45: if (os = ed.getParam("save_oncancelcallback")) { bgneal@45: ed.execCallback('save_oncancelcallback', ed); bgneal@45: return; bgneal@45: } bgneal@45: bgneal@45: ed.setContent(h); bgneal@45: ed.undoManager.clear(); bgneal@45: ed.nodeChanged(); bgneal@45: } bgneal@45: }); bgneal@45: bgneal@45: // Register plugin bgneal@45: tinymce.PluginManager.add('save', tinymce.plugins.Save); bgneal@45: })();