2 * $RCSfile: editor_plugin_src.js,v $
\r
4 * $Date: 2006/02/06 20:02:38 $
\r
6 * Moxiecode DHTML Windows script.
\r
9 * @copyright Copyright © 2004-2006, Moxiecode Systems AB, All rights reserved.
\r
12 // Patch openWindow, closeWindow TinyMCE functions
\r
14 var TinyMCE_InlinePopupsPlugin = {
\r
15 getInfo : function() {
\r
17 longname : 'Inline Popups',
\r
18 author : 'Moxiecode Systems',
\r
19 authorurl : 'http://tinymce.moxiecode.com',
\r
20 infourl : 'http://tinymce.moxiecode.com/tinymce/docs/plugin_inlinepopups.html',
\r
21 version : tinyMCE.majorVersion + "." + tinyMCE.minorVersion
\r
26 tinyMCE.addPlugin("inlinepopups", TinyMCE_InlinePopupsPlugin);
\r
28 // Patch openWindow, closeWindow TinyMCE functions
\r
30 TinyMCE_Engine.prototype.orgOpenWindow = TinyMCE_Engine.prototype.openWindow;
\r
32 TinyMCE_Engine.prototype.openWindow = function(template, args) {
\r
33 // Does the caller support inline
\r
34 if (args['inline'] != "yes" || tinyMCE.isOpera || tinyMCE.getParam("plugins").indexOf('inlinepopups') == -1) {
\r
35 mcWindows.selectedWindow = null;
\r
36 args['mce_inside_iframe'] = false;
\r
37 this.orgOpenWindow(template, args);
\r
41 var url, resizable, scrollbars;
\r
43 args['mce_inside_iframe'] = true;
\r
44 tinyMCE.windowArgs = args;
\r
46 if (template['file'].charAt(0) != '/' && template['file'].indexOf('://') == -1)
\r
47 url = tinyMCE.baseURL + "/themes/" + tinyMCE.getParam("theme") + "/" + template['file'];
\r
49 url = template['file'];
\r
51 if (!(width = parseInt(template['width'])))
\r
54 if (!(height = parseInt(template['height'])))
\r
57 resizable = (args && args['resizable']) ? args['resizable'] : "no";
\r
58 scrollbars = (args && args['scrollbars']) ? args['scrollbars'] : "no";
\r
62 // Replace all args as variables in URL
\r
63 for (var name in args) {
\r
64 if (typeof(args[name]) == 'function')
\r
67 url = tinyMCE.replaceVar(url, name, escape(args[name]));
\r
70 var elm = document.getElementById(this.selectedInstance.editorId + '_parent');
\r
71 var pos = tinyMCE.getAbsPosition(elm);
\r
73 // Center div in editor area
\r
74 pos.absLeft += Math.round((elm.firstChild.clientWidth / 2) - (width / 2));
\r
75 pos.absTop += Math.round((elm.firstChild.clientHeight / 2) - (height / 2));
\r
77 mcWindows.open(url, mcWindows.idCounter++, "modal=yes,width=" + width+ ",height=" + height + ",resizable=" + resizable + ",scrollbars=" + scrollbars + ",statusbar=" + resizable + ",left=" + pos.absLeft + ",top=" + pos.absTop);
\r
80 TinyMCE_Engine.prototype.orgCloseWindow = TinyMCE_Engine.prototype.closeWindow;
\r
82 TinyMCE_Engine.prototype.closeWindow = function(win) {
\r
83 if (mcWindows.selectedWindow != null)
\r
84 mcWindows.selectedWindow.close();
\r
86 this.orgCloseWindow(win);
\r
89 TinyMCE_Engine.prototype.setWindowTitle = function(win_ref, title) {
\r
90 for (var n in mcWindows.windows) {
\r
91 var win = mcWindows.windows[n];
\r
92 if (typeof(win) == 'function')
\r
95 if (win_ref.name == win.id + "_iframe")
\r
96 window.frames[win.id + "_iframe"].document.getElementById(win.id + '_title').innerHTML = title;
\r
100 // * * * * * TinyMCE_Windows classes below
\r
103 function TinyMCE_Windows() {
\r
104 this.settings = new Array();
\r
105 this.windows = new Array();
\r
106 this.isMSIE = (navigator.appName == "Microsoft Internet Explorer");
\r
107 this.isGecko = navigator.userAgent.indexOf('Gecko') != -1;
\r
108 this.isSafari = navigator.userAgent.indexOf('Safari') != -1;
\r
109 this.isMac = navigator.userAgent.indexOf('Mac') != -1;
\r
110 this.isMSIE5_0 = this.isMSIE && (navigator.userAgent.indexOf('MSIE 5.0') != -1);
\r
111 this.action = "none";
\r
112 this.selectedWindow = null;
\r
113 this.lastSelectedWindow = null;
\r
115 this.mouseDownScreenX = 0;
\r
116 this.mouseDownScreenY = 0;
\r
117 this.mouseDownLayerX = 0;
\r
118 this.mouseDownLayerY = 0;
\r
119 this.mouseDownWidth = 0;
\r
120 this.mouseDownHeight = 0;
\r
121 this.idCounter = 0;
\r
124 TinyMCE_Windows.prototype.init = function(settings) {
\r
125 this.settings = settings;
\r
128 this.addEvent(document, "mousemove", mcWindows.eventDispatcher);
\r
130 this.addEvent(window, "mousemove", mcWindows.eventDispatcher);
\r
132 this.addEvent(document, "mouseup", mcWindows.eventDispatcher);
\r
134 this.doc = document;
\r
137 TinyMCE_Windows.prototype.getParam = function(name, default_value) {
\r
140 value = (typeof(this.settings[name]) == "undefined") ? default_value : this.settings[name];
\r
143 if (value == "true" || value == "false")
\r
144 return (value == "true");
\r
149 TinyMCE_Windows.prototype.eventDispatcher = function(e) {
\r
150 e = typeof(e) == "undefined" ? window.event : e;
\r
152 if (mcWindows.selectedWindow == null)
\r
156 if (mcWindows.isGecko && e.type == "mousedown") {
\r
157 var elm = e.currentTarget;
\r
159 for (var n in mcWindows.windows) {
\r
160 var win = mcWindows.windows[n];
\r
162 if (win.headElement == elm || win.resizeElement == elm) {
\r
171 mcWindows.selectedWindow.onMouseMove(e);
\r
175 mcWindows.selectedWindow.onMouseUp(e);
\r
179 mcWindows.selectedWindow.onMouseDown(e);
\r
183 mcWindows.selectedWindow.onFocus(e);
\r
188 TinyMCE_Windows.prototype.addEvent = function(obj, name, handler) {
\r
190 obj.attachEvent("on" + name, handler);
\r
192 obj.addEventListener(name, handler, true);
\r
195 TinyMCE_Windows.prototype.cancelEvent = function(e) {
\r
197 e.returnValue = false;
\r
198 e.cancelBubble = true;
\r
200 e.preventDefault();
\r
203 TinyMCE_Windows.prototype.parseFeatures = function(opts) {
\r
204 // Cleanup the options
\r
205 opts = opts.toLowerCase();
\r
206 opts = opts.replace(/;/g, ",");
\r
207 opts = opts.replace(/[^0-9a-z=,]/g, "");
\r
209 var optionChunks = opts.split(',');
\r
210 var options = new Array();
\r
212 options['left'] = "10";
\r
213 options['top'] = "10";
\r
214 options['width'] = "300";
\r
215 options['height'] = "300";
\r
216 options['resizable'] = "yes";
\r
217 options['minimizable'] = "yes";
\r
218 options['maximizable'] = "yes";
\r
219 options['close'] = "yes";
\r
220 options['movable'] = "yes";
\r
221 options['statusbar'] = "yes";
\r
222 options['scrollbars'] = "auto";
\r
223 options['modal'] = "no";
\r
228 for (var i=0; i<optionChunks.length; i++) {
\r
229 var parts = optionChunks[i].split('=');
\r
231 if (parts.length == 2)
\r
232 options[parts[0]] = parts[1];
\r
235 options['left'] = parseInt(options['left']);
\r
236 options['top'] = parseInt(options['top']);
\r
237 options['width'] = parseInt(options['width']);
\r
238 options['height'] = parseInt(options['height']);
\r
243 TinyMCE_Windows.prototype.open = function(url, name, features) {
\r
244 this.lastSelectedWindow = this.selectedWindow;
\r
246 var win = new TinyMCE_Window();
\r
247 var winDiv, html = "", id;
\r
248 var imgPath = this.getParam("images_path");
\r
250 features = this.parseFeatures(features);
\r
253 id = "mcWindow_" + name;
\r
254 win.deltaHeight = 18;
\r
256 if (features['statusbar'] == "yes") {
\r
257 win.deltaHeight += 13;
\r
260 win.deltaHeight += 1;
\r
263 width = parseInt(features['width']);
\r
264 height = parseInt(features['height'])-win.deltaHeight;
\r
269 // Setup first part of window
\r
273 win.features = features;
\r
274 this.windows[name] = win;
\r
276 iframeWidth = width;
\r
277 iframeHeight = height;
\r
279 // Create inner content
\r
280 html += '<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">';
\r
283 html += '<title>Wrapper iframe</title>';
\r
284 html += '<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">';
\r
285 html += '<link href="' + this.getParam("css_file") + '" rel="stylesheet" type="text/css" />';
\r
287 html += '<body onload="parent.mcWindows.onLoad(\'' + name + '\');">';
\r
289 html += '<div id="' + id + '_container" class="mceWindow">';
\r
290 html += '<div id="' + id + '_head" class="mceWindowHead" onmousedown="parent.mcWindows.windows[\'' + name + '\'].focus();">';
\r
291 html += ' <div id="' + id + '_title" class="mceWindowTitle"';
\r
292 html += ' onselectstart="return false;" unselectable="on" style="-moz-user-select: none !important;"></div>';
\r
293 html += ' <div class="mceWindowHeadTools">';
\r
294 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
295 // html += ' <a href="javascript:mcWindows.windows[\'' + name + '\'].maximize();" target="_self" onmousedown="return false;" class="mceWindowMaximize"></a>';
\r
296 // html += ' <a href="javascript:mcWindows.windows[\'' + name + '\'].minimize();" target="_self" onmousedown="return false;" class="mceWindowMinimize"></a>';
\r
298 html += '</div><div id="' + id + '_body" class="mceWindowBody" style="width: ' + width + 'px; height: ' + height + 'px;">';
\r
299 html += '<iframe id="' + id + '_iframe" name="' + id + '_iframe" frameborder="0" width="' + iframeWidth + '" height="' + iframeHeight + '" src="' + url + '" class="mceWindowBodyIframe" scrolling="' + features['scrollbars'] + '"></iframe></div>';
\r
301 if (features['statusbar'] == "yes") {
\r
302 html += '<div id="' + id + '_statusbar" class="mceWindowStatusbar" onmousedown="parent.mcWindows.windows[\'' + name + '\'].focus();">';
\r
304 if (features['resizable'] == "yes") {
\r
306 html += '<div id="' + id + '_resize" class="mceWindowResize"><div style="background-image: url(\'' + imgPath + '/window_resize.gif\'); width: 12px; height: 12px;"></div></div>';
\r
308 html += '<div id="' + id + '_resize" class="mceWindowResize"><img onmousedown="parent.mcWindows.windows[\'' + name + '\'].focus();" border="0" src="' + imgPath + '/window_resize.gif" /></div>';
\r
320 this.createFloatingIFrame(id, features['left'], features['top'], features['width'], features['height'], html);
\r
323 // Blocks the document events by placing a image over the whole document
\r
324 TinyMCE_Windows.prototype.setDocumentLock = function(state) {
\r
326 var elm = document.getElementById('mcWindowEventBlocker');
\r
328 elm = document.createElement("div");
\r
330 elm.id = "mcWindowEventBlocker";
\r
331 elm.style.position = "absolute";
\r
332 elm.style.left = "0";
\r
333 elm.style.top = "0";
\r
335 document.body.appendChild(elm);
\r
338 elm.style.display = "none";
\r
340 var imgPath = this.getParam("images_path");
\r
341 var width = document.body.clientWidth;
\r
342 var height = document.body.clientHeight;
\r
344 elm.style.width = width;
\r
345 elm.style.height = height;
\r
346 elm.innerHTML = '<img src="' + imgPath + '/spacer.gif" width="' + width + '" height="' + height + '" />';
\r
348 elm.style.zIndex = mcWindows.zindex-1;
\r
349 elm.style.display = "block";
\r
351 var elm = document.getElementById('mcWindowEventBlocker');
\r
353 if (mcWindows.windows.length == 0)
\r
354 elm.parentNode.removeChild(elm);
\r
356 elm.style.zIndex = mcWindows.zindex-1;
\r
360 // Gets called when wrapper iframe is initialized
\r
361 TinyMCE_Windows.prototype.onLoad = function(name) {
\r
362 var win = mcWindows.windows[name];
\r
363 var id = "mcWindow_" + name;
\r
364 var wrapperIframe = window.frames[id + "_iframe"].frames[0];
\r
365 var wrapperDoc = window.frames[id + "_iframe"].document;
\r
366 var doc = window.frames[id + "_iframe"].document;
\r
367 var winDiv = document.getElementById("mcWindow_" + name + "_div");
\r
368 var realIframe = window.frames[id + "_iframe"].frames[0];
\r
371 win.id = "mcWindow_" + name;
\r
372 win.winElement = winDiv;
\r
373 win.bodyElement = doc.getElementById(id + '_body');
\r
374 win.iframeElement = doc.getElementById(id + '_iframe');
\r
375 win.headElement = doc.getElementById(id + '_head');
\r
376 win.titleElement = doc.getElementById(id + '_title');
\r
377 win.resizeElement = doc.getElementById(id + '_resize');
\r
378 win.containerElement = doc.getElementById(id + '_container');
\r
379 win.left = win.features['left'];
\r
380 win.top = win.features['top'];
\r
381 win.frame = window.frames[id + '_iframe'].frames[0];
\r
382 win.wrapperFrame = window.frames[id + '_iframe'];
\r
383 win.wrapperIFrameElement = document.getElementById(id + "_iframe");
\r
385 // Add event handlers
\r
386 mcWindows.addEvent(win.headElement, "mousedown", mcWindows.eventDispatcher);
\r
388 if (win.resizeElement != null)
\r
389 mcWindows.addEvent(win.resizeElement, "mousedown", mcWindows.eventDispatcher);
\r
391 if (mcWindows.isMSIE) {
\r
392 mcWindows.addEvent(realIframe.document, "mousemove", mcWindows.eventDispatcher);
\r
393 mcWindows.addEvent(realIframe.document, "mouseup", mcWindows.eventDispatcher);
\r
395 mcWindows.addEvent(realIframe, "mousemove", mcWindows.eventDispatcher);
\r
396 mcWindows.addEvent(realIframe, "mouseup", mcWindows.eventDispatcher);
\r
397 mcWindows.addEvent(realIframe, "focus", mcWindows.eventDispatcher);
\r
400 for (var i=0; i<window.frames.length; i++) {
\r
401 if (!window.frames[i]._hasMouseHandlers) {
\r
402 if (mcWindows.isMSIE) {
\r
403 mcWindows.addEvent(window.frames[i].document, "mousemove", mcWindows.eventDispatcher);
\r
404 mcWindows.addEvent(window.frames[i].document, "mouseup", mcWindows.eventDispatcher);
\r
406 mcWindows.addEvent(window.frames[i], "mousemove", mcWindows.eventDispatcher);
\r
407 mcWindows.addEvent(window.frames[i], "mouseup", mcWindows.eventDispatcher);
\r
410 window.frames[i]._hasMouseHandlers = true;
\r
414 if (mcWindows.isMSIE) {
\r
415 mcWindows.addEvent(win.frame.document, "mousemove", mcWindows.eventDispatcher);
\r
416 mcWindows.addEvent(win.frame.document, "mouseup", mcWindows.eventDispatcher);
\r
418 mcWindows.addEvent(win.frame, "mousemove", mcWindows.eventDispatcher);
\r
419 mcWindows.addEvent(win.frame, "mouseup", mcWindows.eventDispatcher);
\r
420 mcWindows.addEvent(win.frame, "focus", mcWindows.eventDispatcher);
\r
423 // Dispatch open window event
\r
424 var func = this.getParam("on_open_window", "");
\r
426 eval(func + "(win);");
\r
430 if (win.features['modal'] == "yes")
\r
431 mcWindows.setDocumentLock(true);
\r
434 TinyMCE_Windows.prototype.createFloatingIFrame = function(id_prefix, left, top, width, height, html) {
\r
435 var iframe = document.createElement("iframe");
\r
436 var div = document.createElement("div");
\r
438 width = parseInt(width);
\r
439 height = parseInt(height)+1;
\r
441 // Create wrapper div
\r
442 div.setAttribute("id", id_prefix + "_div");
\r
443 div.setAttribute("width", width);
\r
444 div.setAttribute("height", (height));
\r
445 div.style.position = "absolute";
\r
446 div.style.left = left + "px";
\r
447 div.style.top = top + "px";
\r
448 div.style.width = width + "px";
\r
449 div.style.height = (height) + "px";
\r
450 div.style.backgroundColor = "white";
\r
451 div.style.display = "none";
\r
453 if (this.isGecko) {
\r
454 iframeWidth = width + 2;
\r
455 iframeHeight = height + 2;
\r
457 iframeWidth = width;
\r
458 iframeHeight = height + 1;
\r
462 iframe.setAttribute("id", id_prefix + "_iframe");
\r
463 iframe.setAttribute("name", id_prefix + "_iframe");
\r
464 iframe.setAttribute("border", "0");
\r
465 iframe.setAttribute("frameBorder", "0");
\r
466 iframe.setAttribute("marginWidth", "0");
\r
467 iframe.setAttribute("marginHeight", "0");
\r
468 iframe.setAttribute("leftMargin", "0");
\r
469 iframe.setAttribute("topMargin", "0");
\r
470 iframe.setAttribute("width", iframeWidth);
\r
471 iframe.setAttribute("height", iframeHeight);
\r
472 // iframe.setAttribute("src", "../jscripts/tiny_mce/blank.htm");
\r
473 // iframe.setAttribute("allowtransparency", "false");
\r
474 iframe.setAttribute("scrolling", "no");
\r
475 iframe.style.width = iframeWidth + "px";
\r
476 iframe.style.height = iframeHeight + "px";
\r
477 iframe.style.backgroundColor = "white";
\r
478 div.appendChild(iframe);
\r
480 document.body.appendChild(div);
\r
482 // Fixed MSIE 5.0 issue
\r
483 div.innerHTML = div.innerHTML;
\r
485 if (this.isSafari) {
\r
486 // Give Safari some time to setup
\r
487 window.setTimeout(function() {
\r
488 doc = window.frames[id_prefix + '_iframe'].document;
\r
494 doc = window.frames[id_prefix + '_iframe'].window.document;
\r
500 div.style.display = "block";
\r
506 function TinyMCE_Window() {
\r
509 TinyMCE_Window.prototype.focus = function() {
\r
510 if (this != mcWindows.selectedWindow) {
\r
511 this.winElement.style.zIndex = ++mcWindows.zindex;
\r
512 mcWindows.lastSelectedWindow = mcWindows.selectedWindow;
\r
513 mcWindows.selectedWindow = this;
\r
517 TinyMCE_Window.prototype.minimize = function() {
\r
520 TinyMCE_Window.prototype.maximize = function() {
\r
524 TinyMCE_Window.prototype.startResize = function() {
\r
525 mcWindows.action = "resize";
\r
528 TinyMCE_Window.prototype.startMove = function(e) {
\r
529 mcWindows.action = "move";
\r
532 TinyMCE_Window.prototype.close = function() {
\r
533 if (this.frame && this.frame['tinyMCEPopup'])
\r
534 this.frame['tinyMCEPopup'].restoreSelection();
\r
536 if (mcWindows.lastSelectedWindow != null)
\r
537 mcWindows.lastSelectedWindow.focus();
\r
539 var mcWindowsNew = new Array();
\r
540 for (var n in mcWindows.windows) {
\r
541 var win = mcWindows.windows[n];
\r
542 if (typeof(win) == 'function')
\r
545 if (win.name != this.name)
\r
546 mcWindowsNew[n] = win;
\r
549 mcWindows.windows = mcWindowsNew;
\r
551 // alert(mcWindows.doc.getElementById(this.id + "_iframe"));
\r
553 var e = mcWindows.doc.getElementById(this.id + "_iframe");
\r
554 e.parentNode.removeChild(e);
\r
556 var e = mcWindows.doc.getElementById(this.id + "_div");
\r
557 e.parentNode.removeChild(e);
\r
559 mcWindows.setDocumentLock(false);
\r
562 TinyMCE_Window.prototype.onMouseMove = function(e) {
\r
563 var scrollX = 0;//this.doc.body.scrollLeft;
\r
564 var scrollY = 0;//this.doc.body.scrollTop;
\r
566 // Calculate real X, Y
\r
567 var dx = e.screenX - mcWindows.mouseDownScreenX;
\r
568 var dy = e.screenY - mcWindows.mouseDownScreenY;
\r
570 switch (mcWindows.action) {
\r
572 width = mcWindows.mouseDownWidth + (e.screenX - mcWindows.mouseDownScreenX);
\r
573 height = mcWindows.mouseDownHeight + (e.screenY - mcWindows.mouseDownScreenY);
\r
575 width = width < 100 ? 100 : width;
\r
576 height = height < 100 ? 100 : height;
\r
578 this.wrapperIFrameElement.style.width = width+2;
\r
579 this.wrapperIFrameElement.style.height = height+2;
\r
580 this.wrapperIFrameElement.width = width+2;
\r
581 this.wrapperIFrameElement.height = height+2;
\r
582 this.winElement.style.width = width;
\r
583 this.winElement.style.height = height;
\r
585 height = height - this.deltaHeight;
\r
587 this.containerElement.style.width = width;
\r
589 this.iframeElement.style.width = width;
\r
590 this.iframeElement.style.height = height;
\r
591 this.bodyElement.style.width = width;
\r
592 this.bodyElement.style.height = height;
\r
593 this.headElement.style.width = width;
\r
594 //this.statusElement.style.width = width;
\r
596 mcWindows.cancelEvent(e);
\r
600 this.left = mcWindows.mouseDownLayerX + (e.screenX - mcWindows.mouseDownScreenX);
\r
601 this.top = mcWindows.mouseDownLayerY + (e.screenY - mcWindows.mouseDownScreenY);
\r
602 this.winElement.style.left = this.left + "px";
\r
603 this.winElement.style.top = this.top + "px";
\r
605 mcWindows.cancelEvent(e);
\r
610 function debug(msg) {
\r
611 document.getElementById('debug').value += msg + "\n";
\r
614 TinyMCE_Window.prototype.onMouseUp = function(e) {
\r
615 mcWindows.action = "none";
\r
618 TinyMCE_Window.prototype.onFocus = function(e) {
\r
619 // Gecko only handler
\r
620 var winRef = e.currentTarget;
\r
622 for (var n in mcWindows.windows) {
\r
623 var win = mcWindows.windows[n];
\r
624 if (typeof(win) == 'function')
\r
627 if (winRef.name == win.id + "_iframe") {
\r
634 TinyMCE_Window.prototype.onMouseDown = function(e) {
\r
635 var elm = mcWindows.isMSIE ? this.wrapperFrame.event.srcElement : e.target;
\r
637 var scrollX = 0;//this.doc.body.scrollLeft;
\r
638 var scrollY = 0;//this.doc.body.scrollTop;
\r
640 mcWindows.mouseDownScreenX = e.screenX;
\r
641 mcWindows.mouseDownScreenY = e.screenY;
\r
642 mcWindows.mouseDownLayerX = this.left;
\r
643 mcWindows.mouseDownLayerY = this.top;
\r
644 mcWindows.mouseDownWidth = parseInt(this.winElement.style.width);
\r
645 mcWindows.mouseDownHeight = parseInt(this.winElement.style.height);
\r
647 if (this.resizeElement != null && elm == this.resizeElement.firstChild)
\r
648 this.startResize(e);
\r
652 mcWindows.cancelEvent(e);
\r
656 var mcWindows = new TinyMCE_Windows();
\r
658 // Initialize windows
\r
660 images_path : tinyMCE.baseURL + "/plugins/inlinepopups/images",
\r
661 css_file : tinyMCE.baseURL + "/plugins/inlinepopups/css/inlinepopup.css"
\r