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