includes/clientside/tinymce/plugins/save/editor_plugin_src.js
changeset 1344 dc96d6c5cd1e
parent 1343 2a31905a567d
child 1345 1de01205143b
equal deleted inserted replaced
1343:2a31905a567d 1344:dc96d6c5cd1e
     1 /**
       
     2  * $Id: editor_plugin_src.js 851 2008-05-26 15:38:49Z spocke $
       
     3  *
       
     4  * @author Moxiecode
       
     5  * @copyright Copyright © 2004-2008, Moxiecode Systems AB, All rights reserved.
       
     6  */
       
     7 
       
     8 (function() {
       
     9 	tinymce.create('tinymce.plugins.Save', {
       
    10 		init : function(ed, url) {
       
    11 			var t = this;
       
    12 
       
    13 			t.editor = ed;
       
    14 
       
    15 			// Register commands
       
    16 			ed.addCommand('mceSave', t._save, t);
       
    17 			ed.addCommand('mceCancel', t._cancel, t);
       
    18 
       
    19 			// Register buttons
       
    20 			ed.addButton('save', {title : 'save.save_desc', cmd : 'mceSave'});
       
    21 			ed.addButton('cancel', {title : 'save.cancel_desc', cmd : 'mceCancel'});
       
    22 
       
    23 			ed.onNodeChange.add(t._nodeChange, t);
       
    24 			ed.addShortcut('ctrl+s', ed.getLang('save.save_desc'), 'mceSave');
       
    25 		},
       
    26 
       
    27 		getInfo : function() {
       
    28 			return {
       
    29 				longname : 'Save',
       
    30 				author : 'Moxiecode Systems AB',
       
    31 				authorurl : 'http://tinymce.moxiecode.com',
       
    32 				infourl : 'http://wiki.moxiecode.com/index.php/TinyMCE:Plugins/save',
       
    33 				version : tinymce.majorVersion + "." + tinymce.minorVersion
       
    34 			};
       
    35 		},
       
    36 
       
    37 		// Private methods
       
    38 
       
    39 		_nodeChange : function(ed, cm, n) {
       
    40 			var ed = this.editor;
       
    41 
       
    42 			if (ed.getParam('save_enablewhendirty')) {
       
    43 				cm.setDisabled('save', !ed.isDirty());
       
    44 				cm.setDisabled('cancel', !ed.isDirty());
       
    45 			}
       
    46 		},
       
    47 
       
    48 		// Private methods
       
    49 
       
    50 		_save : function() {
       
    51 			var ed = this.editor, formObj, os, i, elementId;
       
    52 
       
    53 			formObj = tinymce.DOM.get(ed.id).form || tinymce.DOM.getParent(ed.id, 'form');
       
    54 
       
    55 			if (ed.getParam("save_enablewhendirty") && !ed.isDirty())
       
    56 				return;
       
    57 
       
    58 			tinyMCE.triggerSave();
       
    59 
       
    60 			// Use callback instead
       
    61 			if (os = ed.getParam("save_onsavecallback")) {
       
    62 				if (ed.execCallback('save_onsavecallback', ed)) {
       
    63 					ed.startContent = tinymce.trim(ed.getContent({format : 'raw'}));
       
    64 					ed.nodeChanged();
       
    65 				}
       
    66 
       
    67 				return;
       
    68 			}
       
    69 
       
    70 			if (formObj) {
       
    71 				ed.isNotDirty = true;
       
    72 
       
    73 				if (formObj.onsubmit == null || formObj.onsubmit() != false)
       
    74 					formObj.submit();
       
    75 
       
    76 				ed.nodeChanged();
       
    77 			} else
       
    78 				ed.windowManager.alert("Error: No form element found.");
       
    79 		},
       
    80 
       
    81 		_cancel : function() {
       
    82 			var ed = this.editor, os, h = tinymce.trim(ed.startContent);
       
    83 
       
    84 			// Use callback instead
       
    85 			if (os = ed.getParam("save_oncancelcallback")) {
       
    86 				ed.execCallback('save_oncancelcallback', ed);
       
    87 				return;
       
    88 			}
       
    89 
       
    90 			ed.setContent(h);
       
    91 			ed.undoManager.clear();
       
    92 			ed.nodeChanged();
       
    93 		}
       
    94 	});
       
    95 
       
    96 	// Register plugin
       
    97 	tinymce.PluginManager.add('save', tinymce.plugins.Save);
       
    98 })();