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