1 // Some global instances
2 var tinymce = null, tinyMCEPopup, tinyMCE;
6 var t = this, w, ti, li, q, i, it;
8 li = ('' + document.location.search).replace(/^\?/, '').split('&');
10 for (i=0; i<li.length; i++) {
11 it = li[i].split('=');
12 q[unescape(it[0])] = unescape(it[1]);
16 document.domain = q.mce_rdomain;
22 t.editor = tinymce.EditorManager.activeEditor;
23 t.params = t.editor.windowManager.params;
24 t.features = t.editor.windowManager.features;
27 t.dom = t.editor.windowManager.createInstance('tinymce.dom.DOMUtils', document);
29 // Enables you to skip loading the default css
30 if (t.features.popup_css !== false)
31 t.dom.loadCSS(t.features.popup_css || t.editor.settings.popup_css);
33 // Setup on init listeners
36 add : function(f, s) {
37 t.listeners.push({func : f, scope : s});
41 t.isWindow = !t.getWindowArg('mce_inline');
42 t.id = t.getWindowArg('mce_window_id');
43 t.editor.windowManager.onOpen.dispatch(t.editor.windowManager, window);
47 return window.dialogArguments || opener || parent || top;
50 getWindowArg : function(n, dv) {
51 var v = this.params[n];
53 return tinymce.is(v) ? v : dv;
56 getParam : function(n, dv) {
57 return this.editor.getParam(n, dv);
60 getLang : function(n, dv) {
61 return this.editor.getLang(n, dv);
64 execCommand : function(cmd, ui, val, a) {
68 this.restoreSelection();
69 return this.editor.execCommand(cmd, ui, val, a);
72 resizeToInnerSize : function() {
73 var t = this, n, b = document.body, vp = t.dom.getViewPort(window), dw, dh;
75 dw = t.getWindowArg('mce_width') - vp.w;
76 dh = t.getWindowArg('mce_height') - vp.h;
79 window.resizeBy(dw, dh);
81 t.editor.windowManager.resizeBy(dw, dh, t.id);
84 executeOnLoad : function(s) {
85 this.onInit.add(function() {
90 storeSelection : function() {
91 this.editor.windowManager.bookmark = tinyMCEPopup.editor.selection.getBookmark('simple');
94 restoreSelection : function() {
97 if (!t.isWindow && tinymce.isIE)
98 t.editor.selection.moveToBookmark(t.editor.windowManager.bookmark);
101 requireLangPack : function() {
102 var u = this.getWindowArg('plugin_url') || this.getWindowArg('theme_url');
104 if (u && this.editor.settings.language) {
105 u += '/langs/' + this.editor.settings.language + '_dlg.js';
107 if (!tinymce.ScriptLoader.isDone(u)) {
108 document.write('<script type="text/javascript" src="' + tinymce._addVer(u) + '"></script>');
109 tinymce.ScriptLoader.markDone(u);
114 pickColor : function(e, element_id) {
115 this.execCommand('mceColorPicker', true, {
116 color : document.getElementById(element_id).value,
118 document.getElementById(element_id).value = c;
121 document.getElementById(element_id).onchange();
123 // Try fire event, ignore errors
129 openBrowser : function(element_id, type, option) {
130 tinyMCEPopup.restoreSelection();
131 this.editor.execCallback('file_browser_callback', element_id, document.getElementById(element_id).value, type, window);
134 confirm : function(t, cb, s) {
135 this.editor.windowManager.confirm(t, cb, s, window);
138 alert : function(tx, cb, s) {
139 this.editor.windowManager.alert(tx, cb, s, window);
145 // To avoid domain relaxing issue in Opera
147 t.editor.windowManager.close(window);
148 tinymce = tinyMCE = t.editor = t.params = t.dom = t.dom.doc = null; // Cleanup
152 t.getWin().setTimeout(close, 0);
157 // Internal functions
159 _restoreSelection : function() {
160 var e = window.event.srcElement;
162 if (e.nodeName == 'INPUT' && (e.type == 'submit' || e.type == 'button'))
163 tinyMCEPopup.restoreSelection();
166 /* _restoreSelection : function() {
167 var e = window.event.srcElement;
169 // If user focus a non text input or textarea
170 if ((e.nodeName != 'INPUT' && e.nodeName != 'TEXTAREA') || e.type != 'text')
171 tinyMCEPopup.restoreSelection();
174 _onDOMLoaded : function() {
175 var t = this, ti = document.title, bm, h, nv;
178 if (t.features.translate_i18n !== false) {
179 h = document.body.innerHTML;
181 // Replace a=x with a="x" in IE
183 h = h.replace(/ (value|title|alt)=([^"][^\s>]+)/gi, ' $1="$2"')
185 document.dir = t.editor.getParam('directionality','');
187 if ((nv = t.editor.translate(h)) && nv != h)
188 document.body.innerHTML = nv;
190 if ((nv = t.editor.translate(ti)) && nv != ti)
191 document.title = ti = nv;
194 document.body.style.display = '';
196 // Restore selection in IE when focus is placed on a non textarea or input element of the type text
198 document.attachEvent('onmouseup', tinyMCEPopup._restoreSelection);
200 t.restoreSelection();
201 t.resizeToInnerSize();
205 t.editor.windowManager.setTitle(window, ti);
209 if (!tinymce.isIE && !t.isWindow) {
210 tinymce.dom.Event._add(document, 'focus', function() {
211 t.editor.windowManager.focus(t.id)
215 // Patch for accessibility
216 tinymce.each(t.dom.select('select'), function(e) {
217 e.onkeydown = tinyMCEPopup._accessHandler;
221 // Init must be called before focus so the selection won't get lost by the focus call
222 tinymce.each(t.listeners, function(o) {
223 o.func.call(o.scope, t.editor);
226 // Move focus to window
227 if (t.getWindowArg('mce_auto_focus', true)) {
230 // Focus element with mceFocus class
231 tinymce.each(document.forms, function(f) {
232 tinymce.each(f.elements, function(e) {
233 if (t.dom.hasClass(e, 'mceFocus') && !e.disabled) {
235 return false; // Break loop
241 document.onkeyup = tinyMCEPopup._closeWinKeyHandler;
244 _accessHandler : function(e) {
245 e = e || window.event;
247 if (e.keyCode == 13 || e.keyCode == 32) {
248 e = e.target || e.srcElement;
253 return tinymce.dom.Event.cancel(e);
257 _closeWinKeyHandler : function(e) {
258 e = e || window.event;
261 tinyMCEPopup.close();
267 if (tinymce.isIE && document.location.protocol != 'https:') {
268 // Fake DOMContentLoaded on IE
269 document.write('<script id=__ie_onload defer src=\'javascript:""\';><\/script>');
270 document.getElementById("__ie_onload").onreadystatechange = function() {
271 if (this.readyState == "complete") {
273 document.getElementById("__ie_onload").onreadystatechange = null; // Prevent leak
277 if (tinymce.isIE || tinymce.isWebKit) {
278 ti = setInterval(function() {
279 if (/loaded|complete/.test(document.readyState)) {
285 window.addEventListener('DOMContentLoaded', function() {
294 tinyMCEPopup._wait(); // Wait for DOM Content Loaded