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;
26 t.dom = t.editor.windowManager.createInstance('tinymce.dom.DOMUtils', document);
27 t.dom.loadCSS(t.editor.settings.popup_css);
29 // Setup on init listeners
32 add : function(f, s) {
33 t.listeners.push({func : f, scope : s});
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);
43 return window.dialogArguments || opener || parent || top;
46 getWindowArg : function(n, dv) {
47 var v = this.params[n];
49 return tinymce.is(v) ? v : dv;
52 getParam : function(n, dv) {
53 return this.editor.getParam(n, dv);
56 getLang : function(n, dv) {
57 return this.editor.getLang(n, dv);
60 execCommand : function(cmd, ui, val, a) {
64 this.restoreSelection();
65 return this.editor.execCommand(cmd, ui, val, a);
68 resizeToInnerSize : function() {
69 var t = this, n, b = document.body, vp = t.dom.getViewPort(window), dw, dh;
71 dw = t.getWindowArg('mce_width') - vp.w;
72 dh = t.getWindowArg('mce_height') - vp.h;
75 window.resizeBy(dw, dh);
77 t.editor.windowManager.resizeBy(dw, dh, t.id);
80 executeOnLoad : function(s) {
81 this.onInit.add(function() {
86 storeSelection : function() {
87 this.editor.windowManager.bookmark = tinyMCEPopup.editor.selection.getBookmark('simple');
90 restoreSelection : function() {
93 if (!t.isWindow && tinymce.isIE)
94 t.editor.selection.moveToBookmark(t.editor.windowManager.bookmark);
97 requireLangPack : function() {
98 var u = this.getWindowArg('plugin_url') || this.getWindowArg('theme_url');
100 if (u && this.editor.settings.language) {
101 u += '/langs/' + this.editor.settings.language + '_dlg.js';
103 if (!tinymce.ScriptLoader.isDone(u)) {
104 document.write('<script type="text/javascript" src="' + tinymce._addVer(u) + '"></script>');
105 tinymce.ScriptLoader.markDone(u);
110 pickColor : function(e, element_id) {
111 this.execCommand('mceColorPicker', true, {
112 color : document.getElementById(element_id).value,
114 document.getElementById(element_id).value = c;
117 document.getElementById(element_id).onchange();
119 // Try fire event, ignore errors
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);
133 // To avoid domain relaxing issue in Opera
135 t.editor.windowManager.close(window, t.id);
136 tinymce = tinyMCE = t.editor = t.params = t.dom = t.dom.doc = null; // Cleanup
140 t.getWin().setTimeout(close, 0);
145 // Internal functions
147 _restoreSelection : function() {
148 var e = window.event.srcElement;
150 if (e.nodeName == 'INPUT' && (e.type == 'submit' || e.type == 'button'))
151 tinyMCEPopup.restoreSelection();
154 /* _restoreSelection : function() {
155 var e = window.event.srcElement;
157 // If user focus a non text input or textarea
158 if ((e.nodeName != 'INPUT' && e.nodeName != 'TEXTAREA') || e.type != 'text')
159 tinyMCEPopup.restoreSelection();
162 _onDOMLoaded : function() {
163 var t = this, ti = document.title, bm, h;
166 h = document.body.innerHTML;
168 // Replace a=x with a="x" in IE
170 h = h.replace(/ (value|title|alt)=([^"][^\s>]+)/gi, ' $1="$2"')
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 = '';
177 // Restore selection in IE when focus is placed on a non textarea or input element of the type text
179 document.attachEvent('onmouseup', tinyMCEPopup._restoreSelection);
181 t.restoreSelection();
182 t.resizeToInnerSize();
186 t.editor.windowManager.setTitle(ti, t.id);
190 if (!tinymce.isIE && !t.isWindow) {
191 tinymce.dom.Event._add(document, 'focus', function() {
192 t.editor.windowManager.focus(t.id)
196 // Patch for accessibility
197 tinymce.each(t.dom.select('select'), function(e) {
198 e.onkeydown = tinyMCEPopup._accessHandler;
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);
207 // Move focus to window
208 if (t.getWindowArg('mce_auto_focus', true)) {
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) {
216 return false; // Break loop
222 document.onkeyup = tinyMCEPopup._closeWinKeyHandler;
225 _accessHandler : function(e) {
226 e = e || window.event;
228 if (e.keyCode == 13 || e.keyCode == 32) {
229 e = e.target || e.srcElement;
234 return tinymce.dom.Event.cancel(e);
238 _closeWinKeyHandler : function(e) {
239 e = e || window.event;
242 tinyMCEPopup.close();
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") {
254 document.getElementById("__ie_onload").onreadystatechange = null; // Prevent leak
258 if (tinymce.isIE || tinymce.isWebKit) {
259 ti = setInterval(function() {
260 if (/loaded|complete/.test(document.readyState)) {
266 window.addEventListener('DOMContentLoaded', function() {
275 tinyMCEPopup._wait(); // Wait for DOM Content Loaded