/** * $Id: editor_plugin_src.js 268 2007-04-28 15:52:59Z spocke $ * * Moxiecode DHTML Windows script. * * @author Moxiecode * @copyright Copyright © 2004-2007, Moxiecode Systems AB, All rights reserved. */ // Patch openWindow, closeWindow TinyMCE functions var TinyMCE_InlinePopupsPlugin = { getInfo : function() { return { longname : 'Inline Popups', author : 'Moxiecode Systems AB', authorurl : 'http://tinymce.moxiecode.com', infourl : 'http://wiki.moxiecode.com/index.php/TinyMCE:Plugins/inlinepopups', version : tinyMCE.majorVersion + "." + tinyMCE.minorVersion }; } }; tinyMCE.addPlugin("inlinepopups", TinyMCE_InlinePopupsPlugin); // Patch openWindow, closeWindow TinyMCE functions TinyMCE_Engine.prototype.orgOpenWindow = TinyMCE_Engine.prototype.openWindow; TinyMCE_Engine.prototype.orgCloseWindow = TinyMCE_Engine.prototype.closeWindow; TinyMCE_Engine.prototype.openWindow = function(template, args) { // Does the caller support inline if (args['inline'] != "yes" || tinyMCE.isOpera || tinyMCE.getParam("plugins").indexOf('inlinepopups') == -1) { mcWindows.selectedWindow = null; args['mce_inside_iframe'] = false; this.orgOpenWindow(template, args); return; } var url, resizable, scrollbars; args['mce_inside_iframe'] = true; tinyMCE.windowArgs = args; if (template['file'].charAt(0) != '/' && template['file'].indexOf('://') == -1) url = tinyMCE.baseURL + "/themes/" + tinyMCE.getParam("theme") + "/" + template['file']; else url = template['file']; if (!(width = parseInt(template['width']))) width = 320; if (!(height = parseInt(template['height']))) height = 200; if (!(minWidth = parseInt(template['minWidth']))) minWidth = 100; if (!(minHeight = parseInt(template['minHeight']))) minHeight = 100; resizable = (args && args['resizable']) ? args['resizable'] : "no"; scrollbars = (args && args['scrollbars']) ? args['scrollbars'] : "no"; height += 18; // Replace all args as variables in URL for (var name in args) { if (typeof(args[name]) == 'function') continue; url = tinyMCE.replaceVar(url, name, escape(args[name])); } var elm = document.getElementById(this.selectedInstance.editorId + '_parent'); if (tinyMCE.hasPlugin('fullscreen') && this.selectedInstance.getData('fullscreen').enabled) pos = { absLeft: 0, absTop: 0 }; else pos = tinyMCE.getAbsPosition(elm); // Center div in editor area pos.absLeft += Math.round((elm.firstChild.clientWidth / 2) - (width / 2)); pos.absTop += Math.round((elm.firstChild.clientHeight / 2) - (height / 2)); // WordPress cache buster url += tinyMCE.settings['imp_version'] ? (url.indexOf('?')==-1?'?':'&') + 'ver=' + tinyMCE.settings['imp_version'] : ''; 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 ); }; TinyMCE_Engine.prototype.closeWindow = function(win) { var gotit = false, n, w; for (n in mcWindows.windows) { w = mcWindows.windows[n]; if (typeof(w) == 'function') continue; if (win.name == w.id + '_iframe') { w.close(); gotit = true; } } if (!gotit) this.orgCloseWindow(win); tinyMCE.selectedInstance.getWin().focus(); }; TinyMCE_Engine.prototype.setWindowTitle = function(win_ref, title) { for (var n in mcWindows.windows) { var win = mcWindows.windows[n]; if (typeof(win) == 'function') continue; if (win_ref.name == win.id + "_iframe") window.frames[win.id + "_iframe"].document.getElementById(win.id + '_title').innerHTML = title; } }; // * * * * * TinyMCE_Windows classes below // Windows handler function TinyMCE_Windows() { this.settings = new Array(); this.windows = new Array(); this.isMSIE = (navigator.appName == "Microsoft Internet Explorer"); this.isGecko = navigator.userAgent.indexOf('Gecko') != -1; this.isSafari = navigator.userAgent.indexOf('Safari') != -1; this.isMac = navigator.userAgent.indexOf('Mac') != -1; this.isMSIE5_0 = this.isMSIE && (navigator.userAgent.indexOf('MSIE 5.0') != -1); this.action = "none"; this.selectedWindow = null; this.lastSelectedWindow = null; this.zindex = 1001; this.mouseDownScreenX = 0; this.mouseDownScreenY = 0; this.mouseDownLayerX = 0; this.mouseDownLayerY = 0; this.mouseDownWidth = 0; this.mouseDownHeight = 0; this.idCounter = 0; }; TinyMCE_Windows.prototype.init = function(settings) { this.settings = settings; if (this.isMSIE) this.addEvent(document, "mousemove", mcWindows.eventDispatcher); else this.addEvent(window, "mousemove", mcWindows.eventDispatcher); this.addEvent(document, "mouseup", mcWindows.eventDispatcher); this.addEvent(window, "resize", mcWindows.eventDispatcher); this.addEvent(document, "scroll", mcWindows.eventDispatcher); this.doc = document; }; TinyMCE_Windows.prototype.getBounds = function() { if (!this.bounds) { var vp = tinyMCE.getViewPort(window); var top, left, bottom, right, docEl = this.doc.documentElement; top = vp.top; left = vp.left; bottom = vp.height + top - 2; right = vp.width + left - 22; // TODO this number is platform dependant // x1, y1, x2, y2 this.bounds = [left, top, right, bottom]; } return this.bounds; }; TinyMCE_Windows.prototype.clampBoxPosition = function(x, y, w, h, minW, minH) { var bounds = this.getBounds(); x = Math.max(bounds[0], Math.min(bounds[2], x + w) - w); y = Math.max(bounds[1], Math.min(bounds[3], y + h) - h); return this.clampBoxSize(x, y, w, h, minW, minH); }; TinyMCE_Windows.prototype.clampBoxSize = function(x, y, w, h, minW, minH) { var bounds = this.getBounds(); return [ x, y, Math.max(minW, Math.min(bounds[2], x + w) - x), Math.max(minH, Math.min(bounds[3], y + h) - y) ]; }; TinyMCE_Windows.prototype.getParam = function(name, default_value) { var value = null; value = (typeof(this.settings[name]) == "undefined") ? default_value : this.settings[name]; // Fix bool values if (value == "true" || value == "false") return (value == "true"); return value; }; TinyMCE_Windows.prototype.eventDispatcher = function(e) { e = typeof(e) == "undefined" ? window.event : e; if (mcWindows.selectedWindow == null) return; // Switch focus if (mcWindows.isGecko && e.type == "mousedown") { var elm = e.currentTarget; for (var n in mcWindows.windows) { var win = mcWindows.windows[n]; if (win.headElement == elm || win.resizeElement == elm) { win.focus(); break; } } } switch (e.type) { case "mousemove": mcWindows.selectedWindow.onMouseMove(e); break; case "mouseup": mcWindows.selectedWindow.onMouseUp(e); break; case "mousedown": mcWindows.selectedWindow.onMouseDown(e); break; case "focus": mcWindows.selectedWindow.onFocus(e); break; case "scroll": case "resize": if (mcWindows.clampUpdateTimeout) clearTimeout(mcWindows.clampUpdateTimeout); mcWindows.clampEventType = e.type; mcWindows.clampUpdateTimeout = setTimeout(function () {mcWindows.updateClamping()}, 100); break; } }; TinyMCE_Windows.prototype.updateClamping = function () { var clamp, oversize, etype = mcWindows.clampEventType; this.bounds = null; // Recalc window bounds on resize/scroll this.clampUpdateTimeout = null; for (var n in this.windows) { win = this.windows[n]; if (typeof(win) == 'function' || ! win.winElement) continue; clamp = mcWindows.clampBoxPosition( win.left, win.top, win.winElement.scrollWidth, win.winElement.scrollHeight, win.features.minWidth, win.features.minHeight ); oversize = ( clamp[2] != win.winElement.scrollWidth || clamp[3] != win.winElement.scrollHeight ) ? true : false; if (!oversize || win.features.resizable == "yes" || etype != "scroll") win.moveTo(clamp[0], clamp[1]); if (oversize && win.features.resizable == "yes") win.resizeTo(clamp[2], clamp[3]); } }; TinyMCE_Windows.prototype.addEvent = function(obj, name, handler) { if (this.isMSIE) obj.attachEvent("on" + name, handler); else obj.addEventListener(name, handler, false); }; TinyMCE_Windows.prototype.cancelEvent = function(e) { if (this.isMSIE) { e.returnValue = false; e.cancelBubble = true; } else e.preventDefault(); }; TinyMCE_Windows.prototype.parseFeatures = function(opts) { // Cleanup the options opts = opts.toLowerCase(); opts = opts.replace(/;/g, ","); opts = opts.replace(/[^0-9a-z=,]/g, ""); var optionChunks = opts.split(','); var options = new Array(); options['left'] = "10"; options['top'] = "10"; options['width'] = "300"; options['height'] = "300"; options['minwidth'] = "100"; options['minheight'] = "100"; options['resizable'] = "yes"; options['minimizable'] = "yes"; options['maximizable'] = "yes"; options['close'] = "yes"; options['movable'] = "yes"; options['statusbar'] = "yes"; options['scrollbars'] = "auto"; options['modal'] = "no"; if (opts == "") return options; for (var i=0; i'; html += ''; html += ''; html += '
'; html += '
'; html += '
'; if (features['resizable'] == "yes" && features['maximizable'] == "yes") html += ' '; // html += ' '; html += '
'; html += '
'; html += '
'; if (features['statusbar'] == "yes") { html += '
'; if (features['resizable'] == "yes") { if (this.isGecko) html += '
'; else html += '
'; } html += '
'; } html += '
'; html += ''; html += ''; // Create iframe this.createFloatingIFrame(id, features['left'], features['top'], features['width'], features['height'], html); }; // Blocks the document events by placing a image over the whole document TinyMCE_Windows.prototype.setDocumentLock = function(state) { var elm = document.getElementById('mcWindowEventBlocker'); if (state) { if (elm == null) { elm = document.createElement("div"); elm.id = "mcWindowEventBlocker"; elm.style.position = "absolute"; elm.style.left = "0"; elm.style.top = "0"; document.body.appendChild(elm); } elm.style.display = "none"; var imgPath = this.getParam("images_path"); var width = document.body.clientWidth; var height = document.body.clientHeight; elm.style.width = width; elm.style.height = height; elm.innerHTML = ''; elm.style.zIndex = mcWindows.zindex-1; elm.style.display = "block"; } else if (elm != null) { if (mcWindows.windows.length == 0) elm.parentNode.removeChild(elm); else elm.style.zIndex = mcWindows.zindex-1; } }; // Gets called when wrapper iframe is initialized TinyMCE_Windows.prototype.onLoad = function(name) { var win = mcWindows.windows[name]; var id = "mcWindow_" + name; var wrapperIframe = window.frames[id + "_iframe"].frames[0]; var wrapperDoc = window.frames[id + "_iframe"].document; var doc = window.frames[id + "_iframe"].document; var winDiv = document.getElementById("mcWindow_" + name + "_div"); var realIframe = window.frames[id + "_iframe"].frames[0]; // Set window data win.id = "mcWindow_" + name; win.winElement = winDiv; win.bodyElement = doc.getElementById(id + '_body'); win.iframeElement = doc.getElementById(id + '_iframe'); win.headElement = doc.getElementById(id + '_head'); win.titleElement = doc.getElementById(id + '_title'); win.resizeElement = doc.getElementById(id + '_resize'); win.containerElement = doc.getElementById(id + '_container'); win.left = win.features['left']; win.top = win.features['top']; win.frame = window.frames[id + '_iframe'].frames[0]; win.wrapperFrame = window.frames[id + '_iframe']; win.wrapperIFrameElement = document.getElementById(id + "_iframe"); // Add event handlers mcWindows.addEvent(win.headElement, "mousedown", mcWindows.eventDispatcher); if (win.resizeElement != null) mcWindows.addEvent(win.resizeElement, "mousedown", mcWindows.eventDispatcher); if (mcWindows.isMSIE) { mcWindows.addEvent(realIframe.document, "mousemove", mcWindows.eventDispatcher); mcWindows.addEvent(realIframe.document, "mouseup", mcWindows.eventDispatcher); } else { mcWindows.addEvent(realIframe, "mousemove", mcWindows.eventDispatcher); mcWindows.addEvent(realIframe, "mouseup", mcWindows.eventDispatcher); mcWindows.addEvent(realIframe, "focus", mcWindows.eventDispatcher); } for (var i=0; i