2 * editor_plugin_src.js
\r
4 * Copyright 2009, Moxiecode Systems AB
\r
5 * Released under LGPL License.
\r
7 * License: http://tinymce.moxiecode.com/license
\r
8 * Contributing: http://tinymce.moxiecode.com/contributing
\r
12 var DOM = tinymce.DOM, Element = tinymce.dom.Element, Event = tinymce.dom.Event, each = tinymce.each, is = tinymce.is;
\r
14 tinymce.create('tinymce.plugins.InlinePopups', {
\r
15 init : function(ed, url) {
\r
16 // Replace window manager
\r
17 ed.onBeforeRenderUI.add(function() {
\r
18 ed.windowManager = new tinymce.InlineWindowManager(ed);
\r
19 DOM.loadCSS(url + '/skins/' + (ed.settings.inlinepopups_skin || 'clearlooks2') + "/window.css");
\r
23 getInfo : function() {
\r
25 longname : 'InlinePopups',
\r
26 author : 'Moxiecode Systems AB',
\r
27 authorurl : 'http://tinymce.moxiecode.com',
\r
28 infourl : 'http://wiki.moxiecode.com/index.php/TinyMCE:Plugins/inlinepopups',
\r
29 version : tinymce.majorVersion + "." + tinymce.minorVersion
\r
34 tinymce.create('tinymce.InlineWindowManager:tinymce.WindowManager', {
\r
35 InlineWindowManager : function(ed) {
\r
44 open : function(f, p) {
\r
45 var t = this, id, opt = '', ed = t.editor, dw = 0, dh = 0, vp, po, mdf, clf, we, w, u;
\r
50 // Run native windows
\r
52 return t.parent(f, p);
\r
54 // Only store selection if the type is a normal window
\r
56 t.bookmark = ed.selection.getBookmark(1);
\r
58 id = DOM.uniqueId();
\r
59 vp = DOM.getViewPort();
\r
60 f.width = parseInt(f.width || 320);
\r
61 f.height = parseInt(f.height || 240) + (tinymce.isIE ? 8 : 0);
\r
62 f.min_width = parseInt(f.min_width || 150);
\r
63 f.min_height = parseInt(f.min_height || 100);
\r
64 f.max_width = parseInt(f.max_width || 2000);
\r
65 f.max_height = parseInt(f.max_height || 2000);
\r
66 f.left = f.left || Math.round(Math.max(vp.x, vp.x + (vp.w / 2.0) - (f.width / 2.0)));
\r
67 f.top = f.top || Math.round(Math.max(vp.y, vp.y + (vp.h / 2.0) - (f.height / 2.0)));
\r
68 f.movable = f.resizable = true;
\r
69 p.mce_width = f.width;
\r
70 p.mce_height = f.height;
\r
71 p.mce_inline = true;
\r
72 p.mce_window_id = id;
\r
73 p.mce_auto_focus = f.auto_focus;
\r
76 // po = DOM.getPos(ed.getContainer());
\r
82 t.onOpen.dispatch(t, f, p);
\r
88 opt += ' mce' + f.type.substring(0, 1).toUpperCase() + f.type.substring(1);
\r
90 f.resizable = false;
\r
94 opt += ' mceStatusbar';
\r
97 opt += ' mceResizable';
\r
100 opt += ' mceMinimizable';
\r
103 opt += ' mceMaximizable';
\r
106 opt += ' mceMovable';
\r
108 // Create DOM objects
\r
109 t._addAll(DOM.doc.body,
\r
110 ['div', {id : id, 'class' : ed.settings.inlinepopups_skin || 'clearlooks2', style : 'width:100px;height:100px'},
\r
111 ['div', {id : id + '_wrapper', 'class' : 'mceWrapper' + opt},
\r
112 ['div', {id : id + '_top', 'class' : 'mceTop'},
\r
113 ['div', {'class' : 'mceLeft'}],
\r
114 ['div', {'class' : 'mceCenter'}],
\r
115 ['div', {'class' : 'mceRight'}],
\r
116 ['span', {id : id + '_title'}, f.title || '']
\r
119 ['div', {id : id + '_middle', 'class' : 'mceMiddle'},
\r
120 ['div', {id : id + '_left', 'class' : 'mceLeft'}],
\r
121 ['span', {id : id + '_content'}],
\r
122 ['div', {id : id + '_right', 'class' : 'mceRight'}]
\r
125 ['div', {id : id + '_bottom', 'class' : 'mceBottom'},
\r
126 ['div', {'class' : 'mceLeft'}],
\r
127 ['div', {'class' : 'mceCenter'}],
\r
128 ['div', {'class' : 'mceRight'}],
\r
129 ['span', {id : id + '_status'}, 'Content']
\r
132 ['a', {'class' : 'mceMove', tabindex : '-1', href : 'javascript:;'}],
\r
133 ['a', {'class' : 'mceMin', tabindex : '-1', href : 'javascript:;', onmousedown : 'return false;'}],
\r
134 ['a', {'class' : 'mceMax', tabindex : '-1', href : 'javascript:;', onmousedown : 'return false;'}],
\r
135 ['a', {'class' : 'mceMed', tabindex : '-1', href : 'javascript:;', onmousedown : 'return false;'}],
\r
136 ['a', {'class' : 'mceClose', tabindex : '-1', href : 'javascript:;', onmousedown : 'return false;'}],
\r
137 ['a', {id : id + '_resize_n', 'class' : 'mceResize mceResizeN', tabindex : '-1', href : 'javascript:;'}],
\r
138 ['a', {id : id + '_resize_s', 'class' : 'mceResize mceResizeS', tabindex : '-1', href : 'javascript:;'}],
\r
139 ['a', {id : id + '_resize_w', 'class' : 'mceResize mceResizeW', tabindex : '-1', href : 'javascript:;'}],
\r
140 ['a', {id : id + '_resize_e', 'class' : 'mceResize mceResizeE', tabindex : '-1', href : 'javascript:;'}],
\r
141 ['a', {id : id + '_resize_nw', 'class' : 'mceResize mceResizeNW', tabindex : '-1', href : 'javascript:;'}],
\r
142 ['a', {id : id + '_resize_ne', 'class' : 'mceResize mceResizeNE', tabindex : '-1', href : 'javascript:;'}],
\r
143 ['a', {id : id + '_resize_sw', 'class' : 'mceResize mceResizeSW', tabindex : '-1', href : 'javascript:;'}],
\r
144 ['a', {id : id + '_resize_se', 'class' : 'mceResize mceResizeSE', tabindex : '-1', href : 'javascript:;'}]
\r
149 DOM.setStyles(id, {top : -10000, left : -10000});
\r
151 // Fix gecko rendering bug, where the editors iframe messed with window contents
\r
152 if (tinymce.isGecko)
\r
153 DOM.setStyle(id, 'overflow', 'auto');
\r
157 dw += DOM.get(id + '_left').clientWidth;
\r
158 dw += DOM.get(id + '_right').clientWidth;
\r
159 dh += DOM.get(id + '_top').clientHeight;
\r
160 dh += DOM.get(id + '_bottom').clientHeight;
\r
164 DOM.setStyles(id, {top : f.top, left : f.left, width : f.width + dw, height : f.height + dh});
\r
166 u = f.url || f.file;
\r
168 if (tinymce.relaxedDomain)
\r
169 u += (u.indexOf('?') == -1 ? '?' : '&') + 'mce_rdomain=' + tinymce.relaxedDomain;
\r
171 u = tinymce._addVer(u);
\r
175 DOM.add(id + '_content', 'iframe', {id : id + '_ifr', src : 'javascript:""', frameBorder : 0, style : 'border:0;width:10px;height:10px'});
\r
176 DOM.setStyles(id + '_ifr', {width : f.width, height : f.height});
\r
177 DOM.setAttrib(id + '_ifr', 'src', u);
\r
179 DOM.add(id + '_wrapper', 'a', {id : id + '_ok', 'class' : 'mceButton mceOk', href : 'javascript:;', onmousedown : 'return false;'}, 'Ok');
\r
181 if (f.type == 'confirm')
\r
182 DOM.add(id + '_wrapper', 'a', {'class' : 'mceButton mceCancel', href : 'javascript:;', onmousedown : 'return false;'}, 'Cancel');
\r
184 DOM.add(id + '_middle', 'div', {'class' : 'mceIcon'});
\r
185 DOM.setHTML(id + '_content', f.content.replace('\n', '<br />'));
\r
189 mdf = Event.add(id, 'mousedown', function(e) {
\r
190 var n = e.target, w, vp;
\r
195 if (n.nodeName == 'A' || n.nodeName == 'a') {
\r
196 if (n.className == 'mceMax') {
\r
197 w.oldPos = w.element.getXY();
\r
198 w.oldSize = w.element.getSize();
\r
200 vp = DOM.getViewPort();
\r
202 // Reduce viewport size to avoid scrollbars
\r
206 w.element.moveTo(vp.x, vp.y);
\r
207 w.element.resizeTo(vp.w, vp.h);
\r
208 DOM.setStyles(id + '_ifr', {width : vp.w - w.deltaWidth, height : vp.h - w.deltaHeight});
\r
209 DOM.addClass(id + '_wrapper', 'mceMaximized');
\r
210 } else if (n.className == 'mceMed') {
\r
211 // Reset to old size
\r
212 w.element.moveTo(w.oldPos.x, w.oldPos.y);
\r
213 w.element.resizeTo(w.oldSize.w, w.oldSize.h);
\r
214 w.iframeElement.resizeTo(w.oldSize.w - w.deltaWidth, w.oldSize.h - w.deltaHeight);
\r
216 DOM.removeClass(id + '_wrapper', 'mceMaximized');
\r
217 } else if (n.className == 'mceMove')
\r
218 return t._startDrag(id, e, n.className);
\r
219 else if (DOM.hasClass(n, 'mceResize'))
\r
220 return t._startDrag(id, e, n.className.substring(13));
\r
224 clf = Event.add(id, 'click', function(e) {
\r
229 if (n.nodeName == 'A' || n.nodeName == 'a') {
\r
230 switch (n.className) {
\r
233 return Event.cancel(e);
\r
235 case 'mceButton mceOk':
\r
236 case 'mceButton mceCancel':
\r
237 f.button_func(n.className == 'mceButton mceOk');
\r
238 return Event.cancel(e);
\r
244 w = t.windows[id] = {
\r
246 mousedown_func : mdf,
\r
248 element : new Element(id, {blocker : 1, container : ed.getContainer()}),
\r
249 iframeElement : new Element(id + '_ifr'),
\r
255 w.iframeElement.on('focus', function() {
\r
260 if (t.count == 0 && t.editor.getParam('dialog_type', 'modal') == 'modal') {
\r
261 DOM.add(DOM.doc.body, 'div', {
\r
262 id : 'mceModalBlocker',
\r
263 'class' : (t.editor.settings.inlinepopups_skin || 'clearlooks2') + '_modalBlocker',
\r
264 style : {zIndex : t.zIndex - 1}
\r
267 DOM.show('mceModalBlocker'); // Reduces flicker in IE
\r
269 DOM.setStyle('mceModalBlocker', 'z-index', t.zIndex - 1);
\r
271 if (tinymce.isIE6 || /Firefox\/2\./.test(navigator.userAgent) || (tinymce.isIE && !DOM.boxModel))
\r
272 DOM.setStyles('mceModalBlocker', {position : 'absolute', left : vp.x, top : vp.y, width : vp.w - 2, height : vp.h - 2});
\r
275 t._fixIELayout(id, 1);
\r
278 if (DOM.get(id + '_ok'))
\r
279 DOM.get(id + '_ok').focus();
\r
286 focus : function(id) {
\r
289 if (w = t.windows[id]) {
\r
290 w.zIndex = this.zIndex++;
\r
291 w.element.setStyle('zIndex', w.zIndex);
\r
292 w.element.update();
\r
294 id = id + '_wrapper';
\r
295 DOM.removeClass(t.lastId, 'mceFocus');
\r
296 DOM.addClass(id, 'mceFocus');
\r
301 _addAll : function(te, ne) {
\r
302 var i, n, t = this, dom = tinymce.DOM;
\r
304 if (is(ne, 'string'))
\r
305 te.appendChild(dom.doc.createTextNode(ne));
\r
306 else if (ne.length) {
\r
307 te = te.appendChild(dom.create(ne[0], ne[1]));
\r
309 for (i=2; i<ne.length; i++)
\r
310 t._addAll(te, ne[i]);
\r
314 _startDrag : function(id, se, ac) {
\r
315 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
317 // Get positons and sizes
\r
318 // cp = DOM.getPos(t.editor.getContainer());
\r
319 cp = {x : 0, y : 0};
\r
320 vp = DOM.getViewPort();
\r
322 // Reduce viewport size to avoid scrollbars while dragging
\r
328 dx = dy = dw = dh = 0;
\r
331 mu = Event.add(d, 'mouseup', function(e) {
\r
332 Event.remove(d, 'mouseup', mu);
\r
333 Event.remove(d, 'mousemove', mm);
\r
339 we.resizeBy(dw, dh);
\r
341 DOM.setStyles(id + '_ifr', {width : sz.w - w.deltaWidth, height : sz.h - w.deltaHeight});
\r
342 t._fixIELayout(id, 1);
\r
344 return Event.cancel(e);
\r
350 function startMove() {
\r
354 t._fixIELayout(id, 0);
\r
356 // Setup event blocker
\r
357 DOM.add(d.body, 'div', {
\r
358 id : 'mceEventBlocker',
\r
359 'class' : 'mceEventBlocker ' + (t.editor.settings.inlinepopups_skin || 'clearlooks2'),
\r
360 style : {zIndex : t.zIndex + 1}
\r
363 if (tinymce.isIE6 || (tinymce.isIE && !DOM.boxModel))
\r
364 DOM.setStyles('mceEventBlocker', {position : 'absolute', left : vp.x, top : vp.y, width : vp.w - 2, height : vp.h - 2});
\r
366 eb = new Element('mceEventBlocker');
\r
369 // Setup placeholder
\r
372 sx = cp.x + p.x - vp.x;
\r
373 sy = cp.y + p.y - vp.y;
\r
374 DOM.add(eb.get(), 'div', {id : 'mcePlaceHolder', 'class' : 'mcePlaceHolder', style : {left : sx, top : sy, width : sz.w, height : sz.h}});
\r
375 ph = new Element('mcePlaceHolder');
\r
378 // Handle mouse move/drag
\r
379 mm = Event.add(d, 'mousemove', function(e) {
\r
384 x = e.screenX - sex;
\r
385 y = e.screenY - sey;
\r
400 if (ac == "ResizeNW") {
\r
403 } else if (ac == "ResizeNE")
\r
413 if (ac == "ResizeSW") {
\r
416 } else if (ac == "ResizeSE")
\r
429 if (dw < (v = w.features.min_width - sz.w)) {
\r
436 if (dh < (v = w.features.min_height - sz.h)) {
\r
443 dw = Math.min(dw, w.features.max_width - sz.w);
\r
444 dh = Math.min(dh, w.features.max_height - sz.h);
\r
445 dx = Math.max(dx, vp.x - (sx + vp.x));
\r
446 dy = Math.max(dy, vp.y - (sy + vp.y));
\r
447 dx = Math.min(dx, (vp.w + vp.x) - (sx + sz.w + vp.x));
\r
448 dy = Math.min(dy, (vp.h + vp.y) - (sy + sz.h + vp.y));
\r
451 if (dx + dy !== 0) {
\r
458 ph.moveTo(sx + dx, sy + dy);
\r
461 // Resize if needed
\r
463 ph.resizeTo(sz.w + dw, sz.h + dh);
\r
465 return Event.cancel(e);
\r
468 return Event.cancel(se);
\r
471 resizeBy : function(dw, dh, id) {
\r
472 var w = this.windows[id];
\r
475 w.element.resizeBy(dw, dh);
\r
476 w.iframeElement.resizeBy(dw, dh);
\r
480 close : function(win, id) {
\r
481 var t = this, w, d = DOM.doc, ix = 0, fw, id;
\r
483 id = t._findId(id || win);
\r
485 // Probably not inline
\r
486 if (!t.windows[id]) {
\r
494 DOM.remove('mceModalBlocker');
\r
496 if (w = t.windows[id]) {
\r
497 t.onClose.dispatch(t);
\r
498 Event.remove(d, 'mousedown', w.mousedownFunc);
\r
499 Event.remove(d, 'click', w.clickFunc);
\r
501 Event.clear(id + '_ifr');
\r
503 DOM.setAttrib(id + '_ifr', 'src', 'javascript:""'); // Prevent leak
\r
504 w.element.remove();
\r
505 delete t.windows[id];
\r
507 // Find front most window and focus that
\r
508 each (t.windows, function(w) {
\r
509 if (w.zIndex > ix) {
\r
520 setTitle : function(w, ti) {
\r
523 w = this._findId(w);
\r
525 if (e = DOM.get(w + '_title'))
\r
526 e.innerHTML = DOM.encode(ti);
\r
529 alert : function(txt, cb, s) {
\r
535 button_func : function(s) {
\r
537 cb.call(s || t, s);
\r
539 t.close(null, w.id);
\r
541 content : DOM.encode(t.editor.getLang(txt, txt)),
\r
548 confirm : function(txt, cb, s) {
\r
554 button_func : function(s) {
\r
556 cb.call(s || t, s);
\r
558 t.close(null, w.id);
\r
560 content : DOM.encode(t.editor.getLang(txt, txt)),
\r
567 // Internal functions
\r
569 _findId : function(w) {
\r
572 if (typeof(w) == 'string')
\r
575 each(t.windows, function(wo) {
\r
576 var ifr = DOM.get(wo.id + '_ifr');
\r
578 if (ifr && w == ifr.contentWindow) {
\r
587 _fixIELayout : function(id, s) {
\r
590 if (!tinymce.isIE6)
\r
593 // Fixes the bug where hover flickers and does odd things in IE6
\r
594 each(['n','s','w','e','nw','ne','sw','se'], function(v) {
\r
595 var e = DOM.get(id + '_resize_' + v);
\r
598 width : s ? e.clientWidth : '',
\r
599 height : s ? e.clientHeight : '',
\r
600 cursor : DOM.getStyle(e, 'cursor', 1)
\r
603 DOM.setStyle(id + "_bottom", 'bottom', '-1px');
\r
608 // Fixes graphics glitch
\r
609 if (w = this.windows[id]) {
\r
610 // Fixes rendering bug after resize
\r
614 // Forced a repaint of the window
\r
615 //DOM.get(id).style.filter = '';
\r
617 // IE has a bug where images used in CSS won't get loaded
\r
618 // sometimes when the cache in the browser is disabled
\r
619 // This fix tries to solve it by loading the images using the image object
\r
620 each(DOM.select('div,a', id), function(e, i) {
\r
621 if (e.currentStyle.backgroundImage != 'none') {
\r
623 img.src = e.currentStyle.backgroundImage.replace(/url\(\"(.+)\"\)/, '$1');
\r
627 DOM.get(id).style.filter = '';
\r
633 tinymce.PluginManager.add('inlinepopups', tinymce.plugins.InlinePopups);
\r