Subversion Repositories Sites.tela-botanica.org

Rev

Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
420 florian 1
/**
2
 * $Id: editor_plugin_src.js 251 2007-04-10 20:16:15Z 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
			case "cancel":
35
				return tinyMCE.getButtonHTML(cn, 'lang_cancel_desc', '{$pluginurl}/images/cancel.gif', 'mceCancel');
36
		}
37
 
38
		return "";
39
	},
40
 
41
	/**
42
	 * Executes the save command.
43
	 */
44
	execCommand : function(editor_id, element, command, user_interface, value) {
45
		// Handle commands
46
		switch (command) {
47
			case "mceSave":
48
				return this._save(editor_id, element, command, user_interface, value);
49
 
50
			case "mceCancel":
51
				return this._cancel(editor_id, element, command, user_interface, value);
52
		}
53
 
54
		// Pass to next handler in chain
55
		return false;
56
	},
57
 
58
	_save : function(editor_id, element, command, user_interface, value) {
59
		var inst, formObj, os, i, elementId;
60
 
61
		if (tinyMCE.getParam("fullscreen_is_enabled"))
62
			return true;
63
 
64
		inst = tinyMCE.selectedInstance;
65
		formObj = inst.formElement.form;
66
 
67
		if (tinyMCE.getParam("save_enablewhendirty") && !inst.isDirty())
68
			return true;
69
 
70
		if (formObj) {
71
			tinyMCE.triggerSave();
72
 
73
			// Use callback instead
74
			if ((os = tinyMCE.getParam("save_onsavecallback"))) {
75
				if (eval(os + '(inst);')) {
76
					inst.startContent = tinyMCE.trim(inst.getBody().innerHTML);
77
					/*inst.undoLevels = new Array();
78
					inst.undoIndex = 0;
79
					inst.typingUndoIndex = -1;
80
					inst.undoRedo = true;
81
					inst.undoLevels[inst.undoLevels.length] = inst.startContent;*/
82
					tinyMCE.triggerNodeChange(false, true);
83
				}
84
 
85
				return true;
86
			}
87
 
88
			// Disable all UI form elements that TinyMCE created
89
			for (i=0; i<formObj.elements.length; i++) {
90
				elementId = formObj.elements[i].name ? formObj.elements[i].name : formObj.elements[i].id;
91
 
92
				if (elementId.indexOf('mce_editor_') == 0)
93
					formObj.elements[i].disabled = true;
94
			}
95
 
96
			inst.isNotDirty = true;
97
 
98
			if (formObj.onsubmit == null || formObj.onsubmit() != false)
99
				inst.formElement.form.submit();
100
 
101
			tinyMCE.triggerNodeChange(false, true);
102
		} else
103
			alert("Error: No form element found.");
104
 
105
		return true;
106
	},
107
 
108
	_cancel : function(editor_id, element, command, user_interface, value) {
109
		var inst = tinyMCE.getInstanceById(editor_id), os, h = tinyMCE.trim(inst.startContent);
110
 
111
		// Use callback instead
112
		if ((os = tinyMCE.getParam("save_oncancelcallback"))) {
113
			if (eval(os + '(inst);'))
114
				return true;
115
		}
116
 
117
		inst.setHTML(h);
118
 
119
		inst.undoRedo.undoLevels = [];
120
		inst.undoRedo.add({ content : h });
121
		inst.undoRedo.undoIndex = 0;
122
		inst.undoRedo.typingUndoIndex = -1;
123
 
124
		tinyMCE.triggerNodeChange(false, true);
125
 
126
		return true;
127
	},
128
 
129
	handleNodeChange : function(editor_id, node, undo_index, undo_levels, visual_aid, any_selection) {
130
		var inst;
131
 
132
		if (tinyMCE.getParam("fullscreen_is_enabled")) {
133
			tinyMCE.switchClass(editor_id + '_save', 'mceButtonDisabled');
134
			return true;
135
		}
136
 
137
		if (tinyMCE.getParam("save_enablewhendirty")) {
138
			inst = tinyMCE.getInstanceById(editor_id);
139
 
140
			if (inst.isDirty()) {
141
				tinyMCE.switchClass(editor_id + '_save', 'mceButtonNormal');
142
				return true;
143
			}
144
 
145
			tinyMCE.switchClass(editor_id + '_save', 'mceButtonDisabled');
146
		}
147
 
148
		return true;
149
	}
150
};
151
 
152
tinyMCE.addPlugin("save", TinyMCE_SavePlugin);