2 * Copyright © 2004-2008, Moxiecode Systems AB, All rights reserved.
\r
6 var DOM = tinymce.DOM, Element = tinymce.dom.Element, Event = tinymce.dom.Event, each = tinymce.each, is = tinymce.is;
\r
8 tinymce.create('tinymce.plugins.InlinePopups', {
\r
9 init : function(ed, url) {
\r
10 // Replace window manager
\r
11 ed.onBeforeRenderUI.add(function() {
\r
12 ed.windowManager = new tinymce.InlineWindowManager(ed);
\r
13 DOM.loadCSS(url + '/skins/' + (ed.settings.inlinepopups_skin || 'clearlooks2') + "/window.css");
\r
17 getInfo : function() {
\r
19 longname : 'InlinePopups',
\r
20 author : 'Moxiecode Systems AB',
\r
21 authorurl : 'http://tinymce.moxiecode.com',
\r
22 infourl : 'http://wiki.moxiecode.com/index.php/TinyMCE:Plugins/inlinepopups',
\r
23 version : tinymce.majorVersion + "." + tinymce.minorVersion
\r
28 tinymce.create('tinymce.InlineWindowManager:tinymce.WindowManager', {
\r
29 InlineWindowManager : function(ed) {
\r
38 open : function(f, p) {
\r
39 var t = this, id, opt = '', ed = t.editor, dw = 0, dh = 0, vp, po, mdf, clf, we, w, u;
\r
44 // Run native windows
\r
46 return t.parent(f, p);
\r
48 // Only store selection if the type is a normal window
\r
50 t.bookmark = ed.selection.getBookmark('simple');
\r
52 id = DOM.uniqueId();
\r
53 vp = DOM.getViewPort();
\r
54 f.width = parseInt(f.width || 320);
\r
55 f.height = parseInt(f.height || 240) + (tinymce.isIE ? 8 : 0);
\r
56 f.min_width = parseInt(f.min_width || 150);
\r
57 f.min_height = parseInt(f.min_height || 100);
\r
58 f.max_width = parseInt(f.max_width || 2000);
\r
59 f.max_height = parseInt(f.max_height || 2000);
\r
60 f.left = f.left || Math.round(Math.max(vp.x, vp.x + (vp.w / 2.0) - (f.width / 2.0)));
\r
61 f.top = f.top || Math.round(Math.max(vp.y, vp.y + (vp.h / 2.0) - (f.height / 2.0)));
\r
62 f.movable = f.resizable = true;
\r
63 p.mce_width = f.width;
\r
64 p.mce_height = f.height;
\r
65 p.mce_inline = true;
\r
66 p.mce_window_id = id;
\r
67 p.mce_auto_focus = f.auto_focus;
\r
70 // po = DOM.getPos(ed.getContainer());
\r
76 t.onOpen.dispatch(t, f, p);
\r
82 opt += ' mce' + f.type.substring(0, 1).toUpperCase() + f.type.substring(1);
\r
84 f.resizable = false;
\r
88 opt += ' mceStatusbar';
\r
91 opt += ' mceResizable';
\r
94 opt += ' mceMinimizable';
\r
97 opt += ' mceMaximizable';
\r
100 opt += ' mceMovable';
\r
102 // Create DOM objects
\r
103 t._addAll(DOM.doc.body,
\r
104 ['div', {id : id, 'class' : ed.settings.inlinepopups_skin || 'clearlooks2', style : 'width:100px;height:100px'},
\r
105 ['div', {id : id + '_wrapper', 'class' : 'mceWrapper' + opt},
\r
106 ['div', {id : id + '_top', 'class' : 'mceTop'},
\r
107 ['div', {'class' : 'mceLeft'}],
\r
108 ['div', {'class' : 'mceCenter'}],
\r
109 ['div', {'class' : 'mceRight'}],
\r
110 ['span', {id : id + '_title'}, f.title || '']
\r
113 ['div', {id : id + '_middle', 'class' : 'mceMiddle'},
\r
114 ['div', {id : id + '_left', 'class' : 'mceLeft'}],
\r
115 ['span', {id : id + '_content'}],
\r
116 ['div', {id : id + '_right', 'class' : 'mceRight'}]
\r
119 ['div', {id : id + '_bottom', 'class' : 'mceBottom'},
\r
120 ['div', {'class' : 'mceLeft'}],
\r
121 ['div', {'class' : 'mceCenter'}],
\r
122 ['div', {'class' : 'mceRight'}],
\r
123 ['span', {id : id + '_status'}, 'Content']
\r
126 ['a', {'class' : 'mceMove', tabindex : '-1', href : 'javascript:;'}],
\r
127 ['a', {'class' : 'mceMin', tabindex : '-1', href : 'javascript:;', onmousedown : 'return false;'}],
\r
128 ['a', {'class' : 'mceMax', tabindex : '-1', href : 'javascript:;', onmousedown : 'return false;'}],
\r
129 ['a', {'class' : 'mceMed', tabindex : '-1', href : 'javascript:;', onmousedown : 'return false;'}],
\r
130 ['a', {'class' : 'mceClose', tabindex : '-1', href : 'javascript:;', onmousedown : 'return false;'}],
\r
131 ['a', {id : id + '_resize_n', 'class' : 'mceResize mceResizeN', tabindex : '-1', href : 'javascript:;'}],
\r
132 ['a', {id : id + '_resize_s', 'class' : 'mceResize mceResizeS', tabindex : '-1', href : 'javascript:;'}],
\r
133 ['a', {id : id + '_resize_w', 'class' : 'mceResize mceResizeW', tabindex : '-1', href : 'javascript:;'}],
\r
134 ['a', {id : id + '_resize_e', 'class' : 'mceResize mceResizeE', tabindex : '-1', href : 'javascript:;'}],
\r
135 ['a', {id : id + '_resize_nw', 'class' : 'mceResize mceResizeNW', tabindex : '-1', href : 'javascript:;'}],
\r
136 ['a', {id : id + '_resize_ne', 'class' : 'mceResize mceResizeNE', tabindex : '-1', href : 'javascript:;'}],
\r
137 ['a', {id : id + '_resize_sw', 'class' : 'mceResize mceResizeSW', tabindex : '-1', href : 'javascript:;'}],
\r
138 ['a', {id : id + '_resize_se', 'class' : 'mceResize mceResizeSE', tabindex : '-1', href : 'javascript:;'}]
\r
143 DOM.setStyles(id, {top : -10000, left : -10000});
\r
145 // Fix gecko rendering bug, where the editors iframe messed with window contents
\r
146 if (tinymce.isGecko)
\r
147 DOM.setStyle(id, 'overflow', 'auto');
\r
151 dw += DOM.get(id + '_left').clientWidth;
\r
152 dw += DOM.get(id + '_right').clientWidth;
\r
153 dh += DOM.get(id + '_top').clientHeight;
\r
154 dh += DOM.get(id + '_bottom').clientHeight;
\r
158 DOM.setStyles(id, {top : f.top, left : f.left, width : f.width + dw, height : f.height + dh});
\r
160 u = f.url || f.file;
\r
162 if (tinymce.relaxedDomain)
\r
163 u += (u.indexOf('?') == -1 ? '?' : '&') + 'mce_rdomain=' + tinymce.relaxedDomain;
\r
165 u = tinymce._addVer(u);
\r
169 DOM.add(id + '_content', 'iframe', {id : id + '_ifr', src : 'javascript:""', frameBorder : 0, style : 'border:0;width:10px;height:10px'});
\r
170 DOM.setStyles(id + '_ifr', {width : f.width, height : f.height});
\r
171 DOM.setAttrib(id + '_ifr', 'src', u);
\r
173 DOM.add(id + '_wrapper', 'a', {id : id + '_ok', 'class' : 'mceButton mceOk', href : 'javascript:;', onmousedown : 'return false;'}, 'Ok');
\r
175 if (f.type == 'confirm')
\r
176 DOM.add(id + '_wrapper', 'a', {'class' : 'mceButton mceCancel', href : 'javascript:;', onmousedown : 'return false;'}, 'Cancel');
\r
178 DOM.add(id + '_middle', 'div', {'class' : 'mceIcon'});
\r
179 DOM.setHTML(id + '_content', f.content.replace('\n', '<br />'));
\r
183 mdf = Event.add(id, 'mousedown', function(e) {
\r
184 var n = e.target, w, vp;
\r
189 if (n.nodeName == 'A' || n.nodeName == 'a') {
\r
190 if (n.className == 'mceMax') {
\r
191 w.oldPos = w.element.getXY();
\r
192 w.oldSize = w.element.getSize();
\r
194 vp = DOM.getViewPort();
\r
196 // Reduce viewport size to avoid scrollbars
\r
200 w.element.moveTo(vp.x, vp.y);
\r
201 w.element.resizeTo(vp.w, vp.h);
\r
202 DOM.setStyles(id + '_ifr', {width : vp.w - w.deltaWidth, height : vp.h - w.deltaHeight});
\r
203 DOM.addClass(id + '_wrapper', 'mceMaximized');
\r
204 } else if (n.className == 'mceMed') {
\r
205 // Reset to old size
\r
206 w.element.moveTo(w.oldPos.x, w.oldPos.y);
\r
207 w.element.resizeTo(w.oldSize.w, w.oldSize.h);
\r
208 w.iframeElement.resizeTo(w.oldSize.w - w.deltaWidth, w.oldSize.h - w.deltaHeight);
\r
210 DOM.removeClass(id + '_wrapper', 'mceMaximized');
\r
211 } else if (n.className == 'mceMove')
\r
212 return t._startDrag(id, e, n.className);
\r
213 else if (DOM.hasClass(n, 'mceResize'))
\r
214 return t._startDrag(id, e, n.className.substring(13));
\r
218 clf = Event.add(id, 'click', function(e) {
\r
223 if (n.nodeName == 'A' || n.nodeName == 'a') {
\r
224 switch (n.className) {
\r
227 return Event.cancel(e);
\r
229 case 'mceButton mceOk':
\r
230 case 'mceButton mceCancel':
\r
231 f.button_func(n.className == 'mceButton mceOk');
\r
232 return Event.cancel(e);
\r
238 w = t.windows[id] = {
\r
240 mousedown_func : mdf,
\r
242 element : new Element(id, {blocker : 1, container : ed.getContainer()}),
\r
243 iframeElement : new Element(id + '_ifr'),
\r
249 w.iframeElement.on('focus', function() {
\r
254 if (t.count == 0 && t.editor.getParam('dialog_type', 'modal') == 'modal') {
\r
255 DOM.add(DOM.doc.body, 'div', {
\r
256 id : 'mceModalBlocker',
\r
257 'class' : (t.editor.settings.inlinepopups_skin || 'clearlooks2') + '_modalBlocker',
\r
258 style : {zIndex : t.zIndex - 1}
\r
261 DOM.show('mceModalBlocker'); // Reduces flicker in IE
\r
263 DOM.setStyle('mceModalBlocker', 'z-index', t.zIndex - 1);
\r
265 if (tinymce.isIE6 || /Firefox\/2\./.test(navigator.userAgent) || (tinymce.isIE && !DOM.boxModel))
\r
266 DOM.setStyles('mceModalBlocker', {position : 'absolute', width : vp.w - 2, height : vp.h - 2});
\r
269 t._fixIELayout(id, 1);
\r
272 if (DOM.get(id + '_ok'))
\r
273 DOM.get(id + '_ok').focus();
\r
280 focus : function(id) {
\r
283 if (w = t.windows[id]) {
\r
284 w.zIndex = this.zIndex++;
\r
285 w.element.setStyle('zIndex', w.zIndex);
\r
286 w.element.update();
\r
288 id = id + '_wrapper';
\r
289 DOM.removeClass(t.lastId, 'mceFocus');
\r
290 DOM.addClass(id, 'mceFocus');
\r
295 _addAll : function(te, ne) {
\r
296 var i, n, t = this, dom = tinymce.DOM;
\r
298 if (is(ne, 'string'))
\r
299 te.appendChild(dom.doc.createTextNode(ne));
\r
300 else if (ne.length) {
\r
301 te = te.appendChild(dom.create(ne[0], ne[1]));
\r
303 for (i=2; i<ne.length; i++)
\r
304 t._addAll(te, ne[i]);
\r
308 _startDrag : function(id, se, ac) {
\r
309 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;
\r
311 // Get positons and sizes
\r
312 // cp = DOM.getPos(t.editor.getContainer());
\r
313 cp = {x : 0, y : 0};
\r
314 vp = DOM.getViewPort();
\r
316 // Reduce viewport size to avoid scrollbars while dragging
\r
322 dx = dy = dw = dh = 0;
\r
325 mu = Event.add(d, 'mouseup', function(e) {
\r
326 Event.remove(d, 'mouseup', mu);
\r
327 Event.remove(d, 'mousemove', mm);
\r
333 we.resizeBy(dw, dh);
\r
335 DOM.setStyles(id + '_ifr', {width : sz.w - w.deltaWidth, height : sz.h - w.deltaHeight});
\r
336 t._fixIELayout(id, 1);
\r
338 return Event.cancel(e);
\r
344 function startMove() {
\r
348 t._fixIELayout(id, 0);
\r
350 // Setup event blocker
\r
351 DOM.add(d.body, 'div', {
\r
352 id : 'mceEventBlocker',
\r
353 'class' : 'mceEventBlocker ' + (t.editor.settings.inlinepopups_skin || 'clearlooks2'),
\r
354 style : {zIndex : t.zIndex + 1}
\r
357 if (tinymce.isIE6 || (tinymce.isIE && !DOM.boxModel))
\r
358 DOM.setStyles('mceEventBlocker', {position : 'absolute', width : vp.w - 2, height : vp.h - 2});
\r
360 eb = new Element('mceEventBlocker');
\r
363 // Setup placeholder
\r
366 sx = cp.x + p.x - vp.x;
\r
367 sy = cp.y + p.y - vp.y;
\r
368 DOM.add(eb.get(), 'div', {id : 'mcePlaceHolder', 'class' : 'mcePlaceHolder', style : {left : sx, top : sy, width : sz.w, height : sz.h}});
\r
369 ph = new Element('mcePlaceHolder');
\r
372 // Handle mouse move/drag
\r
373 mm = Event.add(d, 'mousemove', function(e) {
\r
378 x = e.screenX - sex;
\r
379 y = e.screenY - sey;
\r
394 if (ac == "ResizeNW") {
\r
397 } else if (ac == "ResizeNE")
\r
407 if (ac == "ResizeSW") {
\r
410 } else if (ac == "ResizeSE")
\r
423 if (dw < (v = w.features.min_width - sz.w)) {
\r
430 if (dh < (v = w.features.min_height - sz.h)) {
\r
437 dw = Math.min(dw, w.features.max_width - sz.w);
\r
438 dh = Math.min(dh, w.features.max_height - sz.h);
\r
439 dx = Math.max(dx, vp.x - (sx + vp.x));
\r
440 dy = Math.max(dy, vp.y - (sy + vp.y));
\r
441 dx = Math.min(dx, (vp.w + vp.x) - (sx + sz.w + vp.x));
\r
442 dy = Math.min(dy, (vp.h + vp.y) - (sy + sz.h + vp.y));
\r
445 if (dx + dy !== 0) {
\r
452 ph.moveTo(sx + dx, sy + dy);
\r
455 // Resize if needed
\r
457 ph.resizeTo(sz.w + dw, sz.h + dh);
\r
459 return Event.cancel(e);
\r
462 return Event.cancel(se);
\r
465 resizeBy : function(dw, dh, id) {
\r
466 var w = this.windows[id];
\r
469 w.element.resizeBy(dw, dh);
\r
470 w.iframeElement.resizeBy(dw, dh);
\r
474 close : function(win, id) {
\r
475 var t = this, w, d = DOM.doc, ix = 0, fw, id;
\r
477 id = t._findId(id || win);
\r
479 // Probably not inline
\r
480 if (!t.windows[id]) {
\r
488 DOM.remove('mceModalBlocker');
\r
490 if (w = t.windows[id]) {
\r
491 t.onClose.dispatch(t);
\r
492 Event.remove(d, 'mousedown', w.mousedownFunc);
\r
493 Event.remove(d, 'click', w.clickFunc);
\r
495 Event.clear(id + '_ifr');
\r
497 DOM.setAttrib(id + '_ifr', 'src', 'javascript:""'); // Prevent leak
\r
498 w.element.remove();
\r
499 delete t.windows[id];
\r
501 // Find front most window and focus that
\r
502 each (t.windows, function(w) {
\r
503 if (w.zIndex > ix) {
\r
514 setTitle : function(w, ti) {
\r
517 w = this._findId(w);
\r
519 if (e = DOM.get(w + '_title'))
\r
520 e.innerHTML = DOM.encode(ti);
\r
523 alert : function(txt, cb, s) {
\r
529 button_func : function(s) {
\r
531 cb.call(s || t, s);
\r
533 t.close(null, w.id);
\r
535 content : DOM.encode(t.editor.getLang(txt, txt)),
\r
542 confirm : function(txt, cb, s) {
\r
548 button_func : function(s) {
\r
550 cb.call(s || t, s);
\r
552 t.close(null, w.id);
\r
554 content : DOM.encode(t.editor.getLang(txt, txt)),
\r
561 // Internal functions
\r
563 _findId : function(w) {
\r
566 if (typeof(w) == 'string')
\r
569 each(t.windows, function(wo) {
\r
570 var ifr = DOM.get(wo.id + '_ifr');
\r
572 if (ifr && w == ifr.contentWindow) {
\r
581 _fixIELayout : function(id, s) {
\r
584 if (!tinymce.isIE6)
\r
587 // Fixes the bug where hover flickers and does odd things in IE6
\r
588 each(['n','s','w','e','nw','ne','sw','se'], function(v) {
\r
589 var e = DOM.get(id + '_resize_' + v);
\r
592 width : s ? e.clientWidth : '',
\r
593 height : s ? e.clientHeight : '',
\r
594 cursor : DOM.getStyle(e, 'cursor', 1)
\r
597 DOM.setStyle(id + "_bottom", 'bottom', '-1px');
\r
602 // Fixes graphics glitch
\r
603 if (w = this.windows[id]) {
\r
604 // Fixes rendering bug after resize
\r
608 // Forced a repaint of the window
\r
609 //DOM.get(id).style.filter = '';
\r
611 // IE has a bug where images used in CSS won't get loaded
\r
612 // sometimes when the cache in the browser is disabled
\r
613 // This fix tries to solve it by loading the images using the image object
\r
614 each(DOM.select('div,a', id), function(e, i) {
\r
615 if (e.currentStyle.backgroundImage != 'none') {
\r
617 img.src = e.currentStyle.backgroundImage.replace(/url\(\"(.+)\"\)/, '$1');
\r
621 DOM.get(id).style.filter = '';
\r
627 tinymce.PluginManager.add('inlinepopups', tinymce.plugins.InlinePopups);
\r