includes/clientside/tinymce/plugins/save/editor_plugin_src.js
changeset 1 fe660c52c48f
child 335 67bd3121a12e
equal deleted inserted replaced
0:902822492a68 1:fe660c52c48f
       
     1 /**
       
     2  * $Id: editor_plugin_src.js 201 2007-02-12 15:56:56Z spocke $
       
     3  *
       
     4  * @author Moxiecode
       
     5  * @copyright Copyright © 2004-2007, Moxiecode Systems AB, All rights reserved.
       
     6  */
       
     7 
       
     8 /* Import plugin specific language pack */
       
     9 tinyMCE.importPluginLanguagePack('save');
       
    10 
       
    11 var TinyMCE_SavePlugin = {
       
    12 	getInfo : function() {
       
    13 		return {
       
    14 			longname : 'Save',
       
    15 			author : 'Moxiecode Systems AB',
       
    16 			authorurl : 'http://tinymce.moxiecode.com',
       
    17 			infourl : 'http://wiki.moxiecode.com/index.php/TinyMCE:Plugins/save',
       
    18 			version : tinyMCE.majorVersion + "." + tinyMCE.minorVersion
       
    19 		};
       
    20 	},
       
    21 
       
    22 	initInstance : function(inst) {
       
    23 		inst.addShortcut('ctrl', 's', 'lang_save_desc', 'mceSave');
       
    24 	},
       
    25 
       
    26 	/**
       
    27 	 * Returns the HTML contents of the save control.
       
    28 	 */
       
    29 	getControlHTML : function(cn) {
       
    30 		switch (cn) {
       
    31 			case "save":
       
    32 				return tinyMCE.getButtonHTML(cn, 'lang_save_desc', '{$pluginurl}/images/save.gif', 'mceSave');
       
    33 		}
       
    34 
       
    35 		return "";
       
    36 	},
       
    37 
       
    38 	/**
       
    39 	 * Executes the save command.
       
    40 	 */
       
    41 	execCommand : function(editor_id, element, command, user_interface, value) {
       
    42 		// Handle commands
       
    43 		switch (command) {
       
    44 			case "mceSave":
       
    45 				if (tinyMCE.getParam("fullscreen_is_enabled"))
       
    46 					return true;
       
    47 
       
    48 				var inst = tinyMCE.selectedInstance;
       
    49 				var formObj = inst.formElement.form;
       
    50 
       
    51 				if (tinyMCE.getParam("save_enablewhendirty") && !inst.isDirty())
       
    52 					return true;
       
    53 
       
    54 				if (formObj) {
       
    55 					tinyMCE.triggerSave();
       
    56 
       
    57 					// Use callback instead
       
    58 					var os;
       
    59 					if ((os = tinyMCE.getParam("save_onsavecallback"))) {
       
    60 						if (eval(os + '(inst);')) {
       
    61 							inst.startContent = tinyMCE.trim(inst.getBody().innerHTML);
       
    62 							/*inst.undoLevels = new Array();
       
    63 							inst.undoIndex = 0;
       
    64 							inst.typingUndoIndex = -1;
       
    65 							inst.undoRedo = true;
       
    66 							inst.undoLevels[inst.undoLevels.length] = inst.startContent;*/
       
    67 							tinyMCE.triggerNodeChange(false, true);
       
    68 						}
       
    69 
       
    70 						return true;
       
    71 					}
       
    72 
       
    73 					// Disable all UI form elements that TinyMCE created
       
    74 					for (var i=0; i<formObj.elements.length; i++) {
       
    75 						var elementId = formObj.elements[i].name ? formObj.elements[i].name : formObj.elements[i].id;
       
    76 
       
    77 						if (elementId.indexOf('mce_editor_') == 0)
       
    78 							formObj.elements[i].disabled = true;
       
    79 					}
       
    80 
       
    81 					tinyMCE.isNotDirty = true;
       
    82 
       
    83 					if (formObj.onsubmit == null || formObj.onsubmit() != false)
       
    84 						inst.formElement.form.submit();
       
    85 				} else
       
    86 					alert("Error: No form element found.");
       
    87 
       
    88 				return true;
       
    89 		}
       
    90 		// Pass to next handler in chain
       
    91 		return false;
       
    92 	},
       
    93 
       
    94 	handleNodeChange : function(editor_id, node, undo_index, undo_levels, visual_aid, any_selection) {
       
    95 		if (tinyMCE.getParam("fullscreen_is_enabled")) {
       
    96 			tinyMCE.switchClass(editor_id + '_save', 'mceButtonDisabled');
       
    97 			return true;
       
    98 		}
       
    99 
       
   100 		if (tinyMCE.getParam("save_enablewhendirty")) {
       
   101 			var inst = tinyMCE.getInstanceById(editor_id);
       
   102 
       
   103 			if (inst.isDirty()) {
       
   104 				tinyMCE.switchClass(editor_id + '_save', 'mceButtonNormal');
       
   105 				return true;
       
   106 			}
       
   107 
       
   108 			tinyMCE.switchClass(editor_id + '_save', 'mceButtonDisabled');
       
   109 		}
       
   110 
       
   111 		return true;
       
   112 	}
       
   113 };
       
   114 
       
   115 tinyMCE.addPlugin("save", TinyMCE_SavePlugin);