2 * $Id: editor_plugin_src.js 776 2008-04-08 17:00:39Z 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
40 open : function(f, p) {
\r
41 var t = this, id, opt = '', ed = t.editor, dw = 0, dh = 0, vp, po, mdf, clf, we, w, u;
\r
46 // Run native windows
\r
48 return t.parent(f, p);
\r
50 // Only store selection if the type is a normal window
\r
52 t.bookmark = ed.selection.getBookmark('simple');
\r
54 id = DOM.uniqueId();
\r
55 vp = DOM.getViewPort();
\r
56 f.width = parseInt(f.width || 320);
\r
57 f.height = parseInt(f.height || 240) + (tinymce.isIE ? 8 : 0);
\r
58 f.min_width = parseInt(f.min_width || 150);
\r
59 f.min_height = parseInt(f.min_height || 100);
\r
60 f.max_width = parseInt(f.max_width || 2000);
\r
61 f.max_height = parseInt(f.max_height || 2000);
\r
62 f.left = f.left || Math.round(Math.max(vp.x, vp.x + (vp.w / 2.0) - (f.width / 2.0)));
\r
63 f.top = f.top || Math.round(Math.max(vp.y, vp.y + (vp.h / 2.0) - (f.height / 2.0)));
\r
64 f.movable = f.resizable = true;
\r
65 p.mce_width = f.width;
\r
66 p.mce_height = f.height;
\r
67 p.mce_inline = true;
\r
68 p.mce_window_id = id;
\r
69 p.mce_auto_focus = f.auto_focus;
\r
72 // po = DOM.getPos(ed.getContainer());
\r
78 t.onOpen.dispatch(t, f, p);
\r
84 opt += ' mce' + f.type.substring(0, 1).toUpperCase() + f.type.substring(1);
\r
86 f.resizable = false;
\r
90 opt += ' mceStatusbar';
\r
93 opt += ' mceResizable';
\r
96 opt += ' mceMinimizable';
\r
99 opt += ' mceMaximizable';
\r
102 opt += ' mceMovable';
\r
104 // Create DOM objects
\r
105 t._addAll(DOM.doc.body,
\r
106 ['div', {id : id, 'class' : ed.settings.inlinepopups_skin || 'clearlooks2', style : 'width:100px;height:100px'},
\r
107 ['div', {id : id + '_wrapper', 'class' : 'mceWrapper' + opt},
\r
108 ['div', {id : id + '_top', 'class' : 'mceTop'},
\r
109 ['div', {'class' : 'mceLeft'}],
\r
110 ['div', {'class' : 'mceCenter'}],
\r
111 ['div', {'class' : 'mceRight'}],
\r
112 ['span', {id : id + '_title'}, f.title || '']
\r
115 ['div', {id : id + '_middle', 'class' : 'mceMiddle'},
\r
116 ['div', {id : id + '_left', 'class' : 'mceLeft'}],
\r
117 ['span', {id : id + '_content'}],
\r
118 ['div', {id : id + '_right', 'class' : 'mceRight'}]
\r
121 ['div', {id : id + '_bottom', 'class' : 'mceBottom'},
\r
122 ['div', {'class' : 'mceLeft'}],
\r
123 ['div', {'class' : 'mceCenter'}],
\r
124 ['div', {'class' : 'mceRight'}],
\r
125 ['span', {id : id + '_status'}, 'Content']
\r
128 ['a', {'class' : 'mceMove', tabindex : '-1', href : 'javascript:;'}],
\r
129 ['a', {'class' : 'mceMin', tabindex : '-1', href : 'javascript:;', onmousedown : 'return false;'}],
\r
130 ['a', {'class' : 'mceMax', tabindex : '-1', href : 'javascript:;', onmousedown : 'return false;'}],
\r
131 ['a', {'class' : 'mceMed', tabindex : '-1', href : 'javascript:;', onmousedown : 'return false;'}],
\r
132 ['a', {'class' : 'mceClose', tabindex : '-1', href : 'javascript:;', onmousedown : 'return false;'}],
\r
133 ['a', {id : id + '_resize_n', 'class' : 'mceResize mceResizeN', tabindex : '-1', href : 'javascript:;'}],
\r
134 ['a', {id : id + '_resize_s', 'class' : 'mceResize mceResizeS', tabindex : '-1', href : 'javascript:;'}],
\r
135 ['a', {id : id + '_resize_w', 'class' : 'mceResize mceResizeW', tabindex : '-1', href : 'javascript:;'}],
\r
136 ['a', {id : id + '_resize_e', 'class' : 'mceResize mceResizeE', tabindex : '-1', href : 'javascript:;'}],
\r
137 ['a', {id : id + '_resize_nw', 'class' : 'mceResize mceResizeNW', tabindex : '-1', href : 'javascript:;'}],
\r
138 ['a', {id : id + '_resize_ne', 'class' : 'mceResize mceResizeNE', tabindex : '-1', href : 'javascript:;'}],
\r
139 ['a', {id : id + '_resize_sw', 'class' : 'mceResize mceResizeSW', tabindex : '-1', href : 'javascript:;'}],
\r
140 ['a', {id : id + '_resize_se', 'class' : 'mceResize mceResizeSE', tabindex : '-1', href : 'javascript:;'}]
\r
145 DOM.setStyles(id, {top : -10000, left : -10000});
\r
147 // Fix gecko rendering bug, where the editors iframe messed with window contents
\r
148 if (tinymce.isGecko)
\r
149 DOM.setStyle(id, 'overflow', 'auto');
\r
153 dw += DOM.get(id + '_left').clientWidth;
\r
154 dw += DOM.get(id + '_right').clientWidth;
\r
155 dh += DOM.get(id + '_top').clientHeight;
\r
156 dh += DOM.get(id + '_bottom').clientHeight;
\r
160 DOM.setStyles(id, {top : f.top, left : f.left, width : f.width + dw, height : f.height + dh});
\r
162 u = f.url || f.file;
\r
164 if (tinymce.relaxedDomain)
\r
165 u += (u.indexOf('?') == -1 ? '?' : '&') + 'mce_rdomain=' + tinymce.relaxedDomain;
\r
167 u = tinymce._addVer(u);
\r
171 DOM.add(id + '_content', 'iframe', {id : id + '_ifr', src : 'javascript:""', frameBorder : 0, style : 'border:0;width:10px;height:10px'});
\r
172 DOM.setStyles(id + '_ifr', {width : f.width, height : f.height});
\r
173 DOM.setAttrib(id + '_ifr', 'src', u);
\r
175 DOM.add(id + '_wrapper', 'a', {id : id + '_ok', 'class' : 'mceButton mceOk', href : 'javascript:;', onmousedown : 'return false;'}, 'Ok');
\r
177 if (f.type == 'confirm')
\r
178 DOM.add(id + '_wrapper', 'a', {'class' : 'mceButton mceCancel', href : 'javascript:;', onmousedown : 'return false;'}, 'Cancel');
\r
180 DOM.add(id + '_middle', 'div', {'class' : 'mceIcon'});
\r
181 DOM.setHTML(id + '_content', f.content.replace('\n', '<br />'));
\r
185 mdf = Event.add(id, 'mousedown', function(e) {
\r
186 var n = e.target, w, vp;
\r
191 if (n.nodeName == 'A' || n.nodeName == 'a') {
\r
192 if (n.className == 'mceMax') {
\r
193 w.oldPos = w.element.getXY();
\r
194 w.oldSize = w.element.getSize();
\r
196 vp = DOM.getViewPort();
\r
198 // Reduce viewport size to avoid scrollbars
\r
202 w.element.moveTo(vp.x, vp.y);
\r
203 w.element.resizeTo(vp.w, vp.h);
\r
204 DOM.setStyles(id + '_ifr', {width : vp.w - w.deltaWidth, height : vp.h - w.deltaHeight});
\r
205 DOM.addClass(id + '_wrapper', 'mceMaximized');
\r
206 } else if (n.className == 'mceMed') {
\r
207 // Reset to old size
\r
208 w.element.moveTo(w.oldPos.x, w.oldPos.y);
\r
209 w.element.resizeTo(w.oldSize.w, w.oldSize.h);
\r
210 w.iframeElement.resizeTo(w.oldSize.w - w.deltaWidth, w.oldSize.h - w.deltaHeight);
\r
212 DOM.removeClass(id + '_wrapper', 'mceMaximized');
\r
213 } else if (n.className == 'mceMove')
\r
214 return t._startDrag(id, e, n.className);
\r
215 else if (DOM.hasClass(n, 'mceResize'))
\r
216 return t._startDrag(id, e, n.className.substring(13));
\r
220 clf = Event.add(id, 'click', function(e) {
\r
225 if (n.nodeName == 'A' || n.nodeName == 'a') {
\r
226 switch (n.className) {
\r
229 return Event.cancel(e);
\r
231 case 'mceButton mceOk':
\r
232 case 'mceButton mceCancel':
\r
233 f.button_func(n.className == 'mceButton mceOk');
\r
234 return Event.cancel(e);
\r
240 t.windows = t.windows || {};
\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') {
\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 : {left : vp.x, top : vp.y, zIndex : t.zIndex - 1}
\r
264 DOM.show('mceModalBlocker'); // Reduces flicker in IE
\r
266 DOM.setStyle('mceModalBlocker', 'z-index', t.zIndex - 1);
\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
281 var t = this, w = t.windows[id];
\r
283 w.zIndex = this.zIndex++;
\r
284 w.element.setStyle('zIndex', w.zIndex);
\r
285 w.element.update();
\r
287 id = id + '_wrapper';
\r
288 DOM.removeClass(t.lastId, 'mceFocus');
\r
289 DOM.addClass(id, 'mceFocus');
\r
293 _addAll : function(te, ne) {
\r
294 var i, n, t = this, dom = tinymce.DOM;
\r
296 if (is(ne, 'string'))
\r
297 te.appendChild(dom.doc.createTextNode(ne));
\r
298 else if (ne.length) {
\r
299 te = te.appendChild(dom.create(ne[0], ne[1]));
\r
301 for (i=2; i<ne.length; i++)
\r
302 t._addAll(te, ne[i]);
\r
306 _startDrag : function(id, se, ac) {
\r
307 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
309 // Get positons and sizes
\r
310 // cp = DOM.getPos(t.editor.getContainer());
\r
311 cp = {x : 0, y : 0};
\r
312 vp = DOM.getViewPort();
\r
314 // Reduce viewport size to avoid scrollbars while dragging
\r
320 dx = dy = dw = dh = 0;
\r
323 mu = Event.add(d, 'mouseup', function(e) {
\r
324 Event.remove(d, 'mouseup', mu);
\r
325 Event.remove(d, 'mousemove', mm);
\r
331 we.resizeBy(dw, dh);
\r
333 DOM.setStyles(id + '_ifr', {width : sz.w - w.deltaWidth, height : sz.h - w.deltaHeight});
\r
334 t._fixIELayout(id, 1);
\r
336 return Event.cancel(e);
\r
342 function startMove() {
\r
346 t._fixIELayout(id, 0);
\r
348 // Setup event blocker
\r
349 DOM.add(d.body, 'div', {
\r
350 id : 'mceEventBlocker',
\r
351 'class' : 'mceEventBlocker ' + (t.editor.settings.inlinepopups_skin || 'clearlooks2'),
\r
352 style : {left : vp.x, top : vp.y, zIndex : t.zIndex + 1}
\r
354 eb = new Element('mceEventBlocker');
\r
357 // Setup placeholder
\r
360 sx = cp.x + p.x - vp.x;
\r
361 sy = cp.y + p.y - vp.y;
\r
362 DOM.add(eb.get(), 'div', {id : 'mcePlaceHolder', 'class' : 'mcePlaceHolder', style : {left : sx, top : sy, width : sz.w, height : sz.h}});
\r
363 ph = new Element('mcePlaceHolder');
\r
366 // Handle mouse move/drag
\r
367 mm = Event.add(d, 'mousemove', function(e) {
\r
372 x = e.screenX - sex;
\r
373 y = e.screenY - sey;
\r
388 if (ac == "ResizeNW") {
\r
391 } else if (ac == "ResizeNE")
\r
401 if (ac == "ResizeSW") {
\r
404 } else if (ac == "ResizeSE")
\r
417 if (dw < (v = w.features.min_width - sz.w)) {
\r
424 if (dh < (v = w.features.min_height - sz.h)) {
\r
431 dw = Math.min(dw, w.features.max_width - sz.w);
\r
432 dh = Math.min(dh, w.features.max_height - sz.h);
\r
433 dx = Math.max(dx, vp.x - (sx + vp.x));
\r
434 dy = Math.max(dy, vp.y - (sy + vp.y));
\r
435 dx = Math.min(dx, (vp.w + vp.x) - (sx + sz.w + vp.x));
\r
436 dy = Math.min(dy, (vp.h + vp.y) - (sy + sz.h + vp.y));
\r
439 if (dx + dy !== 0) {
\r
446 ph.moveTo(sx + dx, sy + dy);
\r
449 // Resize if needed
\r
451 ph.resizeTo(sz.w + dw, sz.h + dh);
\r
453 return Event.cancel(e);
\r
456 return Event.cancel(se);
\r
459 resizeBy : function(dw, dh, id) {
\r
460 var w = this.windows[id];
\r
463 w.element.resizeBy(dw, dh);
\r
464 w.iframeElement.resizeBy(dw, dh);
\r
468 close : function(win, id) {
\r
469 var t = this, w, d = DOM.doc, ix = 0, fw;
\r
474 DOM.remove('mceModalBlocker');
\r
476 // Probably not inline
\r
482 if (w = t.windows[id]) {
\r
483 t.onClose.dispatch(t);
\r
484 Event.remove(d, 'mousedown', w.mousedownFunc);
\r
485 Event.remove(d, 'click', w.clickFunc);
\r
487 Event.clear(id + '_ifr');
\r
489 DOM.setAttrib(id + '_ifr', 'src', 'javascript:""'); // Prevent leak
\r
490 w.element.remove();
\r
491 delete t.windows[id];
\r
493 // Find front most window and focus that
\r
494 each (t.windows, function(w) {
\r
495 if (w.zIndex > ix) {
\r
506 setTitle : function(ti, id) {
\r
509 if (e = DOM.get(id + '_title'))
\r
510 e.innerHTML = DOM.encode(ti);
\r
513 alert : function(txt, cb, s) {
\r
519 button_func : function(s) {
\r
521 cb.call(s || t, s);
\r
523 t.close(null, w.id);
\r
525 content : DOM.encode(t.editor.getLang(txt, txt)),
\r
532 confirm : function(txt, cb, s) {
\r
538 button_func : function(s) {
\r
540 cb.call(s || t, s);
\r
542 t.close(null, w.id);
\r
544 content : DOM.encode(t.editor.getLang(txt, txt)),
\r
551 // Internal functions
\r
553 _fixIELayout : function(id, s) {
\r
556 if (!tinymce.isIE6)
\r
559 // Fixes the bug where hover flickers and does odd things in IE6
\r
560 each(['n','s','w','e','nw','ne','sw','se'], function(v) {
\r
561 var e = DOM.get(id + '_resize_' + v);
\r
564 width : s ? e.clientWidth : '',
\r
565 height : s ? e.clientHeight : '',
\r
566 cursor : DOM.getStyle(e, 'cursor', 1)
\r
569 DOM.setStyle(id + "_bottom", 'bottom', '-1px');
\r
574 // Fixes graphics glitch
\r
575 if (w = this.windows[id]) {
\r
576 // Fixes rendering bug after resize
\r
580 // Forced a repaint of the window
\r
581 //DOM.get(id).style.filter = '';
\r
583 // IE has a bug where images used in CSS won't get loaded
\r
584 // sometimes when the cache in the browser is disabled
\r
585 // This fix tries to solve it by loading the images using the image object
\r
586 each(DOM.select('div,a', id), function(e, i) {
\r
587 if (e.currentStyle.backgroundImage != 'none') {
\r
589 img.src = e.currentStyle.backgroundImage.replace(/url\(\"(.+)\"\)/, '$1');
\r
593 DOM.get(id).style.filter = '';
\r
599 tinymce.PluginManager.add('inlinepopups', tinymce.plugins.InlinePopups);
\r