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