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