bgneal@45: /** bgneal@45: * $Id: editor_plugin_src.js 999 2009-02-10 17:42:58Z spocke $ bgneal@45: * bgneal@45: * @author Moxiecode bgneal@45: * @copyright Copyright © 2004-2008, Moxiecode Systems AB, All rights reserved. bgneal@45: */ bgneal@45: bgneal@45: (function() { bgneal@45: var DOM = tinymce.DOM, Element = tinymce.dom.Element, Event = tinymce.dom.Event, each = tinymce.each, is = tinymce.is; bgneal@45: bgneal@45: tinymce.create('tinymce.plugins.InlinePopups', { bgneal@45: init : function(ed, url) { bgneal@45: // Replace window manager bgneal@45: ed.onBeforeRenderUI.add(function() { bgneal@45: ed.windowManager = new tinymce.InlineWindowManager(ed); bgneal@45: DOM.loadCSS(url + '/skins/' + (ed.settings.inlinepopups_skin || 'clearlooks2') + "/window.css"); bgneal@45: }); bgneal@45: }, bgneal@45: bgneal@45: getInfo : function() { bgneal@45: return { bgneal@45: longname : 'InlinePopups', bgneal@45: author : 'Moxiecode Systems AB', bgneal@45: authorurl : 'http://tinymce.moxiecode.com', bgneal@45: infourl : 'http://wiki.moxiecode.com/index.php/TinyMCE:Plugins/inlinepopups', bgneal@45: version : tinymce.majorVersion + "." + tinymce.minorVersion bgneal@45: }; bgneal@45: } bgneal@45: }); bgneal@45: bgneal@45: tinymce.create('tinymce.InlineWindowManager:tinymce.WindowManager', { bgneal@45: InlineWindowManager : function(ed) { bgneal@45: var t = this; bgneal@45: bgneal@45: t.parent(ed); bgneal@45: t.zIndex = 300000; bgneal@45: t.count = 0; bgneal@45: t.windows = {}; bgneal@45: }, bgneal@45: bgneal@45: open : function(f, p) { bgneal@45: var t = this, id, opt = '', ed = t.editor, dw = 0, dh = 0, vp, po, mdf, clf, we, w, u; bgneal@45: bgneal@45: f = f || {}; bgneal@45: p = p || {}; bgneal@45: bgneal@45: // Run native windows bgneal@45: if (!f.inline) bgneal@45: return t.parent(f, p); bgneal@45: bgneal@45: // Only store selection if the type is a normal window bgneal@45: if (!f.type) bgneal@45: t.bookmark = ed.selection.getBookmark('simple'); bgneal@45: bgneal@45: id = DOM.uniqueId(); bgneal@45: vp = DOM.getViewPort(); bgneal@45: f.width = parseInt(f.width || 320); bgneal@45: f.height = parseInt(f.height || 240) + (tinymce.isIE ? 8 : 0); bgneal@45: f.min_width = parseInt(f.min_width || 150); bgneal@45: f.min_height = parseInt(f.min_height || 100); bgneal@45: f.max_width = parseInt(f.max_width || 2000); bgneal@45: f.max_height = parseInt(f.max_height || 2000); bgneal@45: f.left = f.left || Math.round(Math.max(vp.x, vp.x + (vp.w / 2.0) - (f.width / 2.0))); bgneal@45: f.top = f.top || Math.round(Math.max(vp.y, vp.y + (vp.h / 2.0) - (f.height / 2.0))); bgneal@45: f.movable = f.resizable = true; bgneal@45: p.mce_width = f.width; bgneal@45: p.mce_height = f.height; bgneal@45: p.mce_inline = true; bgneal@45: p.mce_window_id = id; bgneal@45: p.mce_auto_focus = f.auto_focus; bgneal@45: bgneal@45: // Transpose bgneal@45: // po = DOM.getPos(ed.getContainer()); bgneal@45: // f.left -= po.x; bgneal@45: // f.top -= po.y; bgneal@45: bgneal@45: t.features = f; bgneal@45: t.params = p; bgneal@45: t.onOpen.dispatch(t, f, p); bgneal@45: bgneal@45: if (f.type) { bgneal@45: opt += ' mceModal'; bgneal@45: bgneal@45: if (f.type) bgneal@45: opt += ' mce' + f.type.substring(0, 1).toUpperCase() + f.type.substring(1); bgneal@45: bgneal@45: f.resizable = false; bgneal@45: } bgneal@45: bgneal@45: if (f.statusbar) bgneal@45: opt += ' mceStatusbar'; bgneal@45: bgneal@45: if (f.resizable) bgneal@45: opt += ' mceResizable'; bgneal@45: bgneal@45: if (f.minimizable) bgneal@45: opt += ' mceMinimizable'; bgneal@45: bgneal@45: if (f.maximizable) bgneal@45: opt += ' mceMaximizable'; bgneal@45: bgneal@45: if (f.movable) bgneal@45: opt += ' mceMovable'; bgneal@45: bgneal@45: // Create DOM objects bgneal@45: t._addAll(DOM.doc.body, bgneal@45: ['div', {id : id, 'class' : ed.settings.inlinepopups_skin || 'clearlooks2', style : 'width:100px;height:100px'}, bgneal@45: ['div', {id : id + '_wrapper', 'class' : 'mceWrapper' + opt}, bgneal@45: ['div', {id : id + '_top', 'class' : 'mceTop'}, bgneal@45: ['div', {'class' : 'mceLeft'}], bgneal@45: ['div', {'class' : 'mceCenter'}], bgneal@45: ['div', {'class' : 'mceRight'}], bgneal@45: ['span', {id : id + '_title'}, f.title || ''] bgneal@45: ], bgneal@45: bgneal@45: ['div', {id : id + '_middle', 'class' : 'mceMiddle'}, bgneal@45: ['div', {id : id + '_left', 'class' : 'mceLeft'}], bgneal@45: ['span', {id : id + '_content'}], bgneal@45: ['div', {id : id + '_right', 'class' : 'mceRight'}] bgneal@45: ], bgneal@45: bgneal@45: ['div', {id : id + '_bottom', 'class' : 'mceBottom'}, bgneal@45: ['div', {'class' : 'mceLeft'}], bgneal@45: ['div', {'class' : 'mceCenter'}], bgneal@45: ['div', {'class' : 'mceRight'}], bgneal@45: ['span', {id : id + '_status'}, 'Content'] bgneal@45: ], bgneal@45: bgneal@45: ['a', {'class' : 'mceMove', tabindex : '-1', href : 'javascript:;'}], bgneal@45: ['a', {'class' : 'mceMin', tabindex : '-1', href : 'javascript:;', onmousedown : 'return false;'}], bgneal@45: ['a', {'class' : 'mceMax', tabindex : '-1', href : 'javascript:;', onmousedown : 'return false;'}], bgneal@45: ['a', {'class' : 'mceMed', tabindex : '-1', href : 'javascript:;', onmousedown : 'return false;'}], bgneal@45: ['a', {'class' : 'mceClose', tabindex : '-1', href : 'javascript:;', onmousedown : 'return false;'}], bgneal@45: ['a', {id : id + '_resize_n', 'class' : 'mceResize mceResizeN', tabindex : '-1', href : 'javascript:;'}], bgneal@45: ['a', {id : id + '_resize_s', 'class' : 'mceResize mceResizeS', tabindex : '-1', href : 'javascript:;'}], bgneal@45: ['a', {id : id + '_resize_w', 'class' : 'mceResize mceResizeW', tabindex : '-1', href : 'javascript:;'}], bgneal@45: ['a', {id : id + '_resize_e', 'class' : 'mceResize mceResizeE', tabindex : '-1', href : 'javascript:;'}], bgneal@45: ['a', {id : id + '_resize_nw', 'class' : 'mceResize mceResizeNW', tabindex : '-1', href : 'javascript:;'}], bgneal@45: ['a', {id : id + '_resize_ne', 'class' : 'mceResize mceResizeNE', tabindex : '-1', href : 'javascript:;'}], bgneal@45: ['a', {id : id + '_resize_sw', 'class' : 'mceResize mceResizeSW', tabindex : '-1', href : 'javascript:;'}], bgneal@45: ['a', {id : id + '_resize_se', 'class' : 'mceResize mceResizeSE', tabindex : '-1', href : 'javascript:;'}] bgneal@45: ] bgneal@45: ] bgneal@45: ); bgneal@45: bgneal@45: DOM.setStyles(id, {top : -10000, left : -10000}); bgneal@45: bgneal@45: // Fix gecko rendering bug, where the editors iframe messed with window contents bgneal@45: if (tinymce.isGecko) bgneal@45: DOM.setStyle(id, 'overflow', 'auto'); bgneal@45: bgneal@45: // Measure borders bgneal@45: if (!f.type) { bgneal@45: dw += DOM.get(id + '_left').clientWidth; bgneal@45: dw += DOM.get(id + '_right').clientWidth; bgneal@45: dh += DOM.get(id + '_top').clientHeight; bgneal@45: dh += DOM.get(id + '_bottom').clientHeight; bgneal@45: } bgneal@45: bgneal@45: // Resize window bgneal@45: DOM.setStyles(id, {top : f.top, left : f.left, width : f.width + dw, height : f.height + dh}); bgneal@45: bgneal@45: u = f.url || f.file; bgneal@45: if (u) { bgneal@45: if (tinymce.relaxedDomain) bgneal@45: u += (u.indexOf('?') == -1 ? '?' : '&') + 'mce_rdomain=' + tinymce.relaxedDomain; bgneal@45: bgneal@45: u = tinymce._addVer(u); bgneal@45: } bgneal@45: bgneal@45: if (!f.type) { bgneal@45: DOM.add(id + '_content', 'iframe', {id : id + '_ifr', src : 'javascript:""', frameBorder : 0, style : 'border:0;width:10px;height:10px'}); bgneal@45: DOM.setStyles(id + '_ifr', {width : f.width, height : f.height}); bgneal@45: DOM.setAttrib(id + '_ifr', 'src', u); bgneal@45: } else { bgneal@45: DOM.add(id + '_wrapper', 'a', {id : id + '_ok', 'class' : 'mceButton mceOk', href : 'javascript:;', onmousedown : 'return false;'}, 'Ok'); bgneal@45: bgneal@45: if (f.type == 'confirm') bgneal@45: DOM.add(id + '_wrapper', 'a', {'class' : 'mceButton mceCancel', href : 'javascript:;', onmousedown : 'return false;'}, 'Cancel'); bgneal@45: bgneal@45: DOM.add(id + '_middle', 'div', {'class' : 'mceIcon'}); bgneal@45: DOM.setHTML(id + '_content', f.content.replace('\n', '
')); bgneal@45: } bgneal@45: bgneal@45: // Register events bgneal@45: mdf = Event.add(id, 'mousedown', function(e) { bgneal@45: var n = e.target, w, vp; bgneal@45: bgneal@45: w = t.windows[id]; bgneal@45: t.focus(id); bgneal@45: bgneal@45: if (n.nodeName == 'A' || n.nodeName == 'a') { bgneal@45: if (n.className == 'mceMax') { bgneal@45: w.oldPos = w.element.getXY(); bgneal@45: w.oldSize = w.element.getSize(); bgneal@45: bgneal@45: vp = DOM.getViewPort(); bgneal@45: bgneal@45: // Reduce viewport size to avoid scrollbars bgneal@45: vp.w -= 2; bgneal@45: vp.h -= 2; bgneal@45: bgneal@45: w.element.moveTo(vp.x, vp.y); bgneal@45: w.element.resizeTo(vp.w, vp.h); bgneal@45: DOM.setStyles(id + '_ifr', {width : vp.w - w.deltaWidth, height : vp.h - w.deltaHeight}); bgneal@45: DOM.addClass(id + '_wrapper', 'mceMaximized'); bgneal@45: } else if (n.className == 'mceMed') { bgneal@45: // Reset to old size bgneal@45: w.element.moveTo(w.oldPos.x, w.oldPos.y); bgneal@45: w.element.resizeTo(w.oldSize.w, w.oldSize.h); bgneal@45: w.iframeElement.resizeTo(w.oldSize.w - w.deltaWidth, w.oldSize.h - w.deltaHeight); bgneal@45: bgneal@45: DOM.removeClass(id + '_wrapper', 'mceMaximized'); bgneal@45: } else if (n.className == 'mceMove') bgneal@45: return t._startDrag(id, e, n.className); bgneal@45: else if (DOM.hasClass(n, 'mceResize')) bgneal@45: return t._startDrag(id, e, n.className.substring(13)); bgneal@45: } bgneal@45: }); bgneal@45: bgneal@45: clf = Event.add(id, 'click', function(e) { bgneal@45: var n = e.target; bgneal@45: bgneal@45: t.focus(id); bgneal@45: bgneal@45: if (n.nodeName == 'A' || n.nodeName == 'a') { bgneal@45: switch (n.className) { bgneal@45: case 'mceClose': bgneal@45: t.close(null, id); bgneal@45: return Event.cancel(e); bgneal@45: bgneal@45: case 'mceButton mceOk': bgneal@45: case 'mceButton mceCancel': bgneal@45: f.button_func(n.className == 'mceButton mceOk'); bgneal@45: return Event.cancel(e); bgneal@45: } bgneal@45: } bgneal@45: }); bgneal@45: bgneal@45: // Add window bgneal@45: w = t.windows[id] = { bgneal@45: id : id, bgneal@45: mousedown_func : mdf, bgneal@45: click_func : clf, bgneal@45: element : new Element(id, {blocker : 1, container : ed.getContainer()}), bgneal@45: iframeElement : new Element(id + '_ifr'), bgneal@45: features : f, bgneal@45: deltaWidth : dw, bgneal@45: deltaHeight : dh bgneal@45: }; bgneal@45: bgneal@45: w.iframeElement.on('focus', function() { bgneal@45: t.focus(id); bgneal@45: }); bgneal@45: bgneal@45: // Setup blocker bgneal@45: if (t.count == 0 && t.editor.getParam('dialog_type', 'modal') == 'modal') { bgneal@45: DOM.add(DOM.doc.body, 'div', { bgneal@45: id : 'mceModalBlocker', bgneal@45: 'class' : (t.editor.settings.inlinepopups_skin || 'clearlooks2') + '_modalBlocker', bgneal@45: style : {zIndex : t.zIndex - 1} bgneal@45: }); bgneal@45: bgneal@45: DOM.show('mceModalBlocker'); // Reduces flicker in IE bgneal@45: } else bgneal@45: DOM.setStyle('mceModalBlocker', 'z-index', t.zIndex - 1); bgneal@45: bgneal@45: if (tinymce.isIE6 || /Firefox\/2\./.test(navigator.userAgent) || (tinymce.isIE && !DOM.boxModel)) bgneal@45: DOM.setStyles('mceModalBlocker', {position : 'absolute', left : vp.x, top : vp.y, width : vp.w - 2, height : vp.h - 2}); bgneal@45: bgneal@45: t.focus(id); bgneal@45: t._fixIELayout(id, 1); bgneal@45: bgneal@45: // Focus ok button bgneal@45: if (DOM.get(id + '_ok')) bgneal@45: DOM.get(id + '_ok').focus(); bgneal@45: bgneal@45: t.count++; bgneal@45: bgneal@45: return w; bgneal@45: }, bgneal@45: bgneal@45: focus : function(id) { bgneal@45: var t = this, w; bgneal@45: bgneal@45: if (w = t.windows[id]) { bgneal@45: w.zIndex = this.zIndex++; bgneal@45: w.element.setStyle('zIndex', w.zIndex); bgneal@45: w.element.update(); bgneal@45: bgneal@45: id = id + '_wrapper'; bgneal@45: DOM.removeClass(t.lastId, 'mceFocus'); bgneal@45: DOM.addClass(id, 'mceFocus'); bgneal@45: t.lastId = id; bgneal@45: } bgneal@45: }, bgneal@45: bgneal@45: _addAll : function(te, ne) { bgneal@45: var i, n, t = this, dom = tinymce.DOM; bgneal@45: bgneal@45: if (is(ne, 'string')) bgneal@45: te.appendChild(dom.doc.createTextNode(ne)); bgneal@45: else if (ne.length) { bgneal@45: te = te.appendChild(dom.create(ne[0], ne[1])); bgneal@45: bgneal@45: for (i=2; i ix) { bgneal@45: fw = w; bgneal@45: ix = w.zIndex; bgneal@45: } bgneal@45: }); bgneal@45: bgneal@45: if (fw) bgneal@45: t.focus(fw.id); bgneal@45: } bgneal@45: }, bgneal@45: bgneal@45: setTitle : function(w, ti) { bgneal@45: var e; bgneal@45: bgneal@45: w = this._findId(w); bgneal@45: bgneal@45: if (e = DOM.get(w + '_title')) bgneal@45: e.innerHTML = DOM.encode(ti); bgneal@45: }, bgneal@45: bgneal@45: alert : function(txt, cb, s) { bgneal@45: var t = this, w; bgneal@45: bgneal@45: w = t.open({ bgneal@45: title : t, bgneal@45: type : 'alert', bgneal@45: button_func : function(s) { bgneal@45: if (cb) bgneal@45: cb.call(s || t, s); bgneal@45: bgneal@45: t.close(null, w.id); bgneal@45: }, bgneal@45: content : DOM.encode(t.editor.getLang(txt, txt)), bgneal@45: inline : 1, bgneal@45: width : 400, bgneal@45: height : 130 bgneal@45: }); bgneal@45: }, bgneal@45: bgneal@45: confirm : function(txt, cb, s) { bgneal@45: var t = this, w; bgneal@45: bgneal@45: w = t.open({ bgneal@45: title : t, bgneal@45: type : 'confirm', bgneal@45: button_func : function(s) { bgneal@45: if (cb) bgneal@45: cb.call(s || t, s); bgneal@45: bgneal@45: t.close(null, w.id); bgneal@45: }, bgneal@45: content : DOM.encode(t.editor.getLang(txt, txt)), bgneal@45: inline : 1, bgneal@45: width : 400, bgneal@45: height : 130 bgneal@45: }); bgneal@45: }, bgneal@45: bgneal@45: // Internal functions bgneal@45: bgneal@45: _findId : function(w) { bgneal@45: var t = this; bgneal@45: bgneal@45: if (typeof(w) == 'string') bgneal@45: return w; bgneal@45: bgneal@45: each(t.windows, function(wo) { bgneal@45: var ifr = DOM.get(wo.id + '_ifr'); bgneal@45: bgneal@45: if (ifr && w == ifr.contentWindow) { bgneal@45: w = wo.id; bgneal@45: return false; bgneal@45: } bgneal@45: }); bgneal@45: bgneal@45: return w; bgneal@45: }, bgneal@45: bgneal@45: _fixIELayout : function(id, s) { bgneal@45: var w, img; bgneal@45: bgneal@45: if (!tinymce.isIE6) bgneal@45: return; bgneal@45: bgneal@45: // Fixes the bug where hover flickers and does odd things in IE6 bgneal@45: each(['n','s','w','e','nw','ne','sw','se'], function(v) { bgneal@45: var e = DOM.get(id + '_resize_' + v); bgneal@45: bgneal@45: DOM.setStyles(e, { bgneal@45: width : s ? e.clientWidth : '', bgneal@45: height : s ? e.clientHeight : '', bgneal@45: cursor : DOM.getStyle(e, 'cursor', 1) bgneal@45: }); bgneal@45: bgneal@45: DOM.setStyle(id + "_bottom", 'bottom', '-1px'); bgneal@45: bgneal@45: e = 0; bgneal@45: }); bgneal@45: bgneal@45: // Fixes graphics glitch bgneal@45: if (w = this.windows[id]) { bgneal@45: // Fixes rendering bug after resize bgneal@45: w.element.hide(); bgneal@45: w.element.show(); bgneal@45: bgneal@45: // Forced a repaint of the window bgneal@45: //DOM.get(id).style.filter = ''; bgneal@45: bgneal@45: // IE has a bug where images used in CSS won't get loaded bgneal@45: // sometimes when the cache in the browser is disabled bgneal@45: // This fix tries to solve it by loading the images using the image object bgneal@45: each(DOM.select('div,a', id), function(e, i) { bgneal@45: if (e.currentStyle.backgroundImage != 'none') { bgneal@45: img = new Image(); bgneal@45: img.src = e.currentStyle.backgroundImage.replace(/url\(\"(.+)\"\)/, '$1'); bgneal@45: } bgneal@45: }); bgneal@45: bgneal@45: DOM.get(id).style.filter = ''; bgneal@45: } bgneal@45: } bgneal@45: }); bgneal@45: bgneal@45: // Register plugin bgneal@45: tinymce.PluginManager.add('inlinepopups', tinymce.plugins.InlinePopups); bgneal@45: })(); bgneal@45: