]> git.koha-community.org Git - koha.git/blob - koha-tt/intranet-tmpl/prog/en/js/tinymce/jscripts/tiny_mce/plugins/inlinepopups/editor_plugin_src.js
Bug 5917 / Bug 6085 : Fixing not being able to change language
[koha.git] / koha-tt / intranet-tmpl / prog / en / js / tinymce / jscripts / tiny_mce / plugins / inlinepopups / editor_plugin_src.js
1 /**
2  * $Id: editor_plugin_src.js 268 2007-04-28 15:52:59Z spocke $
3  *
4  * Moxiecode DHTML Windows script.
5  *
6  * @author Moxiecode
7  * @copyright Copyright © 2004-2007, Moxiecode Systems AB, All rights reserved.
8  */
9
10 // Patch openWindow, closeWindow TinyMCE functions
11
12 var TinyMCE_InlinePopupsPlugin = {
13         getInfo : function() {
14                 return {
15                         longname : 'Inline Popups',
16                         author : 'Moxiecode Systems AB',
17                         authorurl : 'http://tinymce.moxiecode.com',
18                         infourl : 'http://wiki.moxiecode.com/index.php/TinyMCE:Plugins/inlinepopups',
19                         version : tinyMCE.majorVersion + "." + tinyMCE.minorVersion
20                 };
21         }
22 };
23
24 tinyMCE.addPlugin("inlinepopups", TinyMCE_InlinePopupsPlugin);
25
26 // Patch openWindow, closeWindow TinyMCE functions
27
28 TinyMCE_Engine.prototype.orgOpenWindow = TinyMCE_Engine.prototype.openWindow;
29 TinyMCE_Engine.prototype.orgCloseWindow = TinyMCE_Engine.prototype.closeWindow;
30
31 TinyMCE_Engine.prototype.openWindow = function(template, args) {
32         // Does the caller support inline
33         if (args['inline'] != "yes" || tinyMCE.isOpera || tinyMCE.getParam("plugins").indexOf('inlinepopups') == -1) {
34                 mcWindows.selectedWindow = null;
35                 args['mce_inside_iframe'] = false;
36                 this.orgOpenWindow(template, args);
37                 return;
38         }
39
40         var url, resizable, scrollbars;
41
42         args['mce_inside_iframe'] = true;
43         tinyMCE.windowArgs = args;
44
45         if (template['file'].charAt(0) != '/' && template['file'].indexOf('://') == -1)
46                 url = tinyMCE.baseURL + "/themes/" + tinyMCE.getParam("theme") + "/" + template['file'];
47         else
48                 url = template['file'];
49
50         if (!(width = parseInt(template['width'])))
51                 width = 320;
52
53         if (!(height = parseInt(template['height'])))
54                 height = 200;
55
56         if (!(minWidth = parseInt(template['minWidth'])))
57                 minWidth = 100;
58
59         if (!(minHeight = parseInt(template['minHeight'])))
60                 minHeight = 100;
61
62         resizable = (args && args['resizable']) ? args['resizable'] : "no";
63         scrollbars = (args && args['scrollbars']) ? args['scrollbars'] : "no";
64
65         height += 18;
66
67         // Replace all args as variables in URL
68         for (var name in args) {
69                 if (typeof(args[name]) == 'function')
70                         continue;
71
72                 url = tinyMCE.replaceVar(url, name, escape(args[name]));
73         }
74
75         var elm = document.getElementById(this.selectedInstance.editorId + '_parent');
76
77         if (tinyMCE.hasPlugin('fullscreen') && this.selectedInstance.getData('fullscreen').enabled)
78                 pos = { absLeft: 0, absTop: 0 };
79         else
80                 pos = tinyMCE.getAbsPosition(elm);
81
82         // Center div in editor area
83         pos.absLeft += Math.round((elm.firstChild.clientWidth / 2) - (width / 2));
84         pos.absTop += Math.round((elm.firstChild.clientHeight / 2) - (height / 2));
85
86         mcWindows.open(url, mcWindows.idCounter++, "modal=yes,width=" + width+ ",height=" + height + ",resizable=" + resizable + ",scrollbars=" + scrollbars + ",statusbar=" + resizable + ",left=" + pos.absLeft + ",top=" + pos.absTop + ",minWidth=" + minWidth + ",minHeight=" + minHeight );
87 };
88
89 TinyMCE_Engine.prototype.closeWindow = function(win) {
90         var gotit = false, n, w;
91
92         for (n in mcWindows.windows) {
93                 w = mcWindows.windows[n];
94
95                 if (typeof(w) == 'function')
96                         continue;
97
98                 if (win.name == w.id + '_iframe') {
99                         w.close();
100                         gotit = true;
101                 }
102         }
103
104         if (!gotit)
105                 this.orgCloseWindow(win);
106
107         tinyMCE.selectedInstance.getWin().focus(); 
108 };
109
110 TinyMCE_Engine.prototype.setWindowTitle = function(win_ref, title) {
111         for (var n in mcWindows.windows) {
112                 var win = mcWindows.windows[n];
113                 if (typeof(win) == 'function')
114                         continue;
115
116                 if (win_ref.name == win.id + "_iframe")
117                         window.frames[win.id + "_iframe"].document.getElementById(win.id + '_title').innerHTML = title;
118         }
119 };
120
121 // * * * * * TinyMCE_Windows classes below
122
123 // Windows handler
124 function TinyMCE_Windows() {
125         this.settings = new Array();
126         this.windows = new Array();
127         this.isMSIE = (navigator.appName == "Microsoft Internet Explorer");
128         this.isGecko = navigator.userAgent.indexOf('Gecko') != -1;
129         this.isSafari = navigator.userAgent.indexOf('Safari') != -1;
130         this.isMac = navigator.userAgent.indexOf('Mac') != -1;
131         this.isMSIE5_0 = this.isMSIE && (navigator.userAgent.indexOf('MSIE 5.0') != -1);
132         this.action = "none";
133         this.selectedWindow = null;
134         this.lastSelectedWindow = null;
135         this.zindex = 1001;
136         this.mouseDownScreenX = 0;
137         this.mouseDownScreenY = 0;
138         this.mouseDownLayerX = 0;
139         this.mouseDownLayerY = 0;
140         this.mouseDownWidth = 0;
141         this.mouseDownHeight = 0;
142         this.idCounter = 0;
143 };
144
145 TinyMCE_Windows.prototype.init = function(settings) {
146         this.settings = settings;
147
148         if (this.isMSIE)
149                 this.addEvent(document, "mousemove", mcWindows.eventDispatcher);
150         else
151                 this.addEvent(window, "mousemove", mcWindows.eventDispatcher);
152
153         this.addEvent(document, "mouseup", mcWindows.eventDispatcher);
154
155         this.addEvent(window, "resize", mcWindows.eventDispatcher);
156         this.addEvent(document, "scroll", mcWindows.eventDispatcher);
157
158         this.doc = document;
159 };
160
161 TinyMCE_Windows.prototype.getBounds = function() {
162         if (!this.bounds) {
163                 var vp = tinyMCE.getViewPort(window);
164                 var top, left, bottom, right, docEl = this.doc.documentElement;
165
166                 top    = vp.top;
167                 left   = vp.left;
168                 bottom = vp.height + top - 2;
169                 right  = vp.width  + left - 22; // TODO this number is platform dependant
170                 // x1, y1, x2, y2
171                 this.bounds = [left, top, right, bottom];
172         }
173         return this.bounds;
174 };
175
176 TinyMCE_Windows.prototype.clampBoxPosition = function(x, y, w, h, minW, minH) {
177         var bounds = this.getBounds();
178
179         x = Math.max(bounds[0], Math.min(bounds[2], x + w) - w);
180         y = Math.max(bounds[1], Math.min(bounds[3], y + h) - h);
181
182         return this.clampBoxSize(x, y, w, h, minW, minH);
183 };
184
185 TinyMCE_Windows.prototype.clampBoxSize = function(x, y, w, h, minW, minH) {
186         var bounds = this.getBounds();
187
188         return [
189                 x, y,
190                 Math.max(minW, Math.min(bounds[2], x + w) - x),
191                 Math.max(minH, Math.min(bounds[3], y + h) - y)
192         ];
193 };
194
195 TinyMCE_Windows.prototype.getParam = function(name, default_value) {
196         var value = null;
197
198         value = (typeof(this.settings[name]) == "undefined") ? default_value : this.settings[name];
199
200         // Fix bool values
201         if (value == "true" || value == "false")
202                 return (value == "true");
203
204         return value;
205 };
206
207 TinyMCE_Windows.prototype.eventDispatcher = function(e) {
208         e = typeof(e) == "undefined" ? window.event : e;
209
210         if (mcWindows.selectedWindow == null)
211                 return;
212
213         // Switch focus
214         if (mcWindows.isGecko && e.type == "mousedown") {
215                 var elm = e.currentTarget;
216
217                 for (var n in mcWindows.windows) {
218                         var win = mcWindows.windows[n];
219
220                         if (win.headElement == elm || win.resizeElement == elm) {
221                                 win.focus();
222                                 break;
223                         }
224                 }
225         }
226
227         switch (e.type) {
228                 case "mousemove":
229                         mcWindows.selectedWindow.onMouseMove(e);
230                         break;
231
232                 case "mouseup":
233                         mcWindows.selectedWindow.onMouseUp(e);
234                         break;
235
236                 case "mousedown":
237                         mcWindows.selectedWindow.onMouseDown(e);
238                         break;
239
240                 case "focus":
241                         mcWindows.selectedWindow.onFocus(e);
242                         break;
243                 case "scroll":
244                 case "resize":
245                         if (mcWindows.clampUpdateTimeout)
246                                 clearTimeout(mcWindows.clampUpdateTimeout);
247                         mcWindows.clampEventType = e.type;
248                         mcWindows.clampUpdateTimeout =
249                                 setTimeout(function () {mcWindows.updateClamping()}, 100);
250                         break;
251         }
252 };
253
254 TinyMCE_Windows.prototype.updateClamping = function () {
255         var clamp, oversize, etype = mcWindows.clampEventType;
256
257         this.bounds = null; // Recalc window bounds on resize/scroll
258         this.clampUpdateTimeout = null;
259
260         for (var n in this.windows) {
261                 win = this.windows[n];
262                 if (typeof(win) == 'function' || ! win.winElement) continue;
263
264                 clamp = mcWindows.clampBoxPosition(
265                         win.left, win.top,
266                         win.winElement.scrollWidth,
267                         win.winElement.scrollHeight,
268                         win.features.minWidth,
269                         win.features.minHeight
270                 );
271                 oversize = (
272                         clamp[2] != win.winElement.scrollWidth ||
273                         clamp[3] != win.winElement.scrollHeight
274                 ) ? true : false;
275
276                 if (!oversize || win.features.resizable == "yes" || etype != "scroll")
277                         win.moveTo(clamp[0], clamp[1]);
278                 if (oversize && win.features.resizable == "yes")
279                         win.resizeTo(clamp[2], clamp[3]);
280         }
281 };
282
283 TinyMCE_Windows.prototype.addEvent = function(obj, name, handler) {
284         if (this.isMSIE)
285                 obj.attachEvent("on" + name, handler);
286         else
287                 obj.addEventListener(name, handler, false);
288 };
289
290 TinyMCE_Windows.prototype.cancelEvent = function(e) {
291         if (this.isMSIE) {
292                 e.returnValue = false;
293                 e.cancelBubble = true;
294         } else
295                 e.preventDefault();
296 };
297
298 TinyMCE_Windows.prototype.parseFeatures = function(opts) {
299         // Cleanup the options
300         opts = opts.toLowerCase();
301         opts = opts.replace(/;/g, ",");
302         opts = opts.replace(/[^0-9a-z=,]/g, "");
303
304         var optionChunks = opts.split(',');
305         var options = new Array();
306
307         options['left'] = "10";
308         options['top'] = "10";
309         options['width'] = "300";
310         options['height'] = "300";
311         options['minwidth'] = "100";
312         options['minheight'] = "100";
313         options['resizable'] = "yes";
314         options['minimizable'] = "yes";
315         options['maximizable'] = "yes";
316         options['close'] = "yes";
317         options['movable'] = "yes";
318         options['statusbar'] = "yes";
319         options['scrollbars'] = "auto";
320         options['modal'] = "no";
321
322         if (opts == "")
323                 return options;
324
325         for (var i=0; i<optionChunks.length; i++) {
326                 var parts = optionChunks[i].split('=');
327
328                 if (parts.length == 2)
329                         options[parts[0]] = parts[1];
330         }
331
332         options['left'] = parseInt(options['left']);
333         options['top'] = parseInt(options['top']);
334         options['width'] = parseInt(options['width']);
335         options['height'] = parseInt(options['height']);
336         options['minWidth'] = parseInt(options['minwidth']);
337         options['minHeight'] = parseInt(options['minheight']);
338
339         return options;
340 };
341
342 TinyMCE_Windows.prototype.open = function(url, name, features) {
343         this.lastSelectedWindow = this.selectedWindow;
344
345         var win = new TinyMCE_Window();
346         var winDiv, html = "", id;
347         var imgPath = this.getParam("images_path");
348
349         features = this.parseFeatures(features);
350
351         // Clamp specified dimensions
352         var clamp = mcWindows.clampBoxPosition(
353                 features['left'], features['top'],
354                 features['width'], features['height'],
355                 features['minWidth'], features['minHeight']
356         );
357
358         features['left'] = clamp[0];
359         features['top'] = clamp[1];
360
361         if (features['resizable'] == "yes") {
362                 features['width'] = clamp[2];
363                 features['height'] = clamp[3];
364         }
365
366         // Create div
367         id = "mcWindow_" + name;
368         win.deltaHeight = 18;
369
370         if (features['statusbar'] == "yes") {
371                 win.deltaHeight += 13;
372
373                 if (this.isMSIE)
374                         win.deltaHeight += 1;
375         }
376
377         width = parseInt(features['width']);
378         height = parseInt(features['height'])-win.deltaHeight;
379
380         if (this.isMSIE)
381                 width -= 2;
382
383         // Setup first part of window
384         win.id = id;
385         win.url = url;
386         win.name = name;
387         win.features = features;
388         this.windows[name] = win;
389
390         iframeWidth = width;
391         iframeHeight = height;
392
393         // Create inner content
394         html += '<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">';
395         html += '<html>';
396         html += '<head>';
397         html += '<title>Wrapper iframe</title>';
398         html += '<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">';
399         html += '<link href="' + this.getParam("css_file") + '" rel="stylesheet" type="text/css" />';
400         html += '</head>';
401         html += '<body onload="parent.mcWindows.onLoad(\'' + name + '\');">';
402
403         html += '<div id="' + id + '_container" class="mceWindow">';
404         html += '<div id="' + id + '_head" class="mceWindowHead" onmousedown="parent.mcWindows.windows[\'' + name + '\'].focus();">';
405         html += '  <div id="' + id + '_title" class="mceWindowTitle"';
406         html += '  onselectstart="return false;" unselectable="on" style="-moz-user-select: none !important;"></div>';
407         html += '    <div class="mceWindowHeadTools">';
408         html += '      <a href="javascript:parent.mcWindows.windows[\'' + name + '\'].close();" target="_self" onmousedown="return false;" class="mceWindowClose"><img border="0" src="' + imgPath + '/window_close.gif" /></a>';
409         if (features['resizable'] == "yes" && features['maximizable'] == "yes")
410                 html += '      <a href="javascript:parent.mcWindows.windows[\'' + name + '\'].maximize();" target="_self" onmousedown="return false;" class="mceWindowMaximize"><img border="0" src="' + imgPath + '/window_maximize.gif" /></a>';
411         // html += '      <a href="javascript:mcWindows.windows[\'' + name + '\'].minimize();" target="_self" onmousedown="return false;" class="mceWindowMinimize"></a>';
412         html += '    </div>';
413         html += '</div><div id="' + id + '_body" class="mceWindowBody" style="width: ' + width + 'px; height: ' + height + 'px;">';
414         html += '<iframe id="' + id + '_iframe" name="' + id + '_iframe" frameborder="0" width="' + iframeWidth + '" height="' + iframeHeight + '" src="' + url + '" class="mceWindowBodyIframe" scrolling="' + features['scrollbars'] + '"></iframe></div>';
415
416         if (features['statusbar'] == "yes") {
417                 html += '<div id="' + id + '_statusbar" class="mceWindowStatusbar" onmousedown="parent.mcWindows.windows[\'' + name + '\'].focus();">';
418
419                 if (features['resizable'] == "yes") {
420                         if (this.isGecko)
421                                 html += '<div id="' + id + '_resize" class="mceWindowResize"><div style="background-image: url(\'' + imgPath + '/window_resize.gif\'); width: 12px; height: 12px;"></div></div>';
422                         else
423                                 html += '<div id="' + id + '_resize" class="mceWindowResize"><img onmousedown="parent.mcWindows.windows[\'' + name + '\'].focus();" border="0" src="' + imgPath + '/window_resize.gif" /></div>';
424                 }
425
426                 html += '</div>';
427         }
428
429         html += '</div>';
430
431         html += '</body>';
432         html += '</html>';
433
434         // Create iframe
435         this.createFloatingIFrame(id, features['left'], features['top'], features['width'], features['height'], html);
436 };
437
438 // Blocks the document events by placing a image over the whole document
439 TinyMCE_Windows.prototype.setDocumentLock = function(state) {
440         var elm = document.getElementById('mcWindowEventBlocker');
441
442         if (state) {
443                 if (elm == null) {
444                         elm = document.createElement("div");
445
446                         elm.id = "mcWindowEventBlocker";
447                         elm.style.position = "absolute";
448                         elm.style.left = "0";
449                         elm.style.top = "0";
450
451                         document.body.appendChild(elm);
452                 }
453
454                 elm.style.display = "none";
455
456                 var imgPath = this.getParam("images_path");
457                 var width = document.body.clientWidth;
458                 var height = document.body.clientHeight;
459
460                 elm.style.width = width;
461                 elm.style.height = height;
462                 elm.innerHTML = '<img src="' + imgPath + '/spacer.gif" width="' + width + '" height="' + height + '" />';
463
464                 elm.style.zIndex = mcWindows.zindex-1;
465                 elm.style.display = "block";
466         } else if (elm != null) {
467                 if (mcWindows.windows.length == 0)
468                         elm.parentNode.removeChild(elm);
469                 else
470                         elm.style.zIndex = mcWindows.zindex-1;
471         }
472 };
473
474 // Gets called when wrapper iframe is initialized
475 TinyMCE_Windows.prototype.onLoad = function(name) {
476         var win = mcWindows.windows[name];
477         var id = "mcWindow_" + name;
478         var wrapperIframe = window.frames[id + "_iframe"].frames[0];
479         var wrapperDoc = window.frames[id + "_iframe"].document;
480         var doc = window.frames[id + "_iframe"].document;
481         var winDiv = document.getElementById("mcWindow_" + name + "_div");
482         var realIframe = window.frames[id + "_iframe"].frames[0];
483
484         // Set window data
485         win.id = "mcWindow_" + name;
486         win.winElement = winDiv;
487         win.bodyElement = doc.getElementById(id + '_body');
488         win.iframeElement = doc.getElementById(id + '_iframe');
489         win.headElement = doc.getElementById(id + '_head');
490         win.titleElement = doc.getElementById(id + '_title');
491         win.resizeElement = doc.getElementById(id + '_resize');
492         win.containerElement = doc.getElementById(id + '_container');
493         win.left = win.features['left'];
494         win.top = win.features['top'];
495         win.frame = window.frames[id + '_iframe'].frames[0];
496         win.wrapperFrame = window.frames[id + '_iframe'];
497         win.wrapperIFrameElement = document.getElementById(id + "_iframe");
498
499         // Add event handlers
500         mcWindows.addEvent(win.headElement, "mousedown", mcWindows.eventDispatcher);
501
502         if (win.resizeElement != null)
503                 mcWindows.addEvent(win.resizeElement, "mousedown", mcWindows.eventDispatcher);
504
505         if (mcWindows.isMSIE) {
506                 mcWindows.addEvent(realIframe.document, "mousemove", mcWindows.eventDispatcher);
507                 mcWindows.addEvent(realIframe.document, "mouseup", mcWindows.eventDispatcher);
508         } else {
509                 mcWindows.addEvent(realIframe, "mousemove", mcWindows.eventDispatcher);
510                 mcWindows.addEvent(realIframe, "mouseup", mcWindows.eventDispatcher);
511                 mcWindows.addEvent(realIframe, "focus", mcWindows.eventDispatcher);
512         }
513
514         for (var i=0; i<window.frames.length; i++) {
515                 if (!window.frames[i]._hasMouseHandlers) {
516                         if (mcWindows.isMSIE) {
517                                 mcWindows.addEvent(window.frames[i].document, "mousemove", mcWindows.eventDispatcher);
518                                 mcWindows.addEvent(window.frames[i].document, "mouseup", mcWindows.eventDispatcher);
519                         } else {
520                                 mcWindows.addEvent(window.frames[i], "mousemove", mcWindows.eventDispatcher);
521                                 mcWindows.addEvent(window.frames[i], "mouseup", mcWindows.eventDispatcher);
522                         }
523
524                         window.frames[i]._hasMouseHandlers = true;
525                 }
526         }
527
528         if (mcWindows.isMSIE) {
529                 mcWindows.addEvent(win.frame.document, "mousemove", mcWindows.eventDispatcher);
530                 mcWindows.addEvent(win.frame.document, "mouseup", mcWindows.eventDispatcher);
531         } else {
532                 mcWindows.addEvent(win.frame, "mousemove", mcWindows.eventDispatcher);
533                 mcWindows.addEvent(win.frame, "mouseup", mcWindows.eventDispatcher);
534                 mcWindows.addEvent(win.frame, "focus", mcWindows.eventDispatcher);
535         }
536
537         // Dispatch open window event
538         var func = this.getParam("on_open_window", "");
539         if (func != "")
540                 eval(func + "(win);");
541
542         win.focus();
543
544         if (win.features['modal'] == "yes")
545                 mcWindows.setDocumentLock(true);
546 };
547
548 TinyMCE_Windows.prototype.createFloatingIFrame = function(id_prefix, left, top, width, height, html) {
549         var iframe = document.createElement("iframe");
550         var div = document.createElement("div"), doc;
551
552         width = parseInt(width);
553         height = parseInt(height)+1;
554
555         // Create wrapper div
556         div.setAttribute("id", id_prefix + "_div");
557         div.setAttribute("width", width);
558         div.setAttribute("height", (height));
559         div.style.position = "absolute";
560
561         div.style.left = left + "px";
562         div.style.top = top + "px";
563         div.style.width = width + "px";
564         div.style.height = (height) + "px";
565         div.style.backgroundColor = "white";
566         div.style.display = "none";
567
568         if (this.isGecko) {
569                 iframeWidth = width + 2;
570                 iframeHeight = height + 2;
571         } else {
572                 iframeWidth = width;
573                 iframeHeight = height + 1;
574         }
575
576         // Create iframe
577         iframe.setAttribute("id", id_prefix + "_iframe");
578         iframe.setAttribute("name", id_prefix + "_iframe");
579         iframe.setAttribute("border", "0");
580         iframe.setAttribute("frameBorder", "0");
581         iframe.setAttribute("marginWidth", "0");
582         iframe.setAttribute("marginHeight", "0");
583         iframe.setAttribute("leftMargin", "0");
584         iframe.setAttribute("topMargin", "0");
585         iframe.setAttribute("width", iframeWidth);
586         iframe.setAttribute("height", iframeHeight);
587         // iframe.setAttribute("src", "../jscripts/tiny_mce/blank.htm");
588         // iframe.setAttribute("allowtransparency", "false");
589         iframe.setAttribute("scrolling", "no");
590         iframe.style.width = iframeWidth + "px";
591         iframe.style.height = iframeHeight + "px";
592         iframe.style.backgroundColor = "white";
593         div.appendChild(iframe);
594
595         document.body.appendChild(div);
596
597         // Fixed MSIE 5.0 issue
598         div.innerHTML = div.innerHTML;
599
600         if (this.isSafari) {
601                 // Give Safari some time to setup
602                 window.setTimeout(function() {
603                         var doc = window.frames[id_prefix + '_iframe'].document;
604                         doc.open();
605                         doc.write(html);
606                         doc.close();
607                 }, 10);
608         } else {
609                 doc = window.frames[id_prefix + '_iframe'].window.document;
610                 doc.open();
611                 doc.write(html);
612                 doc.close();
613         }
614
615         div.style.display = "block";
616
617         return div;
618 };
619
620 // Window instance
621 function TinyMCE_Window() {
622 };
623
624 TinyMCE_Window.prototype.focus = function() {
625         if (this != mcWindows.selectedWindow) {
626                 this.winElement.style.zIndex = ++mcWindows.zindex;
627                 mcWindows.lastSelectedWindow = mcWindows.selectedWindow;
628                 mcWindows.selectedWindow = this;
629         }
630 };
631
632 TinyMCE_Window.prototype.minimize = function() {
633 };
634
635 TinyMCE_Window.prototype.maximize = function() {
636         if (this.restoreSize) {
637                 this.moveTo(this.restoreSize[0], this.restoreSize[1]);
638                 this.resizeTo(this.restoreSize[2], this.restoreSize[3]);
639                 this.updateClamping();
640                 this.restoreSize = null;
641         } else {
642                 var bounds = mcWindows.getBounds();
643                 this.restoreSize = [
644                         this.left, this.top,
645                         this.winElement.scrollWidth,
646                         this.winElement.scrollHeight
647                 ];
648                 this.moveTo(bounds[0], bounds[1]);
649                 this.resizeTo(
650                         bounds[2] - bounds[0],
651                         bounds[3] - bounds[1]
652                 );
653         }
654 };
655
656 TinyMCE_Window.prototype.startResize = function() {
657         mcWindows.action = "resize";
658 };
659
660 TinyMCE_Window.prototype.startMove = function(e) {
661         mcWindows.action = "move";
662 };
663
664 TinyMCE_Window.prototype.close = function() {
665         if (this.frame && this.frame['tinyMCEPopup'])
666                 this.frame['tinyMCEPopup'].restoreSelection();
667
668         if (mcWindows.lastSelectedWindow != null)
669                 mcWindows.lastSelectedWindow.focus();
670
671         var mcWindowsNew = new Array();
672         for (var n in mcWindows.windows) {
673                 var win = mcWindows.windows[n];
674                 if (typeof(win) == 'function')
675                         continue;
676
677                 if (win.name != this.name)
678                         mcWindowsNew[n] = win;
679         }
680
681         mcWindows.windows = mcWindowsNew;
682
683         // alert(mcWindows.doc.getElementById(this.id + "_iframe"));
684
685         var e = mcWindows.doc.getElementById(this.id + "_iframe");
686         e.parentNode.removeChild(e);
687
688         var e = mcWindows.doc.getElementById(this.id + "_div");
689         e.parentNode.removeChild(e);
690
691         mcWindows.setDocumentLock(false);
692 };
693
694 TinyMCE_Window.prototype.onMouseMove = function(e) {
695         var clamp;
696         // Calculate real X, Y
697         var dx = e.screenX - mcWindows.mouseDownScreenX;
698         var dy = e.screenY - mcWindows.mouseDownScreenY;
699
700         switch (mcWindows.action) {
701                 case "resize":
702                         clamp = mcWindows.clampBoxSize(
703                                 this.left, this.top,
704                                 mcWindows.mouseDownWidth + (e.screenX - mcWindows.mouseDownScreenX),
705                                 mcWindows.mouseDownHeight + (e.screenY - mcWindows.mouseDownScreenY),
706                                 this.features.minWidth, this.features.minHeight
707                         );
708
709                         this.resizeTo(clamp[2], clamp[3]);
710
711                         mcWindows.cancelEvent(e);
712                         break;
713
714                 case "move":
715                         this.left = mcWindows.mouseDownLayerX + (e.screenX - mcWindows.mouseDownScreenX);
716                         this.top = mcWindows.mouseDownLayerY + (e.screenY - mcWindows.mouseDownScreenY);
717                         this.updateClamping();
718
719                         mcWindows.cancelEvent(e);
720                         break;
721         }
722 };
723
724 TinyMCE_Window.prototype.moveTo = function (x, y) {
725         this.left = x;
726         this.top = y;
727
728         this.winElement.style.left = this.left + "px";
729         this.winElement.style.top = this.top + "px";
730 };
731
732 TinyMCE_Window.prototype.resizeTo = function (width, height) {
733         this.wrapperIFrameElement.style.width = (width+2) + 'px';
734         this.wrapperIFrameElement.style.height = (height+2) + 'px';
735         this.wrapperIFrameElement.width = width+2;
736         this.wrapperIFrameElement.height = height+2;
737         this.winElement.style.width = width + 'px';
738         this.winElement.style.height = height + 'px';
739
740         height = height - this.deltaHeight;
741
742         this.containerElement.style.width = width + 'px';
743         this.iframeElement.style.width = width + 'px';
744         this.iframeElement.style.height = height + 'px';
745         this.bodyElement.style.width = width + 'px';
746         this.bodyElement.style.height = height + 'px';
747         this.headElement.style.width = width + 'px';
748         //this.statusElement.style.width = width + 'px';
749 };
750
751 TinyMCE_Window.prototype.updateClamping = function () {
752         var clamp, oversize;
753
754         clamp = mcWindows.clampBoxPosition(
755                 this.left, this.top,
756                 this.winElement.scrollWidth,
757                 this.winElement.scrollHeight,
758                 this.features.minWidth, this.features.minHeight
759         );
760         oversize = (
761                 clamp[2] != this.winElement.scrollWidth ||
762                 clamp[3] != this.winElement.scrollHeight
763         ) ? true : false;
764
765         this.moveTo(clamp[0], clamp[1]);
766         if (this.features.resizable == "yes" && oversize)
767                 this.resizeTo(clamp[2], clamp[3]);
768 };
769
770 function debug(msg) {
771         document.getElementById('debug').value += msg + "\n";
772 }
773
774 TinyMCE_Window.prototype.onMouseUp = function(e) {
775         mcWindows.action = "none";
776 };
777
778 TinyMCE_Window.prototype.onFocus = function(e) {
779         // Gecko only handler
780         var winRef = e.currentTarget;
781
782         for (var n in mcWindows.windows) {
783                 var win = mcWindows.windows[n];
784                 if (typeof(win) == 'function')
785                         continue;
786
787                 if (winRef.name == win.id + "_iframe") {
788                         win.focus();
789                         return;
790                 }
791         }
792 };
793
794 TinyMCE_Window.prototype.onMouseDown = function(e) {
795         var elm = mcWindows.isMSIE ? this.wrapperFrame.event.srcElement : e.target;
796
797         mcWindows.mouseDownScreenX = e.screenX;
798         mcWindows.mouseDownScreenY = e.screenY;
799         mcWindows.mouseDownLayerX = this.left;
800         mcWindows.mouseDownLayerY = this.top;
801         mcWindows.mouseDownWidth = parseInt(this.winElement.style.width);
802         mcWindows.mouseDownHeight = parseInt(this.winElement.style.height);
803
804         if (this.resizeElement != null && elm == this.resizeElement.firstChild)
805                 this.startResize(e);
806         else
807                 this.startMove(e);
808
809         mcWindows.cancelEvent(e);
810 };
811
812 // Global instance
813 var mcWindows = new TinyMCE_Windows();
814
815 // Initialize windows
816 mcWindows.init({
817         images_path : tinyMCE.baseURL + "/plugins/inlinepopups/images",
818         css_file : tinyMCE.baseURL + "/plugins/inlinepopups/css/inlinepopup.css"
819 });