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