Revert "Add an EditForm id to the edit form"
[Melange.git] / app / tiny_mce / tiny_mce_popup.js
blobeac381781770e7afe0a849c1a0e7eb0c7fee7b85
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
28                 t.dom.loadCSS(t.features.popup_css || t.editor.settings.popup_css);\r
30                 // Setup on init listeners\r
31                 t.listeners = [];\r
32                 t.onInit = {\r
33                         add : function(f, s) {\r
34                                 t.listeners.push({func : f, scope : s});\r
35                         }\r
36                 };\r
38                 t.isWindow = !t.getWindowArg('mce_inline');\r
39                 t.id = t.getWindowArg('mce_window_id');\r
40                 t.editor.windowManager.onOpen.dispatch(t.editor.windowManager, window);\r
41         },\r
43         getWin : function() {\r
44                 return window.dialogArguments || opener || parent || top;\r
45         },\r
47         getWindowArg : function(n, dv) {\r
48                 var v = this.params[n];\r
50                 return tinymce.is(v) ? v : dv;\r
51         },\r
53         getParam : function(n, dv) {\r
54                 return this.editor.getParam(n, dv);\r
55         },\r
57         getLang : function(n, dv) {\r
58                 return this.editor.getLang(n, dv);\r
59         },\r
61         execCommand : function(cmd, ui, val, a) {\r
62                 a = a || {};\r
63                 a.skip_focus = 1;\r
65                 this.restoreSelection();\r
66                 return this.editor.execCommand(cmd, ui, val, a);\r
67         },\r
69         resizeToInnerSize : function() {\r
70                 var t = this, n, b = document.body, vp = t.dom.getViewPort(window), dw, dh;\r
72                 dw = t.getWindowArg('mce_width') - vp.w;\r
73                 dh = t.getWindowArg('mce_height') - vp.h;\r
75                 if (t.isWindow)\r
76                         window.resizeBy(dw, dh);\r
77                 else\r
78                         t.editor.windowManager.resizeBy(dw, dh, t.id);\r
79         },\r
81         executeOnLoad : function(s) {\r
82                 this.onInit.add(function() {\r
83                         eval(s);\r
84                 });\r
85         },\r
87         storeSelection : function() {\r
88                 this.editor.windowManager.bookmark = tinyMCEPopup.editor.selection.getBookmark('simple');\r
89         },\r
91         restoreSelection : function() {\r
92                 var t = tinyMCEPopup;\r
94                 if (!t.isWindow && tinymce.isIE)\r
95                         t.editor.selection.moveToBookmark(t.editor.windowManager.bookmark);\r
96         },\r
98         requireLangPack : function() {\r
99                 var u = this.getWindowArg('plugin_url') || this.getWindowArg('theme_url');\r
101                 if (u && this.editor.settings.language) {\r
102                         u += '/langs/' + this.editor.settings.language + '_dlg.js';\r
104                         if (!tinymce.ScriptLoader.isDone(u)) {\r
105                                 document.write('<script type="text/javascript" src="' + tinymce._addVer(u) + '"></script>');\r
106                                 tinymce.ScriptLoader.markDone(u);\r
107                         }\r
108                 }\r
109         },\r
111         pickColor : function(e, element_id) {\r
112                 this.execCommand('mceColorPicker', true, {\r
113                         color : document.getElementById(element_id).value,\r
114                         func : function(c) {\r
115                                 document.getElementById(element_id).value = c;\r
117                                 try {\r
118                                         document.getElementById(element_id).onchange();\r
119                                 } catch (ex) {\r
120                                         // Try fire event, ignore errors\r
121                                 }\r
122                         }\r
123                 });\r
124         },\r
126         openBrowser : function(element_id, type, option) {\r
127                 tinyMCEPopup.restoreSelection();\r
128                 this.editor.execCallback('file_browser_callback', element_id, document.getElementById(element_id).value, type, window);\r
129         },\r
131         confirm : function(t, cb, s) {\r
132                 this.editor.windowManager.confirm(t, cb, s, window);\r
133         },\r
135         alert : function(tx, cb, s) {\r
136                 this.editor.windowManager.alert(tx, cb, s, window);\r
137         },\r
139         close : function() {\r
140                 var t = this;\r
142                 // To avoid domain relaxing issue in Opera\r
143                 function close() {\r
144                         t.editor.windowManager.close(window);\r
145                         tinymce = tinyMCE = t.editor = t.params = t.dom = t.dom.doc = null; // Cleanup\r
146                 };\r
148                 if (tinymce.isOpera)\r
149                         t.getWin().setTimeout(close, 0);\r
150                 else\r
151                         close();\r
152         },\r
154         // Internal functions   \r
156         _restoreSelection : function() {\r
157                 var e = window.event.srcElement;\r
159                 if (e.nodeName == 'INPUT' && (e.type == 'submit' || e.type == 'button'))\r
160                         tinyMCEPopup.restoreSelection();\r
161         },\r
163 /*      _restoreSelection : function() {\r
164                 var e = window.event.srcElement;\r
166                 // If user focus a non text input or textarea\r
167                 if ((e.nodeName != 'INPUT' && e.nodeName != 'TEXTAREA') || e.type != 'text')\r
168                         tinyMCEPopup.restoreSelection();\r
169         },*/\r
171         _onDOMLoaded : function() {\r
172                 var t = this, ti = document.title, bm, h;\r
174                 // Translate page\r
175                 h = document.body.innerHTML;\r
177                 // Replace a=x with a="x" in IE\r
178                 if (tinymce.isIE)\r
179                         h = h.replace(/ (value|title|alt)=([^"][^\s>]+)/gi, ' $1="$2"')\r
181                 document.dir = t.editor.getParam('directionality','');\r
182                 document.body.innerHTML = t.editor.translate(h);\r
183                 document.title = ti = t.editor.translate(ti);\r
184                 document.body.style.display = '';\r
186                 // Restore selection in IE when focus is placed on a non textarea or input element of the type text\r
187                 if (tinymce.isIE)\r
188                         document.attachEvent('onmouseup', tinyMCEPopup._restoreSelection);\r
190                 t.restoreSelection();\r
191                 t.resizeToInnerSize();\r
193                 // Set inline title\r
194                 if (!t.isWindow)\r
195                         t.editor.windowManager.setTitle(window, ti);\r
196                 else\r
197                         window.focus();\r
199                 if (!tinymce.isIE && !t.isWindow) {\r
200                         tinymce.dom.Event._add(document, 'focus', function() {\r
201                                 t.editor.windowManager.focus(t.id)\r
202                         });\r
203                 }\r
205                 // Patch for accessibility\r
206                 tinymce.each(t.dom.select('select'), function(e) {\r
207                         e.onkeydown = tinyMCEPopup._accessHandler;\r
208                 });\r
210                 // Call onInit\r
211                 // Init must be called before focus so the selection won't get lost by the focus call\r
212                 tinymce.each(t.listeners, function(o) {\r
213                         o.func.call(o.scope, t.editor);\r
214                 });\r
216                 // Move focus to window\r
217                 if (t.getWindowArg('mce_auto_focus', true)) {\r
218                         window.focus();\r
220                         // Focus element with mceFocus class\r
221                         tinymce.each(document.forms, function(f) {\r
222                                 tinymce.each(f.elements, function(e) {\r
223                                         if (t.dom.hasClass(e, 'mceFocus') && !e.disabled) {\r
224                                                 e.focus();\r
225                                                 return false; // Break loop\r
226                                         }\r
227                                 });\r
228                         });\r
229                 }\r
231                 document.onkeyup = tinyMCEPopup._closeWinKeyHandler;\r
232         },\r
234         _accessHandler : function(e) {\r
235                 e = e || window.event;\r
237                 if (e.keyCode == 13 || e.keyCode == 32) {\r
238                         e = e.target || e.srcElement;\r
240                         if (e.onchange)\r
241                                 e.onchange();\r
243                         return tinymce.dom.Event.cancel(e);\r
244                 }\r
245         },\r
247         _closeWinKeyHandler : function(e) {\r
248                 e = e || window.event;\r
250                 if (e.keyCode == 27)\r
251                         tinyMCEPopup.close();\r
252         },\r
254         _wait : function() {\r
255                 var t = this, ti;\r
257                 if (tinymce.isIE && document.location.protocol != 'https:') {\r
258                         // Fake DOMContentLoaded on IE\r
259                         document.write('<script id=__ie_onload defer src=\'javascript:""\';><\/script>');\r
260                         document.getElementById("__ie_onload").onreadystatechange = function() {\r
261                                 if (this.readyState == "complete") {\r
262                                         t._onDOMLoaded();\r
263                                         document.getElementById("__ie_onload").onreadystatechange = null; // Prevent leak\r
264                                 }\r
265                         };\r
266                 } else {\r
267                         if (tinymce.isIE || tinymce.isWebKit) {\r
268                                 ti = setInterval(function() {\r
269                                         if (/loaded|complete/.test(document.readyState)) {\r
270                                                 clearInterval(ti);\r
271                                                 t._onDOMLoaded();\r
272                                         }\r
273                                 }, 10);\r
274                         } else {\r
275                                 window.addEventListener('DOMContentLoaded', function() {\r
276                                         t._onDOMLoaded();\r
277                                 }, false);\r
278                         }\r
279                 }\r
280         }\r
281 };\r
283 tinyMCEPopup.init();\r
284 tinyMCEPopup._wait(); // Wait for DOM Content Loaded\r