Subversion Repositories Sites.tela-botanica.org

Rev

Go to most recent revision | Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
420 florian 1
// Some global instances, this will be filled later
2
var tinyMCE = null, tinyMCELang = null;
3
 
4
function TinyMCE_Popup() {
5
};
6
 
7
TinyMCE_Popup.prototype = {
8
	findWin : function(w) {
9
		var c;
10
 
11
		// Check parents
12
		c = w;
13
		while (c && (c = c.parent) != null) {
14
			if (typeof(c.tinyMCE) != "undefined")
15
				return c;
16
		}
17
 
18
		// Check openers
19
		c = w;
20
		while (c && (c = c.opener) != null) {
21
			if (typeof(c.tinyMCE) != "undefined")
22
				return c;
23
		}
24
 
25
		// Try top
26
		if (typeof(top.tinyMCE) != "undefined")
27
			return top;
28
 
29
		return null;
30
	},
31
 
32
	init : function() {
33
		var win = window.opener ? window.opener : window.dialogArguments, c;
34
		var inst, re, title, divElm;
35
 
36
		if (!win)
37
			win = this.findWin(window);
38
 
39
		if (!win) {
40
			alert("tinyMCE object reference not found from popup.");
41
			return;
42
		}
43
 
44
		window.opener = win;
45
		this.windowOpener = win;
46
		this.onLoadEval = "";
47
 
48
		// Setup parent references
49
		tinyMCE = win.tinyMCE;
50
		tinyMCELang = win.tinyMCELang;
51
 
52
		inst = tinyMCE.selectedInstance;
53
		this.isWindow = tinyMCE.getWindowArg('mce_inside_iframe', false) == false;
54
		this.storeSelection = (tinyMCE.isRealIE) && !this.isWindow && tinyMCE.getWindowArg('mce_store_selection', true);
55
 
56
		if (this.isWindow)
57
			window.focus();
58
 
59
		// Store selection
60
		if (this.storeSelection)
61
			inst.selectionBookmark = inst.selection.getBookmark(true);
62
 
63
		// Setup dir
64
		if (tinyMCELang.lang_dir)
65
			document.dir = tinyMCELang.lang_dir;
66
 
67
		// Setup title
68
		re = new RegExp('{|\\\$|}', 'g');
69
		title = document.title.replace(re, "");
70
		if (typeof(tinyMCELang[title]) != "undefined") {
71
			divElm = document.createElement("div");
72
			divElm.innerHTML = tinyMCELang[title];
73
			document.title = divElm.innerHTML;
74
 
75
			if (typeof(tinyMCE.setWindowTitle) != 'undefined')
76
				tinyMCE.setWindowTitle(window, divElm.innerHTML);
77
		}
78
 
79
		// Output Popup CSS class
80
		document.write('<link href="' + tinyMCE.getParam("popups_css") + '" rel="stylesheet" type="text/css">');
81
 
82
		if (tinyMCE.getParam("popups_css_add")) {
83
			c = tinyMCE.getParam("popups_css_add");
84
 
85
			// Is relative
86
			if (c.indexOf('://') == -1 && c.charAt(0) != '/')
87
				c = tinyMCE.documentBasePath + "/" + c;
88
 
89
			document.write('<link href="' + c + '" rel="stylesheet" type="text/css">');
90
		}
91
 
92
		tinyMCE.addEvent(window, "load", this.onLoad);
93
	},
94
 
95
	onLoad : function() {
96
		var dir, i, elms, body = document.body;
97
 
98
		if (tinyMCE.getWindowArg('mce_replacevariables', true))
99
			body.innerHTML = tinyMCE.applyTemplate(body.innerHTML, tinyMCE.windowArgs);
100
 
101
		dir = tinyMCE.selectedInstance.settings.directionality;
102
		if (dir == "rtl" && document.forms && document.forms.length > 0) {
103
			elms = document.forms[0].elements;
104
			for (i=0; i<elms.length; i++) {
105
				if ((elms[i].type == "text" || elms[i].type == "textarea") && elms[i].getAttribute("dir") != "ltr")
106
					elms[i].dir = dir;
107
			}
108
		}
109
 
110
		if (body.style.display == 'none')
111
			body.style.display = 'block';
112
 
113
		// Execute real onload (Opera fix)
114
		if (tinyMCEPopup.onLoadEval !== '')
115
			eval(tinyMCEPopup.onLoadEval);
116
	},
117
 
118
	executeOnLoad : function(str) {
119
		if (tinyMCE.isOpera)
120
			this.onLoadEval = str;
121
		else
122
			eval(str);
123
	},
124
 
125
	resizeToInnerSize : function() {
126
		var i, doc, body, oldMargin, wrapper, iframe, nodes, dx, dy;
127
 
128
		// Netscape 7.1 workaround
129
		if (this.isWindow && tinyMCE.isNS71) {
130
			window.resizeBy(0, 10);
131
			return;
132
		}
133
 
134
		if (this.isWindow) {
135
			doc = document;
136
			body = doc.body;
137
 
138
			if (body.style.display == 'none')
139
				body.style.display = 'block';
140
 
141
			// Remove margin
142
			oldMargin = body.style.margin;
143
			body.style.margin = '0';
144
 
145
			// Create wrapper
146
			wrapper = doc.createElement("div");
147
			wrapper.id = 'mcBodyWrapper';
148
			wrapper.style.display = 'none';
149
			wrapper.style.margin = '0';
150
 
151
			// Wrap body elements
152
			nodes = doc.body.childNodes;
153
			for (i=nodes.length-1; i>=0; i--) {
154
				if (wrapper.hasChildNodes())
155
					wrapper.insertBefore(nodes[i].cloneNode(true), wrapper.firstChild);
156
				else
157
					wrapper.appendChild(nodes[i].cloneNode(true));
158
 
159
				nodes[i].parentNode.removeChild(nodes[i]);
160
			}
161
 
162
			// Add wrapper
163
			doc.body.appendChild(wrapper);
164
 
165
			// Create iframe
166
			iframe = document.createElement("iframe");
167
			iframe.id = "mcWinIframe";
168
			iframe.src = document.location.href.toLowerCase().indexOf('https') == -1 ? "about:blank" : tinyMCE.settings.default_document;
169
			iframe.width = "100%";
170
			iframe.height = "100%";
171
			iframe.style.margin = '0';
172
 
173
			// Add iframe
174
			doc.body.appendChild(iframe);
175
 
176
			// Measure iframe
177
			iframe = document.getElementById('mcWinIframe');
178
			dx = tinyMCE.getWindowArg('mce_width') - iframe.clientWidth;
179
			dy = tinyMCE.getWindowArg('mce_height') - iframe.clientHeight;
180
 
181
			// Resize window
182
			// tinyMCE.debug(tinyMCE.getWindowArg('mce_width') + "," + tinyMCE.getWindowArg('mce_height') + " - " + dx + "," + dy);
183
			window.resizeBy(dx, dy);
184
 
185
			// Hide iframe and show wrapper
186
			body.style.margin = oldMargin;
187
			iframe.style.display = 'none';
188
			wrapper.style.display = 'block';
189
		}
190
	},
191
 
192
	resizeToContent : function() {
193
		var isMSIE = (navigator.appName == "Microsoft Internet Explorer");
194
		var isOpera = (navigator.userAgent.indexOf("Opera") != -1);
195
		var elm, width, height, x, y, dx, dy;
196
 
197
		if (isOpera)
198
			return;
199
 
200
		if (isMSIE) {
201
			try { window.resizeTo(10, 10); } catch (e) {}
202
 
203
			elm = document.body;
204
			width = elm.offsetWidth;
205
			height = elm.offsetHeight;
206
			dx = (elm.scrollWidth - width) + 4;
207
			dy = elm.scrollHeight - height;
208
 
209
			try { window.resizeBy(dx, dy); } catch (e) {}
210
		} else {
211
			window.scrollBy(1000, 1000);
212
			if (window.scrollX > 0 || window.scrollY > 0) {
213
				window.resizeBy(window.innerWidth * 2, window.innerHeight * 2);
214
				window.sizeToContent();
215
				window.scrollTo(0, 0);
216
				x = parseInt(screen.width / 2.0) - (window.outerWidth / 2.0);
217
				y = parseInt(screen.height / 2.0) - (window.outerHeight / 2.0);
218
				window.moveTo(x, y);
219
			}
220
		}
221
	},
222
 
223
	getWindowArg : function(name, default_value) {
224
		return tinyMCE.getWindowArg(name, default_value);
225
	},
226
 
227
	restoreSelection : function() {
228
		var inst;
229
 
230
		if (this.storeSelection) {
231
			inst = tinyMCE.selectedInstance;
232
 
233
			inst.getWin().focus();
234
 
235
			if (inst.selectionBookmark)
236
				inst.selection.moveToBookmark(inst.selectionBookmark);
237
		}
238
	},
239
 
240
	execCommand : function(command, user_interface, value) {
241
		var inst = tinyMCE.selectedInstance;
242
 
243
		this.restoreSelection();
244
		inst.execCommand(command, user_interface, value);
245
 
246
		// Store selection
247
		if (this.storeSelection)
248
			inst.selectionBookmark = inst.selection.getBookmark(true);
249
	},
250
 
251
	close : function() {
252
		tinyMCE.closeWindow(window);
253
	},
254
 
255
	pickColor : function(e, element_id) {
256
		tinyMCE.selectedInstance.execCommand('mceColorPicker', true, {
257
			element_id : element_id,
258
			document : document,
259
			window : window,
260
			store_selection : false
261
		});
262
	},
263
 
264
	openBrowser : function(element_id, type, option) {
265
		var cb = tinyMCE.getParam(option, tinyMCE.getParam("file_browser_callback"));
266
		var url = document.getElementById(element_id).value;
267
 
268
		tinyMCE.setWindowArg("window", window);
269
		tinyMCE.setWindowArg("document", document);
270
 
271
		// Call to external callback
272
		if (eval('typeof(tinyMCEPopup.windowOpener.' + cb + ')') == "undefined")
273
			alert("Callback function: " + cb + " could not be found.");
274
		else
275
			eval("tinyMCEPopup.windowOpener." + cb + "(element_id, url, type, window);");
276
	},
277
 
278
	importClass : function(c) {
279
		var n;
280
 
281
		window[c] = function() {};
282
 
283
		for (n in window.opener[c].prototype)
284
			window[c].prototype[n] = window.opener[c].prototype[n];
285
 
286
		window[c].constructor = window.opener[c].constructor;
287
	}
288
 
289
	};
290
 
291
// Setup global instance
292
var tinyMCEPopup = new TinyMCE_Popup();
293
 
294
tinyMCEPopup.init();