4 * Copyright, Moxiecode Systems AB
5 * Released under LGPL License.
7 * License: http://www.tinymce.com/license
8 * Contributing: http://www.tinymce.com/contributing
11 /*global tinymce:true */
13 tinymce.PluginManager.add('save', function(editor) {
17 formObj = tinymce.DOM.getParent(editor.id, 'form');
19 if (editor.getParam("save_enablewhendirty", true) && !editor.isDirty()) {
23 tinymce.triggerSave();
25 // Use callback instead
26 if ((os = editor.getParam("save_onsavecallback"))) {
27 if (editor.execCallback('save_onsavecallback', editor)) {
28 editor.startContent = tinymce.trim(editor.getContent({format: 'raw'}));
36 editor.isNotDirty = true;
38 if (!formObj.onsubmit || formObj.onsubmit()) {
39 if (typeof(formObj.submit) == "function") {
42 editor.windowManager.alert("Error: Form submit field collision.");
48 editor.windowManager.alert("Error: No form element found.");
53 var os, h = tinymce.trim(editor.startContent);
55 // Use callback instead
56 if ((os = editor.getParam("save_oncancelcallback"))) {
57 editor.execCallback('save_oncancelcallback', editor);
62 editor.undoManager.clear();
66 function stateToggle() {
69 editor.on('nodeChange', function() {
70 self.disabled(editor.getParam("save_enablewhendirty", true) && !editor.isDirty());
74 editor.addCommand('mceSave', save);
75 editor.addCommand('mceCancel', cancel);
77 editor.addButton('save', {
82 onPostRender: stateToggle
85 editor.addButton('cancel', {
90 onPostRender: stateToggle
93 editor.addShortcut('ctrl+s', '', 'mceSave');