6 * Moxiecode DHTML Windows script.
9 * @copyright Copyright © 2004, Moxiecode Systems AB, All rights reserved.
12 // Patch openWindow, closeWindow TinyMCE functions
14 function TinyMCE_inlinepopups_getInfo() {
16 longname : 'Inline Popups',
17 author : 'Moxiecode Systems',
18 authorurl : 'http://tinymce.moxiecode.com',
19 infourl : 'http://tinymce.moxiecode.com/tinymce/docs/plugin_inlinepopups.html',
20 version : tinyMCE.majorVersion + "." + tinyMCE.minorVersion
24 TinyMCE.prototype.orgOpenWindow = TinyMCE.prototype.openWindow;
26 TinyMCE.prototype.openWindow = function(template, args) {
27 // Does the caller support inline
28 if (args['inline'] != "yes") {
29 mcWindows.selectedWindow = null;
30 args['mce_inside_iframe'] = false;
31 this.orgOpenWindow(template, args);
35 var url, resizable, scrollbars;
37 args['mce_inside_iframe'] = true;
38 tinyMCE.windowArgs = args;
40 if (template['file'].charAt(0) != '/' && template['file'].indexOf('://') == -1)
41 url = tinyMCE.baseURL + "/themes/" + tinyMCE.getParam("theme") + "/" + template['file'];
43 url = template['file'];
45 if (!(width = parseInt(template['width'])))
48 if (!(height = parseInt(template['height'])))
51 resizable = (args && args['resizable']) ? args['resizable'] : "no";
52 scrollbars = (args && args['scrollbars']) ? args['scrollbars'] : "no";
56 // Replace all args as variables in URL
57 for (var name in args) {
58 if (typeof(args[name]) == 'function')
61 url = tinyMCE.replaceVar(url, name, escape(args[name]));
64 var elm = document.getElementById(this.selectedInstance.editorId + '_parent');
65 var pos = tinyMCE.getAbsPosition(elm);
67 // Center div in editor area
68 pos.absLeft += Math.round((elm.firstChild.clientWidth / 2) - (width / 2));
69 pos.absTop += Math.round((elm.firstChild.clientHeight / 2) - (height / 2));
71 mcWindows.open(url, mcWindows.idCounter++, "modal=yes,width=" + width+ ",height=" + height + ",resizable=" + resizable + ",scrollbars=" + scrollbars + ",statusbar=" + resizable + ",left=" + pos.absLeft + ",top=" + pos.absTop);
74 TinyMCE.prototype.orgCloseWindow = TinyMCE.prototype.closeWindow;
76 TinyMCE.prototype.closeWindow = function(win) {
77 if (mcWindows.selectedWindow != null)
78 mcWindows.selectedWindow.close();
80 this.orgCloseWindow(win);
83 TinyMCE.prototype.setWindowTitle = function(win_ref, title) {
84 for (var n in mcWindows.windows) {
85 var win = mcWindows.windows[n];
86 if (typeof(win) == 'function')
89 if (win_ref.name == win.id + "_iframe")
90 window.frames[win.id + "_iframe"].document.getElementById(win.id + '_title').innerHTML = title;
94 // * * * * * MCWindows classes below
97 function MCWindows() {
98 this.settings = new Array();
99 this.windows = new Array();
100 this.isMSIE = (navigator.appName == "Microsoft Internet Explorer");
101 this.isGecko = navigator.userAgent.indexOf('Gecko') != -1;
102 this.isSafari = navigator.userAgent.indexOf('Safari') != -1;
103 this.isMac = navigator.userAgent.indexOf('Mac') != -1;
104 this.isMSIE5_0 = this.isMSIE && (navigator.userAgent.indexOf('MSIE 5.0') != -1);
105 this.action = "none";
106 this.selectedWindow = null;
107 this.lastSelectedWindow = null;
109 this.mouseDownScreenX = 0;
110 this.mouseDownScreenY = 0;
111 this.mouseDownLayerX = 0;
112 this.mouseDownLayerY = 0;
113 this.mouseDownWidth = 0;
114 this.mouseDownHeight = 0;
118 MCWindows.prototype.init = function(settings) {
119 this.settings = settings;
122 this.addEvent(document, "mousemove", mcWindows.eventDispatcher);
124 this.addEvent(window, "mousemove", mcWindows.eventDispatcher);
126 this.addEvent(document, "mouseup", mcWindows.eventDispatcher);
131 MCWindows.prototype.getParam = function(name, default_value) {
134 value = (typeof(this.settings[name]) == "undefined") ? default_value : this.settings[name];
137 if (value == "true" || value == "false")
138 return (value == "true");
143 MCWindows.prototype.eventDispatcher = function(e) {
144 e = typeof(e) == "undefined" ? window.event : e;
146 if (mcWindows.selectedWindow == null)
150 if (mcWindows.isGecko && e.type == "mousedown") {
151 var elm = e.currentTarget;
153 for (var n in mcWindows.windows) {
154 var win = mcWindows.windows[n];
156 if (win.headElement == elm || win.resizeElement == elm) {
165 mcWindows.selectedWindow.onMouseMove(e);
169 mcWindows.selectedWindow.onMouseUp(e);
173 mcWindows.selectedWindow.onMouseDown(e);
177 mcWindows.selectedWindow.onFocus(e);
182 MCWindows.prototype.addEvent = function(obj, name, handler) {
184 obj.attachEvent("on" + name, handler);
186 obj.addEventListener(name, handler, true);
189 MCWindows.prototype.cancelEvent = function(e) {
191 e.returnValue = false;
192 e.cancelBubble = true;
197 MCWindows.prototype.parseFeatures = function(opts) {
198 // Cleanup the options
199 opts = opts.toLowerCase();
200 opts = opts.replace(/;/g, ",");
201 opts = opts.replace(/[^0-9a-z=,]/g, "");
203 var optionChunks = opts.split(',');
204 var options = new Array();
206 options['left'] = "10";
207 options['top'] = "10";
208 options['width'] = "300";
209 options['height'] = "300";
210 options['resizable'] = "yes";
211 options['minimizable'] = "yes";
212 options['maximizable'] = "yes";
213 options['close'] = "yes";
214 options['movable'] = "yes";
215 options['statusbar'] = "yes";
216 options['scrollbars'] = "auto";
217 options['modal'] = "no";
222 for (var i=0; i<optionChunks.length; i++) {
223 var parts = optionChunks[i].split('=');
225 if (parts.length == 2)
226 options[parts[0]] = parts[1];
229 options['left'] = parseInt(options['left']);
230 options['top'] = parseInt(options['top']);
231 options['width'] = parseInt(options['width']);
232 options['height'] = parseInt(options['height']);
237 MCWindows.prototype.open = function(url, name, features) {
238 this.lastSelectedWindow = this.selectedWindow;
240 var win = new MCWindow();
241 var winDiv, html = "", id;
242 var imgPath = this.getParam("images_path");
244 features = this.parseFeatures(features);
247 id = "mcWindow_" + name;
248 win.deltaHeight = 18;
250 if (features['statusbar'] == "yes") {
251 win.deltaHeight += 13;
254 win.deltaHeight += 1;
257 width = parseInt(features['width']);
258 height = parseInt(features['height'])-win.deltaHeight;
263 // Setup first part of window
267 win.features = features;
268 this.windows[name] = win;
271 iframeHeight = height;
273 // Create inner content
274 html += '<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">';
277 html += '<title>Wrapper iframe</title>';
278 html += '<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">';
279 html += '<link href="' + this.getParam("css_file") + '" rel="stylesheet" type="text/css" />';
281 html += '<body onload="parent.mcWindows.onLoad(\'' + name + '\');">';
283 html += '<div id="' + id + '_container" class="mceWindow">';
284 html += '<div id="' + id + '_head" class="mceWindowHead" onmousedown="parent.mcWindows.windows[\'' + name + '\'].focus();">';
285 html += ' <div id="' + id + '_title" class="mceWindowTitle"';
286 html += ' onselectstart="return false;" unselectable="on" style="-moz-user-select: none !important;"></div>';
287 html += ' <div class="mceWindowHeadTools">';
288 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>';
289 // html += ' <a href="javascript:mcWindows.windows[\'' + name + '\'].maximize();" target="_self" onmousedown="return false;" class="mceWindowMaximize"></a>';
290 // html += ' <a href="javascript:mcWindows.windows[\'' + name + '\'].minimize();" target="_self" onmousedown="return false;" class="mceWindowMinimize"></a>';
292 html += '</div><div id="' + id + '_body" class="mceWindowBody" style="width: ' + width + 'px; height: ' + height + 'px;">';
293 html += '<iframe id="' + id + '_iframe" name="' + id + '_iframe" frameborder="0" width="' + iframeWidth + '" height="' + iframeHeight + '" src="' + url + '" class="mceWindowBodyIframe" scrolling="' + features['scrollbars'] + '"></iframe></div>';
295 if (features['statusbar'] == "yes") {
296 html += '<div id="' + id + '_statusbar" class="mceWindowStatusbar" onmousedown="parent.mcWindows.windows[\'' + name + '\'].focus();">';
298 if (features['resizable'] == "yes") {
300 html += '<div id="' + id + '_resize" class="mceWindowResize"><div style="background-image: url(\'' + imgPath + '/window_resize.gif\'); width: 12px; height: 12px;"></div></div>';
302 html += '<div id="' + id + '_resize" class="mceWindowResize"><img onmousedown="parent.mcWindows.windows[\'' + name + '\'].focus();" border="0" src="' + imgPath + '/window_resize.gif" /></div>';
314 this.createFloatingIFrame(id, features['left'], features['top'], features['width'], features['height'], html);
317 // Blocks the document events by placing a image over the whole document
318 MCWindows.prototype.setDocumentLock = function(state) {
320 var elm = document.getElementById('mcWindowEventBlocker');
322 elm = document.createElement("div");
324 elm.id = "mcWindowEventBlocker";
325 elm.style.position = "absolute";
326 elm.style.left = "0px";
327 elm.style.top = "0px";
329 document.body.appendChild(elm);
332 elm.style.display = "none";
334 var imgPath = this.getParam("images_path");
335 var width = document.body.clientWidth;
336 var height = document.body.clientHeight;
338 elm.style.width = width;
339 elm.style.height = height;
340 elm.innerHTML = '<img src="' + imgPath + '/spacer.gif" width="' + width + '" height="' + height + '" />';
342 elm.style.zIndex = mcWindows.zindex-1;
343 elm.style.display = "block";
345 var elm = document.getElementById('mcWindowEventBlocker');
347 if (mcWindows.windows.length == 0)
348 elm.parentNode.removeChild(elm);
350 elm.style.zIndex = mcWindows.zindex-1;
354 // Gets called when wrapper iframe is initialized
355 MCWindows.prototype.onLoad = function(name) {
356 var win = mcWindows.windows[name];
357 var id = "mcWindow_" + name;
358 var wrapperIframe = window.frames[id + "_iframe"].frames[0];
359 var wrapperDoc = window.frames[id + "_iframe"].document;
360 var doc = window.frames[id + "_iframe"].document;
361 var winDiv = document.getElementById("mcWindow_" + name + "_div");
362 var realIframe = window.frames[id + "_iframe"].frames[0];
365 win.id = "mcWindow_" + name;
366 win.winElement = winDiv;
367 win.bodyElement = doc.getElementById(id + '_body');
368 win.iframeElement = doc.getElementById(id + '_iframe');
369 win.headElement = doc.getElementById(id + '_head');
370 win.titleElement = doc.getElementById(id + '_title');
371 win.resizeElement = doc.getElementById(id + '_resize');
372 win.containerElement = doc.getElementById(id + '_container');
373 win.left = win.features['left'];
374 win.top = win.features['top'];
375 win.frame = window.frames[id + '_iframe'].frames[0];
376 win.wrapperFrame = window.frames[id + '_iframe'];
377 win.wrapperIFrameElement = document.getElementById(id + "_iframe");
379 // Add event handlers
380 mcWindows.addEvent(win.headElement, "mousedown", mcWindows.eventDispatcher);
382 if (win.resizeElement != null)
383 mcWindows.addEvent(win.resizeElement, "mousedown", mcWindows.eventDispatcher);
385 if (mcWindows.isMSIE) {
386 mcWindows.addEvent(realIframe.document, "mousemove", mcWindows.eventDispatcher);
387 mcWindows.addEvent(realIframe.document, "mouseup", mcWindows.eventDispatcher);
389 mcWindows.addEvent(realIframe, "mousemove", mcWindows.eventDispatcher);
390 mcWindows.addEvent(realIframe, "mouseup", mcWindows.eventDispatcher);
391 mcWindows.addEvent(realIframe, "focus", mcWindows.eventDispatcher);
394 for (var i=0; i<window.frames.length; i++) {
395 if (!window.frames[i]._hasMouseHandlers) {
396 if (mcWindows.isMSIE) {
397 mcWindows.addEvent(window.frames[i].document, "mousemove", mcWindows.eventDispatcher);
398 mcWindows.addEvent(window.frames[i].document, "mouseup", mcWindows.eventDispatcher);
400 mcWindows.addEvent(window.frames[i], "mousemove", mcWindows.eventDispatcher);
401 mcWindows.addEvent(window.frames[i], "mouseup", mcWindows.eventDispatcher);
404 window.frames[i]._hasMouseHandlers = true;
408 if (mcWindows.isMSIE) {
409 mcWindows.addEvent(win.frame.document, "mousemove", mcWindows.eventDispatcher);
410 mcWindows.addEvent(win.frame.document, "mouseup", mcWindows.eventDispatcher);
412 mcWindows.addEvent(win.frame, "mousemove", mcWindows.eventDispatcher);
413 mcWindows.addEvent(win.frame, "mouseup", mcWindows.eventDispatcher);
414 mcWindows.addEvent(win.frame, "focus", mcWindows.eventDispatcher);
417 // Dispatch open window event
418 var func = this.getParam("on_open_window", "");
420 eval(func + "(win);");
424 if (win.features['modal'] == "yes")
425 mcWindows.setDocumentLock(true);
428 MCWindows.prototype.createFloatingIFrame = function(id_prefix, left, top, width, height, html) {
429 var iframe = document.createElement("iframe");
430 var div = document.createElement("div");
432 width = parseInt(width);
433 height = parseInt(height)+1;
435 // Create wrapper div
436 div.setAttribute("id", id_prefix + "_div");
437 div.setAttribute("width", width);
438 div.setAttribute("height", (height));
439 div.style.position = "absolute";
440 div.style.left = left + "px";
441 div.style.top = top + "px";
442 div.style.width = width + "px";
443 div.style.height = (height) + "px";
444 div.style.backgroundColor = "white";
445 div.style.display = "none";
448 iframeWidth = width + 2;
449 iframeHeight = height + 2;
452 iframeHeight = height + 1;
456 iframe.setAttribute("id", id_prefix + "_iframe");
457 iframe.setAttribute("name", id_prefix + "_iframe");
458 iframe.setAttribute("border", "0");
459 iframe.setAttribute("frameBorder", "0");
460 iframe.setAttribute("marginWidth", "0");
461 iframe.setAttribute("marginHeight", "0");
462 iframe.setAttribute("leftMargin", "0");
463 iframe.setAttribute("topMargin", "0");
464 iframe.setAttribute("width", iframeWidth);
465 iframe.setAttribute("height", iframeHeight);
466 // iframe.setAttribute("src", "../jscripts/tiny_mce/blank.htm");
467 // iframe.setAttribute("allowtransparency", "false");
468 iframe.setAttribute("scrolling", "no");
469 iframe.style.width = iframeWidth + "px";
470 iframe.style.height = iframeHeight + "px";
471 iframe.style.backgroundColor = "white";
472 div.appendChild(iframe);
474 document.body.appendChild(div);
476 // Fixed MSIE 5.0 issue
477 div.innerHTML = div.innerHTML;
480 // Give Safari some time to setup
481 window.setTimeout(function() {
482 doc = window.frames[id_prefix + '_iframe'].document;
488 doc = window.frames[id_prefix + '_iframe'].window.document;
494 div.style.display = "block";
500 function MCWindow() {
503 MCWindow.prototype.focus = function() {
504 if (this != mcWindows.selectedWindow) {
505 this.winElement.style.zIndex = ++mcWindows.zindex;
506 mcWindows.lastSelectedWindow = mcWindows.selectedWindow;
507 mcWindows.selectedWindow = this;
511 MCWindow.prototype.minimize = function() {
514 MCWindow.prototype.maximize = function() {
518 MCWindow.prototype.startResize = function() {
519 mcWindows.action = "resize";
522 MCWindow.prototype.startMove = function(e) {
523 mcWindows.action = "move";
526 MCWindow.prototype.close = function() {
527 if (mcWindows.lastSelectedWindow != null)
528 mcWindows.lastSelectedWindow.focus();
530 var mcWindowsNew = new Array();
531 for (var n in mcWindows.windows) {
532 var win = mcWindows.windows[n];
533 if (typeof(win) == 'function')
536 if (win.name != this.name)
537 mcWindowsNew[n] = win;
540 mcWindows.windows = mcWindowsNew;
542 // alert(mcWindows.doc.getElementById(this.id + "_iframe"));
544 var e = mcWindows.doc.getElementById(this.id + "_iframe");
545 e.parentNode.removeChild(e);
547 var e = mcWindows.doc.getElementById(this.id + "_div");
548 e.parentNode.removeChild(e);
550 mcWindows.setDocumentLock(false);
553 MCWindow.prototype.onMouseMove = function(e) {
554 var scrollX = 0;//this.doc.body.scrollLeft;
555 var scrollY = 0;//this.doc.body.scrollTop;
557 // Calculate real X, Y
558 var dx = e.screenX - mcWindows.mouseDownScreenX;
559 var dy = e.screenY - mcWindows.mouseDownScreenY;
561 switch (mcWindows.action) {
563 width = mcWindows.mouseDownWidth + (e.screenX - mcWindows.mouseDownScreenX);
564 height = mcWindows.mouseDownHeight + (e.screenY - mcWindows.mouseDownScreenY);
566 width = width < 100 ? 100 : width;
567 height = height < 100 ? 100 : height;
569 this.wrapperIFrameElement.style.width = width+2;
570 this.wrapperIFrameElement.style.height = height+2;
571 this.wrapperIFrameElement.width = width+2;
572 this.wrapperIFrameElement.height = height+2;
573 this.winElement.style.width = width;
574 this.winElement.style.height = height;
576 height = height - this.deltaHeight;
578 this.containerElement.style.width = width;
580 this.iframeElement.style.width = width;
581 this.iframeElement.style.height = height;
582 this.bodyElement.style.width = width;
583 this.bodyElement.style.height = height;
584 this.headElement.style.width = width;
585 //this.statusElement.style.width = width;
587 mcWindows.cancelEvent(e);
591 this.left = mcWindows.mouseDownLayerX + (e.screenX - mcWindows.mouseDownScreenX);
592 this.top = mcWindows.mouseDownLayerY + (e.screenY - mcWindows.mouseDownScreenY);
593 this.winElement.style.left = this.left + "px";
594 this.winElement.style.top = this.top + "px";
596 mcWindows.cancelEvent(e);
601 function debug(msg) {
602 document.getElementById('debug').value += msg + "\n";
605 MCWindow.prototype.onMouseUp = function(e) {
606 mcWindows.action = "none";
609 MCWindow.prototype.onFocus = function(e) {
610 // Gecko only handler
611 var winRef = e.currentTarget;
613 for (var n in mcWindows.windows) {
614 var win = mcWindows.windows[n];
615 if (typeof(win) == 'function')
618 if (winRef.name == win.id + "_iframe") {
625 MCWindow.prototype.onMouseDown = function(e) {
626 var elm = mcWindows.isMSIE ? this.wrapperFrame.event.srcElement : e.target;
628 var scrollX = 0;//this.doc.body.scrollLeft;
629 var scrollY = 0;//this.doc.body.scrollTop;
631 mcWindows.mouseDownScreenX = e.screenX;
632 mcWindows.mouseDownScreenY = e.screenY;
633 mcWindows.mouseDownLayerX = this.left;
634 mcWindows.mouseDownLayerY = this.top;
635 mcWindows.mouseDownWidth = parseInt(this.winElement.style.width);
636 mcWindows.mouseDownHeight = parseInt(this.winElement.style.height);
638 if (this.resizeElement != null && elm == this.resizeElement.firstChild)
643 mcWindows.cancelEvent(e);
647 var mcWindows = new MCWindows();
649 // Initialize windows
651 images_path : tinyMCE.baseURL + "/plugins/inlinepopups/images",
652 css_file : tinyMCE.baseURL + "/plugins/inlinepopups/css/inlinepopup.css"