source: branches/rsr.v5.1/web/app/plugins/tinymce/jscripts/tiny_mce/plugins/inlinepopups/editor_plugin_src.js @ 1

Last change on this file since 1 was 1, checked in by dj3c1t, 12 years ago

import initial

File size: 14.9 KB
Line 
1/**
2 * $Id: editor_plugin_src.js 520 2008-01-07 16:30:32Z spocke $
3 *
4 * @author Moxiecode
5 * @copyright Copyright © 2004-2008, Moxiecode Systems AB, All rights reserved.
6 */
7
8(function() {
9        var DOM = tinymce.DOM, Element = tinymce.dom.Element, Event = tinymce.dom.Event, each = tinymce.each, is = tinymce.is;
10
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");
17                        });
18                },
19
20                getInfo : function() {
21                        return {
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
27                        };
28                }
29        });
30
31        tinymce.create('tinymce.InlineWindowManager:tinymce.WindowManager', {
32                InlineWindowManager : function(ed) {
33                        var t = this;
34
35                        t.parent(ed);
36                        t.zIndex = 1000;
37                },
38
39                open : function(f, p) {
40                        var t = this, id, opt = '', ed = t.editor, dw = 0, dh = 0, vp, po, mdf, clf, we, w;
41
42                        f = f || {};
43                        p = p || {};
44
45                        // Run native windows
46                        if (!f.inline)
47                                return t.parent(f, p);
48
49                        t.bookmark = ed.selection.getBookmark('simple');
50                        id = DOM.uniqueId();
51                        vp = DOM.getViewPort();
52                        f.width = parseInt(f.width || 320);
53                        f.height = parseInt(f.height || 240) + (tinymce.isIE ? 8 : 0);
54                        f.min_width = parseInt(f.min_width || 150);
55                        f.min_height = parseInt(f.min_height || 100);
56                        f.max_width = parseInt(f.max_width || 2000);
57                        f.max_height = parseInt(f.max_height || 2000);
58                        f.left = f.left || Math.round(Math.max(vp.x, vp.x + (vp.w / 2.0) - (f.width / 2.0)));
59                        f.top = f.top || Math.round(Math.max(vp.y, vp.y + (vp.h / 2.0) - (f.height / 2.0)));
60                        f.movable = f.resizable = true;
61                        p.mce_width = f.width;
62                        p.mce_height = f.height;
63                        p.mce_inline = true;
64                        p.mce_window_id = id;
65
66                        // Transpose
67//                      po = DOM.getPos(ed.getContainer());
68//                      f.left -= po.x;
69//                      f.top -= po.y;
70
71                        t.features = f;
72                        t.params = p;
73                        t.onOpen.dispatch(t, f, p);
74
75                        if (f.type) {
76                                opt += ' modal ' + f.type;
77                                f.resizable = false;
78                        }
79
80                        if (f.statusbar)
81                                opt += ' statusbar';
82
83                        if (f.resizable)
84                                opt += ' resizable';
85
86                        if (f.minimizable)
87                                opt += ' minimizable';
88
89                        if (f.maximizable)
90                                opt += ' maximizable';
91
92                        if (f.movable)
93                                opt += ' movable';
94
95                        // Create DOM objects
96                        t._addAll(document.body, 
97                                ['div', {id : id, 'class' : ed.settings.inlinepopups_skin || 'clearlooks2', style : 'width:100px;height:100px'}, 
98                                        ['div', {id : id + '_wrapper', 'class' : 'wrapper' + opt},
99                                                ['div', {id : id + '_top', 'class' : 'top'}, 
100                                                        ['div', {'class' : 'left'}],
101                                                        ['div', {'class' : 'center'}],
102                                                        ['div', {'class' : 'right'}],
103                                                        ['span', {id : id + '_title'}, f.title || '']
104                                                ],
105
106                                                ['div', {id : id + '_middle', 'class' : 'middle'}, 
107                                                        ['div', {id : id + '_left', 'class' : 'left'}],
108                                                        ['span', {id : id + '_content'}],
109                                                        ['div', {id : id + '_right', 'class' : 'right'}]
110                                                ],
111
112                                                ['div', {id : id + '_bottom', 'class' : 'bottom'},
113                                                        ['div', {'class' : 'left'}],
114                                                        ['div', {'class' : 'center'}],
115                                                        ['div', {'class' : 'right'}],
116                                                        ['span', {id : id + '_status'}, 'Content']
117                                                ],
118
119                                                ['a', {'class' : 'move', href : 'javascript:;'}],
120                                                ['a', {'class' : 'min', href : 'javascript:;', onmousedown : 'return false;'}],
121                                                ['a', {'class' : 'max', href : 'javascript:;', onmousedown : 'return false;'}],
122                                                ['a', {'class' : 'med', href : 'javascript:;', onmousedown : 'return false;'}],
123                                                ['a', {'class' : 'close', href : 'javascript:;', onmousedown : 'return false;'}],
124                                                ['a', {id : id + '_resize_n', 'class' : 'resize resize-n', href : 'javascript:;'}],
125                                                ['a', {id : id + '_resize_s', 'class' : 'resize resize-s', href : 'javascript:;'}],
126                                                ['a', {id : id + '_resize_w', 'class' : 'resize resize-w', href : 'javascript:;'}],
127                                                ['a', {id : id + '_resize_e', 'class' : 'resize resize-e', href : 'javascript:;'}],
128                                                ['a', {id : id + '_resize_nw', 'class' : 'resize resize-nw', href : 'javascript:;'}],
129                                                ['a', {id : id + '_resize_ne', 'class' : 'resize resize-ne', href : 'javascript:;'}],
130                                                ['a', {id : id + '_resize_sw', 'class' : 'resize resize-sw', href : 'javascript:;'}],
131                                                ['a', {id : id + '_resize_se', 'class' : 'resize resize-se', href : 'javascript:;'}]
132                                        ]
133                                ]
134                        );
135
136                        DOM.setStyles(id, {top : -10000, left : -10000});
137
138                        // Fix gecko rendering bug, where the editors iframe messed with window contents
139                        if (tinymce.isGecko)
140                                DOM.setStyle(id, 'overflow', 'auto');
141
142                        // Measure borders
143                        if (!f.type) {
144                                dw += DOM.get(id + '_left').clientWidth;
145                                dw += DOM.get(id + '_right').clientWidth;
146                                dh += DOM.get(id + '_top').clientHeight;
147                                dh += DOM.get(id + '_bottom').clientHeight;
148                        }
149
150                        // Resize window
151                        DOM.setStyles(id, {top : f.top, left : f.left, width : f.width + dw, height : f.height + dh});
152
153                        if (!f.type) {
154                                DOM.add(id + '_content', 'iframe', {id : id + '_ifr', src : 'javascript:""', frameBorder : 0, style : 'border:0;width:10px;height:10px'});
155                                DOM.setStyles(id + '_ifr', {width : f.width, height : f.height});
156                                DOM.setAttrib(id + '_ifr', 'src', f.url || f.file);
157                        } else {
158                                DOM.add(id + '_wrapper', 'a', {id : id + '_ok', 'class' : 'button ok', href : 'javascript:;', onmousedown : 'return false;'}, 'Ok');
159
160                                if (f.type == 'confirm')
161                                        DOM.add(id + '_wrapper', 'a', {'class' : 'button cancel', href : 'javascript:;', onmousedown : 'return false;'}, 'Cancel');
162
163                                DOM.add(id + '_middle', 'div', {'class' : 'icon'});
164                                DOM.setHTML(id + '_content', f.content.replace('\n', '<br />'));
165                        }
166
167                        // Register events
168                        mdf = Event.add(id, 'mousedown', function(e) {
169                                var n = e.target, w, vp;
170
171                                w = t.windows[id];
172                                t.focus(id);
173
174                                if (n.nodeName == 'A' || n.nodeName == 'a') {
175                                        if (n.className == 'max') {
176                                                w.oldPos = w.element.getXY();
177                                                w.oldSize = w.element.getSize();
178
179                                                vp = DOM.getViewPort();
180
181                                                // Reduce viewport size to avoid scrollbars
182                                                vp.w -= 2;
183                                                vp.h -= 2;
184
185                                                w.element.moveTo(vp.x, vp.y);
186                                                w.element.resizeTo(vp.w, vp.h);
187                                                DOM.setStyles(id + '_ifr', {width : vp.w - w.deltaWidth, height : vp.h - w.deltaHeight});
188                                                DOM.addClass(id + '_wrapper', 'maximized');
189                                        } else if (n.className == 'med') {
190                                                // Reset to old size
191                                                w.element.moveTo(w.oldPos.x, w.oldPos.y);
192                                                w.element.resizeTo(w.oldSize.w, w.oldSize.h);
193                                                w.iframeElement.resizeTo(w.oldSize.w - w.deltaWidth, w.oldSize.h - w.deltaHeight);
194
195                                                DOM.removeClass(id + '_wrapper', 'maximized');
196                                        } else if (n.className == 'move')
197                                                return t._startDrag(id, e, n.className);
198                                        else if (DOM.hasClass(n, 'resize'))
199                                                return t._startDrag(id, e, n.className.substring(7));
200                                }
201                        });
202
203                        clf = Event.add(id, 'click', function(e) {
204                                var n = e.target;
205
206                                t.focus(id);
207
208                                if (n.nodeName == 'A' || n.nodeName == 'a') {
209                                        switch (n.className) {
210                                                case 'close':
211                                                        t.close(null, id);
212                                                        return Event.cancel(e);
213
214                                                case 'button ok':
215                                                case 'button cancel':
216                                                        f.button_func(n.className == 'button ok');
217                                                        return Event.cancel(e);
218                                        }
219                                }
220                        });
221
222                        // Add window
223                        t.windows = t.windows || {};
224                        w = t.windows[id] = {
225                                id : id,
226                                mousedown_func : mdf,
227                                click_func : clf,
228                                element : new Element(id, {blocker : 1, container : ed.getContainer()}),
229                                iframeElement : new Element(id + '_ifr'),
230                                features : f,
231                                deltaWidth : dw,
232                                deltaHeight : dh
233                        };
234
235                        w.iframeElement.on('focus', function() {
236                                t.focus(id);
237                        });
238
239                        t.focus(id);
240                        t._fixIELayout(id, 1);
241
242//                      if (DOM.get(id + '_ok'))
243//                              DOM.get(id + '_ok').focus();
244
245                        return w;
246                },
247
248                focus : function(id) {
249                        var t = this, w = t.windows[id];
250
251                        w.zIndex = this.zIndex++;
252                        w.element.setStyle('zIndex', w.zIndex);
253                        w.element.update();
254
255                        id = id + '_wrapper';
256                        DOM.removeClass(t.lastId, 'focus');
257                        DOM.addClass(id, 'focus');
258                        t.lastId = id;
259                },
260
261                _addAll : function(te, ne) {
262                        var i, n, t = this, dom = tinymce.DOM;
263
264                        if (is(ne, 'string'))
265                                te.appendChild(dom.doc.createTextNode(ne));
266                        else if (ne.length) {
267                                te = te.appendChild(dom.create(ne[0], ne[1]));
268
269                                for (i=2; i<ne.length; i++)
270                                        t._addAll(te, ne[i]);
271                        }
272                },
273
274                _startDrag : function(id, se, ac) {
275                        var t = this, mu, mm, d = document, eb, w = t.windows[id], we = w.element, sp = we.getXY(), p, sz, ph, cp, vp, sx, sy, sex, sey, dx, dy, dw, dh;
276
277                        // Get positons and sizes
278//                      cp = DOM.getPos(t.editor.getContainer());
279                        cp = {x : 0, y : 0};
280                        vp = DOM.getViewPort();
281
282                        // Reduce viewport size to avoid scrollbars
283                        vp.w -= 2;
284                        vp.h -= 2;
285
286                        sex = se.screenX;
287                        sey = se.screenY;
288                        dx = dy = dw = dh = 0;
289
290                        // Handle mouse up
291                        mu = Event.add(d, 'mouseup', function(e) {
292                                Event.remove(d, 'mouseup', mu);
293                                Event.remove(d, 'mousemove', mm);
294
295                                if (eb)
296                                        eb.remove();
297
298                                we.moveBy(dx, dy);
299                                we.resizeBy(dw, dh);
300                                sz = we.getSize();
301                                DOM.setStyles(id + '_ifr', {width : sz.w - w.deltaWidth, height : sz.h - w.deltaHeight});
302                                t._fixIELayout(id, 1);
303
304                                return Event.cancel(e);
305                        });
306
307                        if (ac != 'move')
308                                startMove();
309
310                        function startMove() {
311                                if (eb)
312                                        return;
313
314                                t._fixIELayout(id, 0);
315
316                                // Setup event blocker
317                                DOM.add(d.body, 'div', {
318                                        id : 'mceEventBlocker',
319                                        'class' : 'mceEventBlocker ' + (t.editor.settings.inlinepopups_skin || 'clearlooks2'),
320                                        style : {left : vp.x, top : vp.y, width : vp.w - 20, height : vp.h - 20, zIndex : 20001}
321                                });
322                                eb = new Element('mceEventBlocker');
323                                eb.update();
324
325                                // Setup placeholder
326                                p = we.getXY();
327                                sz = we.getSize();
328                                sx = cp.x + p.x - vp.x;
329                                sy = cp.y + p.y - vp.y;
330                                DOM.add(eb.get(), 'div', {id : 'mcePlaceHolder', 'class' : 'placeholder', style : {left : sx, top : sy, width : sz.w, height : sz.h}});
331                                ph = new Element('mcePlaceHolder');
332                        };
333
334                        // Handle mouse move/drag
335                        mm = Event.add(d, 'mousemove', function(e) {
336                                var x, y, v;
337
338                                startMove();
339
340                                x = e.screenX - sex;
341                                y = e.screenY - sey;
342
343                                switch (ac) {
344                                        case 'resize-w':
345                                                dx = x;
346                                                dw = 0 - x;
347                                                break;
348
349                                        case 'resize-e':
350                                                dw = x;
351                                                break;
352
353                                        case 'resize-n':
354                                        case 'resize-nw':
355                                        case 'resize-ne':
356                                                if (ac == "resize-nw") {
357                                                        dx = x;
358                                                        dw = 0 - x;
359                                                } else if (ac == "resize-ne")
360                                                        dw = x;
361
362                                                dy = y;
363                                                dh = 0 - y;
364                                                break;
365
366                                        case 'resize-s':
367                                        case 'resize-sw':
368                                        case 'resize-se':
369                                                if (ac == "resize-sw") {
370                                                        dx = x;
371                                                        dw = 0 - x;
372                                                } else if (ac == "resize-se")
373                                                        dw = x;
374
375                                                dh = y;
376                                                break;
377
378                                        case 'move':
379                                                dx = x;
380                                                dy = y;
381                                                break;
382                                }
383
384                                // Boundary check
385                                if (dw < (v = w.features.min_width - sz.w)) {
386                                        if (dx !== 0)
387                                                dx += dw - v;
388
389                                        dw = v;
390                                }
391       
392                                if (dh < (v = w.features.min_height - sz.h)) {
393                                        if (dy !== 0)
394                                                dy += dh - v;
395
396                                        dh = v;
397                                }
398
399                                dw = Math.min(dw, w.features.max_width - sz.w);
400                                dh = Math.min(dh, w.features.max_height - sz.h);
401                                dx = Math.max(dx, vp.x - (sx + vp.x));
402                                dy = Math.max(dy, vp.y - (sy + vp.y));
403                                dx = Math.min(dx, (vp.w + vp.x) - (sx + sz.w + vp.x));
404                                dy = Math.min(dy, (vp.h + vp.y) - (sy + sz.h + vp.y));
405
406                                // Move if needed
407                                if (dx + dy !== 0) {
408                                        if (sx + dx < 0)
409                                                dx = 0;
410       
411                                        if (sy + dy < 0)
412                                                dy = 0;
413
414                                        ph.moveTo(sx + dx, sy + dy);
415                                }
416
417                                // Resize if needed
418                                if (dw + dh !== 0)
419                                        ph.resizeTo(sz.w + dw, sz.h + dh);
420
421                                return Event.cancel(e);
422                        });
423
424                        return Event.cancel(se);
425                },
426
427                resizeBy : function(dw, dh, id) {
428                        var w = this.windows[id];
429
430                        if (w) {
431                                w.element.resizeBy(dw, dh);
432                                w.iframeElement.resizeBy(dw, dh);
433                        }
434                },
435
436                close : function(win, id) {
437                        var t = this, w, d = document, ix = 0, fw;
438
439                        // Probably not inline
440                        if (!id && win) {
441                                t.parent(win);
442                                return;
443                        }
444
445                        if (w = t.windows[id]) {
446                                t.onClose.dispatch(t);
447                                Event.remove(d, 'mousedown', w.mousedownFunc);
448                                Event.remove(d, 'click', w.clickFunc);
449
450                                DOM.setAttrib(id + '_ifr', 'src', 'javascript:""'); // Prevent leak
451                                w.element.remove();
452                                delete t.windows[id];
453
454                                // Find front most window and focus that
455                                each (t.windows, function(w) {
456                                        if (w.zIndex > ix) {
457                                                fw = w;
458                                                ix = w.zIndex;
459                                        }
460                                });
461
462                                if (fw)
463                                        t.focus(fw.id);
464                        }
465                },
466
467                setTitle : function(ti, id) {
468                        DOM.get(id + '_title').innerHTML = DOM.encode(ti);
469                },
470
471                alert : function(txt, cb, s) {
472                        var t = this, w;
473
474                        w = t.open({
475                                title : t,
476                                type : 'alert',
477                                button_func : function(s) {
478                                        if (cb)
479                                                cb.call(s || t, s);
480
481                                        t.close(null, w.id);
482                                },
483                                content : DOM.encode(t.editor.getLang(txt, txt)),
484                                inline : 1,
485                                width : 400,
486                                height : 130
487                        });
488                },
489
490                confirm : function(txt, cb, s) {
491                        var t = this, w;
492
493                        w = t.open({
494                                title : t,
495                                type : 'confirm',
496                                button_func : function(s) {
497                                        if (cb)
498                                                cb.call(s || t, s);
499
500                                        t.close(null, w.id);
501                                },
502                                content : DOM.encode(t.editor.getLang(txt, txt)),
503                                inline : 1,
504                                width : 400,
505                                height : 130
506                        });
507                },
508
509                // Internal functions
510
511                _fixIELayout : function(id, s) {
512                        var w, img;
513
514                        if (!tinymce.isIE6)
515                                return;
516
517                        // Fixes the bug where hover flickers and does odd things in IE6
518                        each(['n','s','w','e','nw','ne','sw','se'], function(v) {
519                                var e = DOM.get(id + '_resize_' + v);
520
521                                DOM.setStyles(e, {
522                                        width : s ? e.clientWidth : '',
523                                        height : s ? e.clientHeight : '',
524                                        cursor : DOM.getStyle(e, 'cursor', 1)
525                                });
526
527                                DOM.setStyle(id + "_bottom", 'bottom', '-1px');
528
529                                e = 0;
530                        });
531
532                        // Fixes graphics glitch
533                        if (w = this.windows[id]) {
534                                // Fixes rendering bug after resize
535                                w.element.hide();
536                                w.element.show();
537
538                                // Forced a repaint of the window
539                                //DOM.get(id).style.filter = '';
540
541                                // IE has a bug where images used in CSS won't get loaded
542                                // sometimes when the cache in the browser is disabled
543                                // This fix tries to solve it by loading the images using the image object
544                                each(DOM.select('div,a', id), function(e, i) {
545                                        if (e.currentStyle.backgroundImage != 'none') {
546                                                img = new Image();
547                                                img.src = e.currentStyle.backgroundImage.replace(/url\(\"(.+)\"\)/, '$1');
548                                        }
549                                });
550
551                                DOM.get(id).style.filter = '';
552                        }
553                }
554        });
555
556        // Register plugin
557        tinymce.PluginManager.add('inlinepopups', tinymce.plugins.InlinePopups);
558})();
559
Note: See TracBrowser for help on using the repository browser.