Browse code

3.5.6 efiction version

Jimako authored on 2024/03/09 16:09:42
Showing 1 changed files
1 1
new file mode 100644
... ...
@@ -0,0 +1,275 @@
1
+// Some global instances
2
+var tinymce = null, tinyMCEPopup, tinyMCE;
3
+
4
+tinyMCEPopup = {
5
+	init : function() {
6
+		var t = this, w, ti, li, q, i, it;
7
+
8
+		li = ('' + document.location.search).replace(/^\?/, '').split('&');
9
+		q = {};
10
+		for (i=0; i<li.length; i++) {
11
+			it = li[i].split('=');
12
+			q[unescape(it[0])] = unescape(it[1]);
13
+		}
14
+
15
+		if (q.mce_rdomain)
16
+			document.domain = q.mce_rdomain;
17
+
18
+		// Find window & API
19
+		w = t.getWin();
20
+		tinymce = w.tinymce;
21
+		tinyMCE = w.tinyMCE;
22
+		t.editor = tinymce.EditorManager.activeEditor;
23
+		t.params = t.editor.windowManager.params;
24
+
25
+		// Setup local DOM
26
+		t.dom = t.editor.windowManager.createInstance('tinymce.dom.DOMUtils', document);
27
+		t.dom.loadCSS(t.editor.settings.popup_css);
28
+
29
+		// Setup on init listeners
30
+		t.listeners = [];
31
+		t.onInit = {
32
+			add : function(f, s) {
33
+				t.listeners.push({func : f, scope : s});
34
+			}
35
+		};
36
+
37
+		t.isWindow = !t.getWindowArg('mce_inline');
38
+		t.id = t.getWindowArg('mce_window_id');
39
+		t.editor.windowManager.onOpen.dispatch(t.editor.windowManager, window);
40
+	},
41
+
42
+	getWin : function() {
43
+		return window.dialogArguments || opener || parent || top;
44
+	},
45
+
46
+	getWindowArg : function(n, dv) {
47
+		var v = this.params[n];
48
+
49
+		return tinymce.is(v) ? v : dv;
50
+	},
51
+
52
+	getParam : function(n, dv) {
53
+		return this.editor.getParam(n, dv);
54
+	},
55
+
56
+	getLang : function(n, dv) {
57
+		return this.editor.getLang(n, dv);
58
+	},
59
+
60
+	execCommand : function(cmd, ui, val, a) {
61
+		a = a || {};
62
+		a.skip_focus = 1;
63
+
64
+		this.restoreSelection();
65
+		return this.editor.execCommand(cmd, ui, val, a);
66
+	},
67
+
68
+	resizeToInnerSize : function() {
69
+		var t = this, n, b = document.body, vp = t.dom.getViewPort(window), dw, dh;
70
+
71
+		dw = t.getWindowArg('mce_width') - vp.w;
72
+		dh = t.getWindowArg('mce_height') - vp.h;
73
+
74
+		if (t.isWindow)
75
+			window.resizeBy(dw, dh);
76
+		else
77
+			t.editor.windowManager.resizeBy(dw, dh, t.id);
78
+	},
79
+
80
+	executeOnLoad : function(s) {
81
+		this.onInit.add(function() {
82
+			eval(s);
83
+		});
84
+	},
85
+
86
+	storeSelection : function() {
87
+		this.editor.windowManager.bookmark = tinyMCEPopup.editor.selection.getBookmark('simple');
88
+	},
89
+
90
+	restoreSelection : function() {
91
+		var t = tinyMCEPopup;
92
+
93
+		if (!t.isWindow && tinymce.isIE)
94
+			t.editor.selection.moveToBookmark(t.editor.windowManager.bookmark);
95
+	},
96
+
97
+	requireLangPack : function() {
98
+		var u = this.getWindowArg('plugin_url') || this.getWindowArg('theme_url');
99
+
100
+		if (u && this.editor.settings.language) {
101
+			u += '/langs/' + this.editor.settings.language + '_dlg.js';
102
+
103
+			if (!tinymce.ScriptLoader.isDone(u)) {
104
+				document.write('<script type="text/javascript" src="' + tinymce._addVer(u) + '"></script>');
105
+				tinymce.ScriptLoader.markDone(u);
106
+			}
107
+		}
108
+	},
109
+
110
+	pickColor : function(e, element_id) {
111
+		this.execCommand('mceColorPicker', true, {
112
+			color : document.getElementById(element_id).value,
113
+			func : function(c) {
114
+				document.getElementById(element_id).value = c;
115
+
116
+				try {
117
+					document.getElementById(element_id).onchange();
118
+				} catch (ex) {
119
+					// Try fire event, ignore errors
120
+				}
121
+			}
122
+		});
123
+	},
124
+
125
+	openBrowser : function(element_id, type, option) {
126
+		tinyMCEPopup.restoreSelection();
127
+		this.editor.execCallback('file_browser_callback', element_id, document.getElementById(element_id).value, type, window);
128
+	},
129
+
130
+	close : function() {
131
+		var t = this;
132
+
133
+		// To avoid domain relaxing issue in Opera
134
+		function close() {
135
+			t.editor.windowManager.close(window);
136
+			tinymce = tinyMCE = t.editor = t.params = t.dom = t.dom.doc = null; // Cleanup
137
+		};
138
+
139
+		if (tinymce.isOpera)
140
+			t.getWin().setTimeout(close, 0);
141
+		else
142
+			close();
143
+	},
144
+
145
+	// Internal functions	
146
+
147
+	_restoreSelection : function() {
148
+		var e = window.event.srcElement;
149
+
150
+		if (e.nodeName == 'INPUT' && (e.type == 'submit' || e.type == 'button'))
151
+			tinyMCEPopup.restoreSelection();
152
+	},
153
+
154
+/*	_restoreSelection : function() {
155
+		var e = window.event.srcElement;
156
+
157
+		// If user focus a non text input or textarea
158
+		if ((e.nodeName != 'INPUT' && e.nodeName != 'TEXTAREA') || e.type != 'text')
159
+			tinyMCEPopup.restoreSelection();
160
+	},*/
161
+
162
+	_onDOMLoaded : function() {
163
+		var t = this, ti = document.title, bm, h;
164
+
165
+		// Translate page
166
+		h = document.body.innerHTML;
167
+
168
+		// Replace a=x with a="x" in IE
169
+		if (tinymce.isIE)
170
+			h = h.replace(/ (value|title|alt)=([^"][^\s>]+)/gi, ' $1="$2"')
171
+
172
+		document.dir = t.editor.getParam('directionality','');
173
+		document.body.innerHTML = t.editor.translate(h);
174
+		document.title = ti = t.editor.translate(ti);
175
+		document.body.style.display = '';
176
+
177
+		// Restore selection in IE when focus is placed on a non textarea or input element of the type text
178
+		if (tinymce.isIE)
179
+			document.attachEvent('onmouseup', tinyMCEPopup._restoreSelection);
180
+
181
+		t.restoreSelection();
182
+		t.resizeToInnerSize();
183
+
184
+		// Set inline title
185
+		if (!t.isWindow)
186
+			t.editor.windowManager.setTitle(window, ti);
187
+		else
188
+			window.focus();
189
+
190
+		if (!tinymce.isIE && !t.isWindow) {
191
+			tinymce.dom.Event._add(document, 'focus', function() {
192
+				t.editor.windowManager.focus(t.id)
193
+			});
194
+		}
195
+
196
+		// Patch for accessibility
197
+		tinymce.each(t.dom.select('select'), function(e) {
198
+			e.onkeydown = tinyMCEPopup._accessHandler;
199
+		});
200
+
201
+		// Call onInit
202
+		// Init must be called before focus so the selection won't get lost by the focus call
203
+		tinymce.each(t.listeners, function(o) {
204
+			o.func.call(o.scope, t.editor);
205
+		});
206
+
207
+		// Move focus to window
208
+		if (t.getWindowArg('mce_auto_focus', true)) {
209
+			window.focus();
210
+
211
+			// Focus element with mceFocus class
212
+			tinymce.each(document.forms, function(f) {
213
+				tinymce.each(f.elements, function(e) {
214
+					if (t.dom.hasClass(e, 'mceFocus') && !e.disabled) {
215
+						e.focus();
216
+						return false; // Break loop
217
+					}
218
+				});
219
+			});
220
+		}
221
+
222
+		document.onkeyup = tinyMCEPopup._closeWinKeyHandler;
223
+	},
224
+
225
+	_accessHandler : function(e) {
226
+		e = e || window.event;
227
+
228
+		if (e.keyCode == 13 || e.keyCode == 32) {
229
+			e = e.target || e.srcElement;
230
+
231
+			if (e.onchange)
232
+				e.onchange();
233
+
234
+			return tinymce.dom.Event.cancel(e);
235
+		}
236
+	},
237
+
238
+	_closeWinKeyHandler : function(e) {
239
+		e = e || window.event;
240
+
241
+		if (e.keyCode == 27)
242
+			tinyMCEPopup.close();
243
+	},
244
+
245
+	_wait : function() {
246
+		var t = this, ti;
247
+
248
+		if (tinymce.isIE && document.location.protocol != 'https:') {
249
+			// Fake DOMContentLoaded on IE
250
+			document.write('<script id=__ie_onload defer src=\'javascript:""\';><\/script>');
251
+			document.getElementById("__ie_onload").onreadystatechange = function() {
252
+				if (this.readyState == "complete") {
253
+					t._onDOMLoaded();
254
+					document.getElementById("__ie_onload").onreadystatechange = null; // Prevent leak
255
+				}
256
+			};
257
+		} else {
258
+			if (tinymce.isIE || tinymce.isWebKit) {
259
+				ti = setInterval(function() {
260
+					if (/loaded|complete/.test(document.readyState)) {
261
+						clearInterval(ti);
262
+						t._onDOMLoaded();
263
+					}
264
+				}, 10);
265
+			} else {
266
+				window.addEventListener('DOMContentLoaded', function() {
267
+					t._onDOMLoaded();
268
+				}, false);
269
+			}
270
+		}
271
+	}
272
+};
273
+
274
+tinyMCEPopup.init();
275
+tinyMCEPopup._wait(); // Wait for DOM Content Loaded