5 * @copyright Copyright © 2004-2008, Moxiecode Systems AB, All rights reserved.
9 var DOM = tinymce.DOM, Element = tinymce.dom.Element, Event = tinymce.dom.Event, each = tinymce.each, is = tinymce.is;
11 tinymce.create('tinymce.plugins.InlinePopups', {
12 init : function(ed, url) {
13 // Replace window manager
14 ed.onBeforeRenderUI.add(function() {
15 ed.windowManager = new tinymce.InlineWindowManager(ed);
16 DOM.loadCSS(url + '/skins/' + (ed.settings.inlinepopups_skin || 'clearlooks2') + "/window.css");
20 getInfo : function() {
22 longname : 'InlinePopups',
23 author : 'Moxiecode Systems AB',
24 authorurl : 'http://tinymce.moxiecode.com',
25 infourl : 'http://wiki.moxiecode.com/index.php/TinyMCE:Plugins/inlinepopups',
26 version : tinymce.majorVersion + "." + tinymce.minorVersion
31 tinymce.create('tinymce.InlineWindowManager:tinymce.WindowManager', {
32 InlineWindowManager : function(ed) {
41 open : function(f, p) {
42 var t = this, id, opt = '', ed = t.editor, dw = 0, dh = 0, vp, po, mdf, clf, we, w, u;
49 return t.parent(f, p);
51 // Only store selection if the type is a normal window
53 t.bookmark = ed.selection.getBookmark('simple');
56 vp = DOM.getViewPort();
57 f.width = parseInt(f.width || 320);
58 f.height = parseInt(f.height || 240) + (tinymce.isIE ? 8 : 0);
59 f.min_width = parseInt(f.min_width || 150);
60 f.min_height = parseInt(f.min_height || 100);
61 f.max_width = parseInt(f.max_width || 2000);
62 f.max_height = parseInt(f.max_height || 2000);
63 f.left = f.left || Math.round(Math.max(vp.x, vp.x + (vp.w / 2.0) - (f.width / 2.0)));
64 f.top = f.top || Math.round(Math.max(vp.y, vp.y + (vp.h / 2.0) - (f.height / 2.0)));
65 f.movable = f.resizable = true;
66 p.mce_width = f.width;
67 p.mce_height = f.height;
70 p.mce_auto_focus = f.auto_focus;
73 // po = DOM.getPos(ed.getContainer());
79 t.onOpen.dispatch(t, f, p);
85 opt += ' mce' + f.type.substring(0, 1).toUpperCase() + f.type.substring(1);
91 opt += ' mceStatusbar';
94 opt += ' mceResizable';
97 opt += ' mceMinimizable';
100 opt += ' mceMaximizable';
103 opt += ' mceMovable';
105 // Create DOM objects
106 t._addAll(DOM.doc.body,
107 ['div', {id : id, 'class' : ed.settings.inlinepopups_skin || 'clearlooks2', style : 'width:100px;height:100px'},
108 ['div', {id : id + '_wrapper', 'class' : 'mceWrapper' + opt},
109 ['div', {id : id + '_top', 'class' : 'mceTop'},
110 ['div', {'class' : 'mceLeft'}],
111 ['div', {'class' : 'mceCenter'}],
112 ['div', {'class' : 'mceRight'}],
113 ['span', {id : id + '_title'}, f.title || '']
116 ['div', {id : id + '_middle', 'class' : 'mceMiddle'},
117 ['div', {id : id + '_left', 'class' : 'mceLeft'}],
118 ['span', {id : id + '_content'}],
119 ['div', {id : id + '_right', 'class' : 'mceRight'}]
122 ['div', {id : id + '_bottom', 'class' : 'mceBottom'},
123 ['div', {'class' : 'mceLeft'}],
124 ['div', {'class' : 'mceCenter'}],
125 ['div', {'class' : 'mceRight'}],
126 ['span', {id : id + '_status'}, 'Content']
129 ['a', {'class' : 'mceMove', tabindex : '-1', href : 'javascript:;'}],
130 ['a', {'class' : 'mceMin', tabindex : '-1', href : 'javascript:;', onmousedown : 'return false;'}],
131 ['a', {'class' : 'mceMax', tabindex : '-1', href : 'javascript:;', onmousedown : 'return false;'}],
132 ['a', {'class' : 'mceMed', tabindex : '-1', href : 'javascript:;', onmousedown : 'return false;'}],
133 ['a', {'class' : 'mceClose', tabindex : '-1', href : 'javascript:;', onmousedown : 'return false;'}],
134 ['a', {id : id + '_resize_n', 'class' : 'mceResize mceResizeN', tabindex : '-1', href : 'javascript:;'}],
135 ['a', {id : id + '_resize_s', 'class' : 'mceResize mceResizeS', tabindex : '-1', href : 'javascript:;'}],
136 ['a', {id : id + '_resize_w', 'class' : 'mceResize mceResizeW', tabindex : '-1', href : 'javascript:;'}],
137 ['a', {id : id + '_resize_e', 'class' : 'mceResize mceResizeE', tabindex : '-1', href : 'javascript:;'}],
138 ['a', {id : id + '_resize_nw', 'class' : 'mceResize mceResizeNW', tabindex : '-1', href : 'javascript:;'}],
139 ['a', {id : id + '_resize_ne', 'class' : 'mceResize mceResizeNE', tabindex : '-1', href : 'javascript:;'}],
140 ['a', {id : id + '_resize_sw', 'class' : 'mceResize mceResizeSW', tabindex : '-1', href : 'javascript:;'}],
141 ['a', {id : id + '_resize_se', 'class' : 'mceResize mceResizeSE', tabindex : '-1', href : 'javascript:;'}]
146 DOM.setStyles(id, {top : -10000, left : -10000});
148 // Fix gecko rendering bug, where the editors iframe messed with window contents
150 DOM.setStyle(id, 'overflow', 'auto');
154 dw += DOM.get(id + '_left').clientWidth;
155 dw += DOM.get(id + '_right').clientWidth;
156 dh += DOM.get(id + '_top').clientHeight;
157 dh += DOM.get(id + '_bottom').clientHeight;
161 DOM.setStyles(id, {top : f.top, left : f.left, width : f.width + dw, height : f.height + dh});
165 if (tinymce.relaxedDomain)
166 u += (u.indexOf('?') == -1 ? '?' : '&') + 'mce_rdomain=' + tinymce.relaxedDomain;
168 u = tinymce._addVer(u);
172 DOM.add(id + '_content', 'iframe', {id : id + '_ifr', src : 'javascript:""', frameBorder : 0, style : 'border:0;width:10px;height:10px'});
173 DOM.setStyles(id + '_ifr', {width : f.width, height : f.height});
174 DOM.setAttrib(id + '_ifr', 'src', u);
176 DOM.add(id + '_wrapper', 'a', {id : id + '_ok', 'class' : 'mceButton mceOk', href : 'javascript:;', onmousedown : 'return false;'}, 'Ok');
178 if (f.type == 'confirm')
179 DOM.add(id + '_wrapper', 'a', {'class' : 'mceButton mceCancel', href : 'javascript:;', onmousedown : 'return false;'}, 'Cancel');
181 DOM.add(id + '_middle', 'div', {'class' : 'mceIcon'});
182 DOM.setHTML(id + '_content', f.content.replace('\n', '<br />'));
186 mdf = Event.add(id, 'mousedown', function(e) {
187 var n = e.target, w, vp;
192 if (n.nodeName == 'A' || n.nodeName == 'a') {
193 if (n.className == 'mceMax') {
194 w.oldPos = w.element.getXY();
195 w.oldSize = w.element.getSize();
197 vp = DOM.getViewPort();
199 // Reduce viewport size to avoid scrollbars
203 w.element.moveTo(vp.x, vp.y);
204 w.element.resizeTo(vp.w, vp.h);
205 DOM.setStyles(id + '_ifr', {width : vp.w - w.deltaWidth, height : vp.h - w.deltaHeight});
206 DOM.addClass(id + '_wrapper', 'mceMaximized');
207 } else if (n.className == 'mceMed') {
209 w.element.moveTo(w.oldPos.x, w.oldPos.y);
210 w.element.resizeTo(w.oldSize.w, w.oldSize.h);
211 w.iframeElement.resizeTo(w.oldSize.w - w.deltaWidth, w.oldSize.h - w.deltaHeight);
213 DOM.removeClass(id + '_wrapper', 'mceMaximized');
214 } else if (n.className == 'mceMove')
215 return t._startDrag(id, e, n.className);
216 else if (DOM.hasClass(n, 'mceResize'))
217 return t._startDrag(id, e, n.className.substring(13));
221 clf = Event.add(id, 'click', function(e) {
226 if (n.nodeName == 'A' || n.nodeName == 'a') {
227 switch (n.className) {
230 return Event.cancel(e);
232 case 'mceButton mceOk':
233 case 'mceButton mceCancel':
234 f.button_func(n.className == 'mceButton mceOk');
235 return Event.cancel(e);
241 w = t.windows[id] = {
243 mousedown_func : mdf,
245 element : new Element(id, {blocker : 1, container : ed.getContainer()}),
246 iframeElement : new Element(id + '_ifr'),
252 w.iframeElement.on('focus', function() {
257 if (t.count == 0 && t.editor.getParam('dialog_type', 'modal') == 'modal') {
258 DOM.add(DOM.doc.body, 'div', {
259 id : 'mceModalBlocker',
260 'class' : (t.editor.settings.inlinepopups_skin || 'clearlooks2') + '_modalBlocker',
261 style : {zIndex : t.zIndex - 1}
264 DOM.show('mceModalBlocker'); // Reduces flicker in IE
266 DOM.setStyle('mceModalBlocker', 'z-index', t.zIndex - 1);
268 if (tinymce.isIE6 || /Firefox\/2\./.test(navigator.userAgent) || (tinymce.isIE && !DOM.boxModel))
269 DOM.setStyles('mceModalBlocker', {position : 'absolute', width : vp.w - 2, height : vp.h - 2});
272 t._fixIELayout(id, 1);
275 if (DOM.get(id + '_ok'))
276 DOM.get(id + '_ok').focus();
283 focus : function(id) {
286 if (w = t.windows[id]) {
287 w.zIndex = this.zIndex++;
288 w.element.setStyle('zIndex', w.zIndex);
291 id = id + '_wrapper';
292 DOM.removeClass(t.lastId, 'mceFocus');
293 DOM.addClass(id, 'mceFocus');
298 _addAll : function(te, ne) {
299 var i, n, t = this, dom = tinymce.DOM;
301 if (is(ne, 'string'))
302 te.appendChild(dom.doc.createTextNode(ne));
303 else if (ne.length) {
304 te = te.appendChild(dom.create(ne[0], ne[1]));
306 for (i=2; i<ne.length; i++)
307 t._addAll(te, ne[i]);
311 _startDrag : function(id, se, ac) {
312 var t = this, mu, mm, d = DOM.doc, eb, w = t.windows[id], we = w.element, sp = we.getXY(), p, sz, ph, cp, vp, sx, sy, sex, sey, dx, dy, dw, dh;
314 // Get positons and sizes
315 // cp = DOM.getPos(t.editor.getContainer());
317 vp = DOM.getViewPort();
319 // Reduce viewport size to avoid scrollbars while dragging
325 dx = dy = dw = dh = 0;
328 mu = Event.add(d, 'mouseup', function(e) {
329 Event.remove(d, 'mouseup', mu);
330 Event.remove(d, 'mousemove', mm);
338 DOM.setStyles(id + '_ifr', {width : sz.w - w.deltaWidth, height : sz.h - w.deltaHeight});
339 t._fixIELayout(id, 1);
341 return Event.cancel(e);
347 function startMove() {
351 t._fixIELayout(id, 0);
353 // Setup event blocker
354 DOM.add(d.body, 'div', {
355 id : 'mceEventBlocker',
356 'class' : 'mceEventBlocker ' + (t.editor.settings.inlinepopups_skin || 'clearlooks2'),
357 style : {zIndex : t.zIndex + 1}
360 if (tinymce.isIE6 || (tinymce.isIE && !DOM.boxModel))
361 DOM.setStyles('mceEventBlocker', {position : 'absolute', width : vp.w - 2, height : vp.h - 2});
363 eb = new Element('mceEventBlocker');
369 sx = cp.x + p.x - vp.x;
370 sy = cp.y + p.y - vp.y;
371 DOM.add(eb.get(), 'div', {id : 'mcePlaceHolder', 'class' : 'mcePlaceHolder', style : {left : sx, top : sy, width : sz.w, height : sz.h}});
372 ph = new Element('mcePlaceHolder');
375 // Handle mouse move/drag
376 mm = Event.add(d, 'mousemove', function(e) {
397 if (ac == "ResizeNW") {
400 } else if (ac == "ResizeNE")
410 if (ac == "ResizeSW") {
413 } else if (ac == "ResizeSE")
426 if (dw < (v = w.features.min_width - sz.w)) {
433 if (dh < (v = w.features.min_height - sz.h)) {
440 dw = Math.min(dw, w.features.max_width - sz.w);
441 dh = Math.min(dh, w.features.max_height - sz.h);
442 dx = Math.max(dx, vp.x - (sx + vp.x));
443 dy = Math.max(dy, vp.y - (sy + vp.y));
444 dx = Math.min(dx, (vp.w + vp.x) - (sx + sz.w + vp.x));
445 dy = Math.min(dy, (vp.h + vp.y) - (sy + sz.h + vp.y));
455 ph.moveTo(sx + dx, sy + dy);
460 ph.resizeTo(sz.w + dw, sz.h + dh);
462 return Event.cancel(e);
465 return Event.cancel(se);
468 resizeBy : function(dw, dh, id) {
469 var w = this.windows[id];
472 w.element.resizeBy(dw, dh);
473 w.iframeElement.resizeBy(dw, dh);
477 close : function(win, id) {
478 var t = this, w, d = DOM.doc, ix = 0, fw, id;
480 id = t._findId(id || win);
482 // Probably not inline
483 if (!t.windows[id]) {
491 DOM.remove('mceModalBlocker');
493 if (w = t.windows[id]) {
494 t.onClose.dispatch(t);
495 Event.remove(d, 'mousedown', w.mousedownFunc);
496 Event.remove(d, 'click', w.clickFunc);
498 Event.clear(id + '_ifr');
500 DOM.setAttrib(id + '_ifr', 'src', 'javascript:""'); // Prevent leak
502 delete t.windows[id];
504 // Find front most window and focus that
505 each (t.windows, function(w) {
517 setTitle : function(w, ti) {
522 if (e = DOM.get(w + '_title'))
523 e.innerHTML = DOM.encode(ti);
526 alert : function(txt, cb, s) {
532 button_func : function(s) {
538 content : DOM.encode(t.editor.getLang(txt, txt)),
545 confirm : function(txt, cb, s) {
551 button_func : function(s) {
557 content : DOM.encode(t.editor.getLang(txt, txt)),
564 // Internal functions
566 _findId : function(w) {
569 if (typeof(w) == 'string')
572 each(t.windows, function(wo) {
573 var ifr = DOM.get(wo.id + '_ifr');
575 if (ifr && w == ifr.contentWindow) {
584 _fixIELayout : function(id, s) {
590 // Fixes the bug where hover flickers and does odd things in IE6
591 each(['n','s','w','e','nw','ne','sw','se'], function(v) {
592 var e = DOM.get(id + '_resize_' + v);
595 width : s ? e.clientWidth : '',
596 height : s ? e.clientHeight : '',
597 cursor : DOM.getStyle(e, 'cursor', 1)
600 DOM.setStyle(id + "_bottom", 'bottom', '-1px');
605 // Fixes graphics glitch
606 if (w = this.windows[id]) {
607 // Fixes rendering bug after resize
611 // Forced a repaint of the window
612 //DOM.get(id).style.filter = '';
614 // IE has a bug where images used in CSS won't get loaded
615 // sometimes when the cache in the browser is disabled
616 // This fix tries to solve it by loading the images using the image object
617 each(DOM.select('div,a', id), function(e, i) {
618 if (e.currentStyle.backgroundImage != 'none') {
620 img.src = e.currentStyle.backgroundImage.replace(/url\(\"(.+)\"\)/, '$1');
624 DOM.get(id).style.filter = '';
630 tinymce.PluginManager.add('inlinepopups', tinymce.plugins.InlinePopups);