X-Git-Url: https://code.citadel.org/?a=blobdiff_plain;f=webcit%2Ftiny_mce%2Fplugins%2Finlinepopups%2Feditor_plugin_src.js;h=67123ca3142ec46384858fda1a641ed6d2401700;hb=eb5fb3f6c3b3e1d4d3d7ebbb92b8c60d70d13254;hp=7ce2e3c343901ad523d2a7138e910daea3398294;hpb=3cedf3f420a1c9316773aa7423689a4f501a3bf8;p=citadel.git diff --git a/webcit/tiny_mce/plugins/inlinepopups/editor_plugin_src.js b/webcit/tiny_mce/plugins/inlinepopups/editor_plugin_src.js index 7ce2e3c34..67123ca31 100644 --- a/webcit/tiny_mce/plugins/inlinepopups/editor_plugin_src.js +++ b/webcit/tiny_mce/plugins/inlinepopups/editor_plugin_src.js @@ -1,653 +1,699 @@ /** - * $RCSfile: editor_plugin_src.js,v $ - * $Revision: 1.4 $ - * $Date: 2005/11/27 18:06:45 $ + * editor_plugin_src.js * - * Moxiecode DHTML Windows script. + * Copyright 2009, Moxiecode Systems AB + * Released under LGPL License. * - * @author Moxiecode - * @copyright Copyright © 2004, Moxiecode Systems AB, All rights reserved. + * License: http://tinymce.moxiecode.com/license + * Contributing: http://tinymce.moxiecode.com/contributing */ -// Patch openWindow, closeWindow TinyMCE functions - -function TinyMCE_inlinepopups_getInfo() { - return { - longname : 'Inline Popups', - author : 'Moxiecode Systems', - authorurl : 'http://tinymce.moxiecode.com', - infourl : 'http://tinymce.moxiecode.com/tinymce/docs/plugin_inlinepopups.html', - version : tinyMCE.majorVersion + "." + tinyMCE.minorVersion - }; -}; - -TinyMCE.prototype.orgOpenWindow = TinyMCE.prototype.openWindow; - -TinyMCE.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; - - 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'); - var 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)); - - mcWindows.open(url, mcWindows.idCounter++, "modal=yes,width=" + width+ ",height=" + height + ",resizable=" + resizable + ",scrollbars=" + scrollbars + ",statusbar=" + resizable + ",left=" + pos.absLeft + ",top=" + pos.absTop); -}; - -TinyMCE.prototype.orgCloseWindow = TinyMCE.prototype.closeWindow; - -TinyMCE.prototype.closeWindow = function(win) { - if (mcWindows.selectedWindow != null) - mcWindows.selectedWindow.close(); - else - this.orgCloseWindow(win); -}; - -TinyMCE.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; - } -}; - -// * * * * * MCWindows classes below - -// Windows handler -function MCWindows() { - 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 = 100; - this.mouseDownScreenX = 0; - this.mouseDownScreenY = 0; - this.mouseDownLayerX = 0; - this.mouseDownLayerY = 0; - this.mouseDownWidth = 0; - this.mouseDownHeight = 0; - this.idCounter = 0; -}; - -MCWindows.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.doc = document; -}; - -MCWindows.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; -}; - -MCWindows.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; - } +(function() { + var DOM = tinymce.DOM, Element = tinymce.dom.Element, Event = tinymce.dom.Event, each = tinymce.each, is = tinymce.is; + + tinymce.create('tinymce.plugins.InlinePopups', { + init : function(ed, url) { + // Replace window manager + ed.onBeforeRenderUI.add(function() { + ed.windowManager = new tinymce.InlineWindowManager(ed); + DOM.loadCSS(url + '/skins/' + (ed.settings.inlinepopups_skin || 'clearlooks2') + "/window.css"); + }); + }, + + getInfo : function() { + return { + longname : 'InlinePopups', + author : 'Moxiecode Systems AB', + authorurl : 'http://tinymce.moxiecode.com', + infourl : 'http://wiki.moxiecode.com/index.php/TinyMCE:Plugins/inlinepopups', + version : tinymce.majorVersion + "." + tinymce.minorVersion + }; } - } - - 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; - } -}; - -MCWindows.prototype.addEvent = function(obj, name, handler) { - if (this.isMSIE) - obj.attachEvent("on" + name, handler); - else - obj.addEventListener(name, handler, true); -}; - -MCWindows.prototype.cancelEvent = function(e) { - if (this.isMSIE) { - e.returnValue = false; - e.cancelBubble = true; - } else - e.preventDefault(); -}; - -MCWindows.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['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 += '
'; -// html += ' '; -// html += ' '; - html += '
'; - html += '
'; - html += '
'; - - if (features['statusbar'] == "yes") { - html += '
'; - - if (features['resizable'] == "yes") { - if (this.isGecko) - html += '
'; - else - html += '
'; - } - - html += '
'; - } + }); - html += '
'; + tinymce.create('tinymce.InlineWindowManager:tinymce.WindowManager', { + InlineWindowManager : function(ed) { + var t = this; - html += ''; - html += ''; + t.parent(ed); + t.zIndex = 300000; + t.count = 0; + t.windows = {}; + }, - // Create iframe - this.createFloatingIFrame(id, features['left'], features['top'], features['width'], features['height'], html); -}; + open : function(f, p) { + var t = this, id, opt = '', ed = t.editor, dw = 0, dh = 0, vp, po, mdf, clf, we, w, u, parentWindow; -// Blocks the document events by placing a image over the whole document -MCWindows.prototype.setDocumentLock = function(state) { - if (state) { - var elm = document.getElementById('mcWindowEventBlocker'); - if (elm == null) { - elm = document.createElement("div"); + f = f || {}; + p = p || {}; - elm.id = "mcWindowEventBlocker"; - elm.style.position = "absolute"; - elm.style.left = "0px"; - elm.style.top = "0px"; + // Run native windows + if (!f.inline) + return t.parent(f, p); - 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 { - var elm = document.getElementById('mcWindowEventBlocker'); - - if (mcWindows.windows.length == 0) - elm.parentNode.removeChild(elm); - else - elm.style.zIndex = mcWindows.zindex-1; - } -}; - -// Gets called when wrapper iframe is initialized -MCWindows.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')); + + Event.add(id, 'keyup', function(evt) { + var VK_ESCAPE = 27; + if (evt.keyCode === VK_ESCAPE) { + f.button_func(false); + return Event.cancel(evt); + } + }); + + Event.add(id, 'keydown', function(evt) { + var cancelButton, VK_TAB = 9; + if (evt.keyCode === VK_TAB) { + cancelButton = DOM.select('a.mceCancel', id + '_wrapper')[0]; + if (cancelButton && cancelButton !== evt.target) { + cancelButton.focus(); + } else { + DOM.get(id + '_ok').focus(); + } + return Event.cancel(evt); + } + }); + } - mcWindows.windows = mcWindowsNew; + // Register events + mdf = Event.add(id, 'mousedown', function(e) { + var n = e.target, w, vp; + + w = t.windows[id]; + t.focus(id); + + if (n.nodeName == 'A' || n.nodeName == 'a') { + if (n.className == 'mceClose') { + t.close(null, id); + return Event.cancel(e); + } else if (n.className == 'mceMax') { + w.oldPos = w.element.getXY(); + w.oldSize = w.element.getSize(); + + vp = DOM.getViewPort(); + + // Reduce viewport size to avoid scrollbars + vp.w -= 2; + vp.h -= 2; + + w.element.moveTo(vp.x, vp.y); + w.element.resizeTo(vp.w, vp.h); + DOM.setStyles(id + '_ifr', {width : vp.w - w.deltaWidth, height : vp.h - w.deltaHeight}); + DOM.addClass(id + '_wrapper', 'mceMaximized'); + } else if (n.className == 'mceMed') { + // Reset to old size + w.element.moveTo(w.oldPos.x, w.oldPos.y); + w.element.resizeTo(w.oldSize.w, w.oldSize.h); + w.iframeElement.resizeTo(w.oldSize.w - w.deltaWidth, w.oldSize.h - w.deltaHeight); + + DOM.removeClass(id + '_wrapper', 'mceMaximized'); + } else if (n.className == 'mceMove') + return t._startDrag(id, e, n.className); + else if (DOM.hasClass(n, 'mceResize')) + return t._startDrag(id, e, n.className.substring(13)); + } + }); + + clf = Event.add(id, 'click', function(e) { + var n = e.target; + + t.focus(id); + + if (n.nodeName == 'A' || n.nodeName == 'a') { + switch (n.className) { + case 'mceClose': + t.close(null, id); + return Event.cancel(e); + + case 'mceButton mceOk': + case 'mceButton mceCancel': + f.button_func(n.className == 'mceButton mceOk'); + return Event.cancel(e); + } + } + }); + + // Make sure the tab order loops within the dialog. + Event.add([id + '_left', id + '_right'], 'focus', function(evt) { + var iframe = DOM.get(id + '_ifr'); + if (iframe) { + var body = iframe.contentWindow.document.body; + var focusable = DOM.select(':input:enabled,*[tabindex=0]', body); + if (evt.target.id === (id + '_left')) { + focusable[focusable.length - 1].focus(); + } else { + focusable[0].focus(); + } + } else { + DOM.get(id + '_ok').focus(); + } + }); + + // Add window + w = t.windows[id] = { + id : id, + mousedown_func : mdf, + click_func : clf, + element : new Element(id, {blocker : 1, container : ed.getContainer()}), + iframeElement : new Element(id + '_ifr'), + features : f, + deltaWidth : dw, + deltaHeight : dh + }; + + w.iframeElement.on('focus', function() { + t.focus(id); + }); + + // Setup blocker + if (t.count == 0 && t.editor.getParam('dialog_type', 'modal') == 'modal') { + DOM.add(DOM.doc.body, 'div', { + id : 'mceModalBlocker', + 'class' : (t.editor.settings.inlinepopups_skin || 'clearlooks2') + '_modalBlocker', + style : {zIndex : t.zIndex - 1} + }); + + DOM.show('mceModalBlocker'); // Reduces flicker in IE + DOM.setAttrib(DOM.doc.body, 'aria-hidden', 'true'); + } else + DOM.setStyle('mceModalBlocker', 'z-index', t.zIndex - 1); + + if (tinymce.isIE6 || /Firefox\/2\./.test(navigator.userAgent) || (tinymce.isIE && !DOM.boxModel)) + DOM.setStyles('mceModalBlocker', {position : 'absolute', left : vp.x, top : vp.y, width : vp.w - 2, height : vp.h - 2}); + + DOM.setAttrib(id, 'aria-hidden', 'false'); + t.focus(id); + t._fixIELayout(id, 1); + + // Focus ok button + if (DOM.get(id + '_ok')) + DOM.get(id + '_ok').focus(); + t.count++; + + return w; + }, + + focus : function(id) { + var t = this, w; + + if (w = t.windows[id]) { + w.zIndex = this.zIndex++; + w.element.setStyle('zIndex', w.zIndex); + w.element.update(); + + id = id + '_wrapper'; + DOM.removeClass(t.lastId, 'mceFocus'); + DOM.addClass(id, 'mceFocus'); + t.lastId = id; + + if (w.focussedElement) { + w.focussedElement.focus(); + } else if (DOM.get(id + '_ok')) { + DOM.get(w.id + '_ok').focus(); + } else if (DOM.get(w.id + '_ifr')) { + DOM.get(w.id + '_ifr').focus(); + } + } + }, -// alert(mcWindows.doc.getElementById(this.id + "_iframe")); + _addAll : function(te, ne) { + var i, n, t = this, dom = tinymce.DOM; - var e = mcWindows.doc.getElementById(this.id + "_iframe"); - e.parentNode.removeChild(e); + if (is(ne, 'string')) + te.appendChild(dom.doc.createTextNode(ne)); + else if (ne.length) { + te = te.appendChild(dom.create(ne[0], ne[1])); - var e = mcWindows.doc.getElementById(this.id + "_div"); - e.parentNode.removeChild(e); + for (i=2; i ix) { + fw = w; + ix = w.zIndex; + } + }); + return fw; + }, + + setTitle : function(w, ti) { + var e; + + w = this._findId(w); + + if (e = DOM.get(w + '_title')) + e.innerHTML = DOM.encode(ti); + }, + + alert : function(txt, cb, s) { + var t = this, w; + + w = t.open({ + title : t, + type : 'alert', + button_func : function(s) { + if (cb) + cb.call(s || t, s); + + t.close(null, w.id); + }, + content : DOM.encode(t.editor.getLang(txt, txt)), + inline : 1, + width : 400, + height : 130 + }); + }, + + confirm : function(txt, cb, s) { + var t = this, w; + + w = t.open({ + title : t, + type : 'confirm', + button_func : function(s) { + if (cb) + cb.call(s || t, s); + + t.close(null, w.id); + }, + content : DOM.encode(t.editor.getLang(txt, txt)), + inline : 1, + width : 400, + height : 130 + }); + }, + + // Internal functions + + _findId : function(w) { + var t = this; + + if (typeof(w) == 'string') + return w; + + each(t.windows, function(wo) { + var ifr = DOM.get(wo.id + '_ifr'); + + if (ifr && w == ifr.contentWindow) { + w = wo.id; + return false; + } + }); + + return w; + }, + + _fixIELayout : function(id, s) { + var w, img; + + if (!tinymce.isIE6) + return; + + // Fixes the bug where hover flickers and does odd things in IE6 + each(['n','s','w','e','nw','ne','sw','se'], function(v) { + var e = DOM.get(id + '_resize_' + v); + + DOM.setStyles(e, { + width : s ? e.clientWidth : '', + height : s ? e.clientHeight : '', + cursor : DOM.getStyle(e, 'cursor', 1) + }); + + DOM.setStyle(id + "_bottom", 'bottom', '-1px'); + + e = 0; + }); + + // Fixes graphics glitch + if (w = this.windows[id]) { + // Fixes rendering bug after resize + w.element.hide(); + w.element.show(); + + // Forced a repaint of the window + //DOM.get(id).style.filter = ''; + + // IE has a bug where images used in CSS won't get loaded + // sometimes when the cache in the browser is disabled + // This fix tries to solve it by loading the images using the image object + each(DOM.select('div,a', id), function(e, i) { + if (e.currentStyle.backgroundImage != 'none') { + img = new Image(); + img.src = e.currentStyle.backgroundImage.replace(/url\(\"(.+)\"\)/, '$1'); + } + }); + + DOM.get(id).style.filter = ''; + } + } + }); - for (var n in mcWindows.windows) { - var win = mcWindows.windows[n]; - if (typeof(win) == 'function') - continue; + // Register plugin + tinymce.PluginManager.add('inlinepopups', tinymce.plugins.InlinePopups); +})(); - if (winRef.name == win.id + "_iframe") { - win.focus(); - return; - } - } -}; - -MCWindow.prototype.onMouseDown = function(e) { - var elm = mcWindows.isMSIE ? this.wrapperFrame.event.srcElement : e.target; - - var scrollX = 0;//this.doc.body.scrollLeft; - var scrollY = 0;//this.doc.body.scrollTop; - - mcWindows.mouseDownScreenX = e.screenX; - mcWindows.mouseDownScreenY = e.screenY; - mcWindows.mouseDownLayerX = this.left; - mcWindows.mouseDownLayerY = this.top; - mcWindows.mouseDownWidth = parseInt(this.winElement.style.width); - mcWindows.mouseDownHeight = parseInt(this.winElement.style.height); - - if (this.resizeElement != null && elm == this.resizeElement.firstChild) - this.startResize(e); - else - this.startMove(e); - - mcWindows.cancelEvent(e); -}; - -// Global instance -var mcWindows = new MCWindows(); - -// Initialize windows -mcWindows.init({ - images_path : tinyMCE.baseURL + "/plugins/inlinepopups/images", - css_file : tinyMCE.baseURL + "/plugins/inlinepopups/css/inlinepopup.css" -});