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