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 264 2007-04-26 20:53:09Z 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
if (!tinyMCE.settings['contextmenu_skip_plugin_css']) {
10
	tinyMCE.loadCSS(tinyMCE.baseURL + "/plugins/contextmenu/css/contextmenu.css");
11
}
12
 
13
var TinyMCE_ContextMenuPlugin = {
14
	// Private fields
15
	_contextMenu : null,
16
 
17
	getInfo : function() {
18
		return {
19
			longname : 'Context menus',
20
			author : 'Moxiecode Systems AB',
21
			authorurl : 'http://tinymce.moxiecode.com',
22
			infourl : 'http://wiki.moxiecode.com/index.php/TinyMCE:Plugins/contextmenu',
23
			version : tinyMCE.majorVersion + "." + tinyMCE.minorVersion
24
		};
25
	},
26
 
27
	initInstance : function(inst) {
28
		// Is not working on MSIE 5.0 or Opera no contextmenu event
29
		if (tinyMCE.isMSIE5_0 && tinyMCE.isOpera)
30
			return;
31
 
32
		TinyMCE_ContextMenuPlugin._contextMenu = new TinyMCE_ContextMenu({
33
			commandhandler : "TinyMCE_ContextMenuPlugin._commandHandler",
34
			spacer_image : tinyMCE.baseURL + "/plugins/contextmenu/images/spacer.gif"
35
		});
36
 
37
		// Add hide event handles
38
		tinyMCE.addEvent(inst.getDoc(), "click", TinyMCE_ContextMenuPlugin._hideContextMenu);
39
		tinyMCE.addEvent(inst.getDoc(), "keypress", TinyMCE_ContextMenuPlugin._hideContextMenu);
40
		tinyMCE.addEvent(inst.getDoc(), "keydown", TinyMCE_ContextMenuPlugin._hideContextMenu);
41
		tinyMCE.addEvent(document, "click", TinyMCE_ContextMenuPlugin._hideContextMenu);
42
		tinyMCE.addEvent(document, "keypress", TinyMCE_ContextMenuPlugin._hideContextMenu);
43
		tinyMCE.addEvent(document, "keydown", TinyMCE_ContextMenuPlugin._hideContextMenu);
44
 
45
		// Attach contextmenu event
46
		if (tinyMCE.isGecko) {
47
			tinyMCE.addEvent(inst.getDoc(), "contextmenu", function(e) {TinyMCE_ContextMenuPlugin._showContextMenu(tinyMCE.isMSIE ? inst.contentWindow.event : e, inst);});
48
		} else
49
			tinyMCE.addEvent(inst.getDoc(), "contextmenu", TinyMCE_ContextMenuPlugin._onContextMenu);
50
	},
51
 
52
	// Private plugin internal methods
53
 
54
	_onContextMenu : function(e) {
55
		var elm = tinyMCE.isMSIE ? e.srcElement : e.target;
56
		var targetInst, body;
57
 
58
		// Find instance
59
		if ((body = tinyMCE.getParentElement(elm, "body")) != null) {
60
			for (var n in tinyMCE.instances) {
61
				var inst = tinyMCE.instances[n];
62
				if (!tinyMCE.isInstance(inst))
63
					continue;
64
 
65
				if (body == inst.getBody()) {
66
					targetInst = inst;
67
					break;
68
				}
69
			}
70
 
71
			return TinyMCE_ContextMenuPlugin._showContextMenu(tinyMCE.isMSIE ? targetInst.contentWindow.event : e, targetInst);
72
		}
73
	},
74
 
75
	_showContextMenu : function(e, inst) {
76
		if (e.ctrlKey)
77
			return true;
78
 
79
		function getAttrib(elm, name) {
80
			return elm.getAttribute(name) ? elm.getAttribute(name) : "";
81
		}
82
 
83
		var x, y, elm, contextMenu;
84
		var pos = tinyMCE.getAbsPosition(inst.iframeElement);
85
 
86
		x = tinyMCE.isMSIE ? e.screenX : pos.absLeft + (e.pageX - inst.getBody().scrollLeft);
87
		y = tinyMCE.isMSIE ? e.screenY : pos.absTop + (e.pageY - inst.getBody().scrollTop);
88
		elm = tinyMCE.isMSIE ? e.srcElement : e.target;
89
 
90
		contextMenu = this._contextMenu;
91
		contextMenu.inst = inst;
92
 
93
		// Mozilla needs some time
94
		window.setTimeout(function () {
95
			var theme = tinyMCE.getParam("theme");
96
 
97
			contextMenu.clearAll();
98
			var sel = inst.selection.getSelectedText().length != 0 || elm.nodeName == "IMG";
99
 
100
			// Default items
101
			contextMenu.addItem(tinyMCE.baseURL + "/themes/" + theme + "/images/cut.gif", "$lang_cut_desc", "Cut", "", !sel);
102
			contextMenu.addItem(tinyMCE.baseURL + "/themes/" + theme + "/images/copy.gif", "$lang_copy_desc", "Copy", "", !sel);
103
			contextMenu.addItem(tinyMCE.baseURL + "/themes/" + theme + "/images/paste.gif", "$lang_paste_desc", "Paste", "", false);
104
 
105
			if (sel || (elm ? (elm.nodeName == 'A' && tinyMCE.getAttrib(elm, 'name') == '') || (elm.nodeName == 'IMG') : false)) {
106
				contextMenu.addSeparator();
107
				contextMenu.addItem(tinyMCE.baseURL + "/themes/advanced/images/link.gif", "$lang_link_desc", inst.hasPlugin("advlink") ? "mceAdvLink" : "mceLink");
108
				contextMenu.addItem(tinyMCE.baseURL + "/themes/advanced/images/unlink.gif", "$lang_unlink_desc", "unlink", "", (elm ? (elm.nodeName != 'A') && (elm.nodeName != 'IMG') : true));
109
			}
110
 
111
			// Get element
112
			elm = tinyMCE.getParentElement(elm, "img,table,td" + (inst.hasPlugin("advhr") ? ',hr' : ''));
113
			if (elm) {
114
				switch (elm.nodeName) {
115
					case "IMG":
116
						contextMenu.addSeparator();
117
 
118
						// If flash
119
						if (tinyMCE.hasPlugin('flash') && tinyMCE.getAttrib(elm, 'class').indexOf('mceItemFlash') != -1)
120
							contextMenu.addItem(tinyMCE.baseURL + "/plugins/flash/images/flash.gif", "$lang_flash_props", "mceFlash");
121
						else if (tinyMCE.hasPlugin('media') && /mceItem(Flash|ShockWave|WindowsMedia|QuickTime|RealMedia)/.test(tinyMCE.getAttrib(elm, 'class')))
122
							contextMenu.addItem(tinyMCE.baseURL + "/plugins/flash/images/flash.gif", "$lang_media_title", "mceMedia");
123
						else
124
							contextMenu.addItem(tinyMCE.baseURL + "/themes/" + theme + "/images/image.gif", "$lang_image_props_desc", inst.hasPlugin("advimage") ? "mceAdvImage" : "mceImage");
125
						break;
126
 
127
					case "HR":
128
						contextMenu.addSeparator();
129
						contextMenu.addItem(tinyMCE.baseURL + "/plugins/advhr/images/advhr.gif", "$lang_insert_advhr_desc", "mceAdvancedHr");
130
						break;
131
 
132
					case "TABLE":
133
					case "TD":
134
						// Is table plugin loaded
135
						if (inst.hasPlugin("table")) {
136
							var colspan = (elm.nodeName == "TABLE") ? "" : getAttrib(elm, "colspan");
137
							var rowspan = (elm.nodeName == "TABLE") ? "" : getAttrib(elm, "rowspan");
138
 
139
							colspan = colspan == "" ? "1" : colspan;
140
							rowspan = rowspan == "" ? "1" : rowspan;
141
 
142
							contextMenu.addSeparator();
143
							contextMenu.addItem(tinyMCE.baseURL + "/themes/" + theme + "/images/cut.gif", "$lang_table_cut_row_desc", "mceTableCutRow");
144
							contextMenu.addItem(tinyMCE.baseURL + "/themes/" + theme + "/images/copy.gif", "$lang_table_copy_row_desc", "mceTableCopyRow");
145
							contextMenu.addItem(tinyMCE.baseURL + "/themes/" + theme + "/images/paste.gif", "$lang_table_paste_row_before_desc", "mceTablePasteRowBefore", "", inst.tableRowClipboard == null);
146
							contextMenu.addItem(tinyMCE.baseURL + "/themes/" + theme + "/images/paste.gif", "$lang_table_paste_row_after_desc", "mceTablePasteRowAfter", "", inst.tableRowClipboard == null);
147
 
148
	/*						contextMenu.addItem(tinyMCE.baseURL + "/themes/" + theme + "/images/justifyleft.gif", "$lang_justifyleft_desc", "JustifyLeft", "", false);
149
							contextMenu.addItem(tinyMCE.baseURL + "/themes/" + theme + "/images/justifycenter.gif", "$lang_justifycenter_desc", "JustifyCenter", "", false);
150
							contextMenu.addItem(tinyMCE.baseURL + "/themes/" + theme + "/images/justifyright.gif", "$lang_justifyright_desc", "JustifyRight", "", false);
151
							contextMenu.addItem(tinyMCE.baseURL + "/themes/" + theme + "/images/justifyfull.gif", "$lang_justifyfull_desc", "JustifyFull", "", false);*/
152
							contextMenu.addSeparator();
153
							contextMenu.addItem(tinyMCE.baseURL + "/plugins/table/images/table.gif", "$lang_table_desc", "mceInsertTable", "insert");
154
							contextMenu.addItem(tinyMCE.baseURL + "/plugins/table/images/table.gif", "$lang_table_props_desc", "mceInsertTable");
155
							contextMenu.addItem(tinyMCE.baseURL + "/plugins/table/images/table_cell_props.gif", "$lang_table_cell_desc", "mceTableCellProps");
156
							contextMenu.addItem(tinyMCE.baseURL + "/plugins/table/images/table_delete.gif", "$lang_table_del", "mceTableDelete");
157
							contextMenu.addSeparator();
158
							contextMenu.addItem(tinyMCE.baseURL + "/plugins/table/images/table_row_props.gif", "$lang_table_row_desc", "mceTableRowProps");
159
							contextMenu.addItem(tinyMCE.baseURL + "/plugins/table/images/table_insert_row_before.gif", "$lang_table_row_before_desc", "mceTableInsertRowBefore");
160
							contextMenu.addItem(tinyMCE.baseURL + "/plugins/table/images/table_insert_row_after.gif", "$lang_table_row_after_desc", "mceTableInsertRowAfter");
161
							contextMenu.addItem(tinyMCE.baseURL + "/plugins/table/images/table_delete_row.gif", "$lang_table_delete_row_desc", "mceTableDeleteRow");
162
							contextMenu.addSeparator();
163
							contextMenu.addItem(tinyMCE.baseURL + "/plugins/table/images/table_insert_col_before.gif", "$lang_table_col_before_desc", "mceTableInsertColBefore");
164
							contextMenu.addItem(tinyMCE.baseURL + "/plugins/table/images/table_insert_col_after.gif", "$lang_table_col_after_desc", "mceTableInsertColAfter");
165
							contextMenu.addItem(tinyMCE.baseURL + "/plugins/table/images/table_delete_col.gif", "$lang_table_delete_col_desc", "mceTableDeleteCol");
166
							contextMenu.addSeparator();
167
							contextMenu.addItem(tinyMCE.baseURL + "/plugins/table/images/table_split_cells.gif", "$lang_table_split_cells_desc", "mceTableSplitCells", "", (colspan == "1" && rowspan == "1"));
168
							contextMenu.addItem(tinyMCE.baseURL + "/plugins/table/images/table_merge_cells.gif", "$lang_table_merge_cells_desc", "mceTableMergeCells", "", false);
169
						}
170
						break;
171
				}
172
			}  else {
173
				// Add table specific
174
				if (inst.hasPlugin("table")) {
175
					contextMenu.addSeparator();
176
					contextMenu.addItem(tinyMCE.baseURL + "/plugins/table/images/table.gif", "$lang_table_desc", "mceInsertTable", "insert");
177
				}
178
			}
179
 
180
			contextMenu.show(x, y);
181
		}, 10);
182
 
183
		// Cancel default handeling
184
		tinyMCE.cancelEvent(e);
185
		return false;
186
	},
187
 
188
	_hideContextMenu : function() {
189
		if (TinyMCE_ContextMenuPlugin._contextMenu)
190
			TinyMCE_ContextMenuPlugin._contextMenu.hide();
191
	},
192
 
193
	_commandHandler : function(command, value) {
194
		var cm = TinyMCE_ContextMenuPlugin._contextMenu;
195
 
196
		cm.hide();
197
 
198
		// UI must be true on these
199
		var ui = false;
200
		if (command == "mceInsertTable" || command == "mceTableCellProps" || command == "mceTableRowProps" || command == "mceTableMergeCells")
201
			ui = true;
202
 
203
		if (command == "Paste")
204
			value = null;
205
 
206
		if (tinyMCE.getParam("dialog_type") == "modal" && tinyMCE.isMSIE) {
207
			// Cell properties will generate access denied error is this isn't done?!
208
			window.setTimeout(function() {
209
				cm.inst.execCommand(command, ui, value);
210
			}, 100);
211
		} else
212
			cm.inst.execCommand(command, ui, value);
213
	}
214
};
215
 
216
tinyMCE.addPlugin("contextmenu", TinyMCE_ContextMenuPlugin);
217
 
218
// Context menu class
219
 
220
function TinyMCE_ContextMenu(settings) {
221
	var doc, self = this;
222
 
223
	// Default value function
224
	function defParam(key, def_val) {
225
		settings[key] = typeof(settings[key]) != "undefined" ? settings[key] : def_val;
226
	}
227
 
228
	this.isMSIE = (navigator.appName == "Microsoft Internet Explorer");
229
 
230
	// Setup contextmenu div
231
	this.contextMenuDiv = document.createElement("div");
232
	this.contextMenuDiv.className = "contextMenu";
233
	this.contextMenuDiv.setAttribute("class", "contextMenu");
234
	this.contextMenuDiv.style.display = "none";
235
	this.contextMenuDiv.style.position = 'absolute';
236
	this.contextMenuDiv.style.zindex = 1000;
237
	this.contextMenuDiv.style.left = '0';
238
	this.contextMenuDiv.style.top = '0';
239
	this.contextMenuDiv.unselectable = "on";
240
 
241
	document.body.appendChild(this.contextMenuDiv);
242
 
243
	// Setup default values
244
	defParam("commandhandler", "");
245
	defParam("spacer_image", "images/spacer.gif");
246
 
247
	this.items = new Array();
248
	this.settings = settings;
249
	this.html = "";
250
 
251
	// IE Popup
252
	if (tinyMCE.isMSIE && !tinyMCE.isMSIE5_0 && !tinyMCE.isOpera) {
253
		this.pop = window.createPopup();
254
		doc = this.pop.document;
255
		doc.open();
256
		doc.write('<html><head><link href="' + tinyMCE.baseURL + '/plugins/contextmenu/css/contextmenu.css" rel="stylesheet" type="text/css" /></head><body unselectable="yes" class="contextMenuIEPopup"></body></html>');
257
		doc.close();
258
	}
259
};
260
 
261
TinyMCE_ContextMenu.prototype = {
262
	clearAll : function() {
263
		this.html = "";
264
		this.contextMenuDiv.innerHTML = "";
265
	},
266
 
267
	addSeparator : function() {
268
		this.html += '<tr class="contextMenuItem"><td class="contextMenuIcon"><img src="' + this.settings['spacer_image'] + '" width="20" height="1" class="contextMenuImage" /></td><td><img class="contextMenuSeparator" width="1" height="1" src="' + this.settings['spacer_image'] + '" /></td></tr>';
269
	},
270
 
271
	addItem : function(icon, title, command, value, disabled) {
272
		if (title.charAt(0) == '$')
273
			title = tinyMCE.getLang(title.substring(1));
274
 
275
		var onMouseDown = '';
276
		var html = '';
277
 
278
		if (tinyMCE.isMSIE && !tinyMCE.isMSIE5_0)
279
			onMouseDown = 'contextMenu.execCommand(\'' + command + '\', \'' + value + '\');return false;';
280
		else
281
			onMouseDown = this.settings['commandhandler'] + '(\'' + command + '\', \'' + value + '\');return false;';
282
 
283
		if (icon == "")
284
			icon = this.settings['spacer_image'];
285
 
286
		if (!disabled)
287
			html += '<tr class="contextMenuItem">';
288
		else
289
			html += '<tr class="contextMenuItemDisabled">';
290
 
291
		html += '<td class="contextMenuIcon"><img src="' + icon + '" width="20" height="20" class="contextMenuImage" /></td>';
292
		html += '<td><div class="contextMenuText">';
293
		html += '<a href="javascript:void(0);" onclick="' + onMouseDown + '" onmousedown="return false;">&#160;';
294
 
295
		// Add text
296
		html += title;
297
 
298
		html += '&#160;</a>';
299
		html += '</div></td>';
300
		html += '</tr>';
301
 
302
		// Add to main
303
		this.html += html;
304
	},
305
 
306
	show : function(x, y) {
307
		var vp, width, height, yo;
308
 
309
		if (this.html == "")
310
			return;
311
 
312
		var html = '';
313
 
314
		html += '<a href="#"></a><table border="0" cellpadding="0" cellspacing="0">';
315
		html += this.html;
316
		html += '</table>';
317
 
318
		this.contextMenuDiv.innerHTML = html;
319
 
320
		// Get dimensions
321
		this.contextMenuDiv.style.display = "block";
322
		width = this.contextMenuDiv.offsetWidth;
323
		height = this.contextMenuDiv.offsetHeight;
324
		this.contextMenuDiv.style.display = "none";
325
 
326
		if (tinyMCE.isMSIE && !tinyMCE.isMSIE5_0 && !tinyMCE.isOpera) {
327
			// Setup popup and show
328
			this.pop.document.body.innerHTML = '<div class="contextMenu">' + html + "</div>";
329
			this.pop.document.tinyMCE = tinyMCE;
330
			this.pop.document.contextMenu = this;
331
			this.pop.show(x, y, width, height);
332
		} else {
333
			vp = this.getViewPort();
334
			yo = tinyMCE.isMSIE5_0 ? document.body.scrollTop : self.pageYOffset;
335
			this.contextMenuDiv.style.left = (x > vp.left + vp.width - width ? vp.left + vp.width - width : x) + 'px';
336
			this.contextMenuDiv.style.top = (y > vp.top + vp.height - height ? vp.top + vp.height - height : y) + 'px';
337
			this.contextMenuDiv.style.display = "block";
338
		}
339
	},
340
 
341
	getViewPort : function() {
342
		return {
343
			left : self.pageXOffset || self.document.documentElement.scrollLeft || self.document.body.scrollLeft,
344
			top: self.pageYOffset || self.document.documentElement.scrollTop || self.document.body.scrollTop,
345
			width : document.documentElement.offsetWidth || document.body.offsetWidth,
346
			height : self.innerHeight || document.documentElement.clientHeight || document.body.clientHeight
347
		};
348
	},
349
 
350
	hide : function() {
351
		if (tinyMCE.isMSIE && !tinyMCE.isMSIE5_0 && !tinyMCE.isOpera)
352
			this.pop.hide();
353
		else
354
			this.contextMenuDiv.style.display = "none";
355
	},
356
 
357
	execCommand : function(command, value) {
358
		eval(this.settings['commandhandler'] + "(command, value);");
359
	}
360
};