annotate media/js/tiny_mce/plugins/inlinepopups/editor_plugin_src.js @ 183:149c3567fec1

Updated to TinyMCE version 3.3.2. This is for #57.
author Brian Neal <bgneal@gmail.com>
date Sun, 28 Mar 2010 21:47:48 +0000
parents a5b4c5ce0658
children
rev   line source
bgneal@45 1 /**
bgneal@183 2 * editor_plugin_src.js
bgneal@45 3 *
bgneal@183 4 * Copyright 2009, Moxiecode Systems AB
bgneal@183 5 * Released under LGPL License.
bgneal@183 6 *
bgneal@183 7 * License: http://tinymce.moxiecode.com/license
bgneal@183 8 * Contributing: http://tinymce.moxiecode.com/contributing
bgneal@45 9 */
bgneal@45 10
bgneal@45 11 (function() {
bgneal@45 12 var DOM = tinymce.DOM, Element = tinymce.dom.Element, Event = tinymce.dom.Event, each = tinymce.each, is = tinymce.is;
bgneal@45 13
bgneal@45 14 tinymce.create('tinymce.plugins.InlinePopups', {
bgneal@45 15 init : function(ed, url) {
bgneal@45 16 // Replace window manager
bgneal@45 17 ed.onBeforeRenderUI.add(function() {
bgneal@45 18 ed.windowManager = new tinymce.InlineWindowManager(ed);
bgneal@45 19 DOM.loadCSS(url + '/skins/' + (ed.settings.inlinepopups_skin || 'clearlooks2') + "/window.css");
bgneal@45 20 });
bgneal@45 21 },
bgneal@45 22
bgneal@45 23 getInfo : function() {
bgneal@45 24 return {
bgneal@45 25 longname : 'InlinePopups',
bgneal@45 26 author : 'Moxiecode Systems AB',
bgneal@45 27 authorurl : 'http://tinymce.moxiecode.com',
bgneal@45 28 infourl : 'http://wiki.moxiecode.com/index.php/TinyMCE:Plugins/inlinepopups',
bgneal@45 29 version : tinymce.majorVersion + "." + tinymce.minorVersion
bgneal@45 30 };
bgneal@45 31 }
bgneal@45 32 });
bgneal@45 33
bgneal@45 34 tinymce.create('tinymce.InlineWindowManager:tinymce.WindowManager', {
bgneal@45 35 InlineWindowManager : function(ed) {
bgneal@45 36 var t = this;
bgneal@45 37
bgneal@45 38 t.parent(ed);
bgneal@45 39 t.zIndex = 300000;
bgneal@45 40 t.count = 0;
bgneal@45 41 t.windows = {};
bgneal@45 42 },
bgneal@45 43
bgneal@45 44 open : function(f, p) {
bgneal@45 45 var t = this, id, opt = '', ed = t.editor, dw = 0, dh = 0, vp, po, mdf, clf, we, w, u;
bgneal@45 46
bgneal@45 47 f = f || {};
bgneal@45 48 p = p || {};
bgneal@45 49
bgneal@45 50 // Run native windows
bgneal@45 51 if (!f.inline)
bgneal@45 52 return t.parent(f, p);
bgneal@45 53
bgneal@45 54 // Only store selection if the type is a normal window
bgneal@45 55 if (!f.type)
bgneal@183 56 t.bookmark = ed.selection.getBookmark(1);
bgneal@45 57
bgneal@45 58 id = DOM.uniqueId();
bgneal@45 59 vp = DOM.getViewPort();
bgneal@45 60 f.width = parseInt(f.width || 320);
bgneal@45 61 f.height = parseInt(f.height || 240) + (tinymce.isIE ? 8 : 0);
bgneal@45 62 f.min_width = parseInt(f.min_width || 150);
bgneal@45 63 f.min_height = parseInt(f.min_height || 100);
bgneal@45 64 f.max_width = parseInt(f.max_width || 2000);
bgneal@45 65 f.max_height = parseInt(f.max_height || 2000);
bgneal@45 66 f.left = f.left || Math.round(Math.max(vp.x, vp.x + (vp.w / 2.0) - (f.width / 2.0)));
bgneal@45 67 f.top = f.top || Math.round(Math.max(vp.y, vp.y + (vp.h / 2.0) - (f.height / 2.0)));
bgneal@45 68 f.movable = f.resizable = true;
bgneal@45 69 p.mce_width = f.width;
bgneal@45 70 p.mce_height = f.height;
bgneal@45 71 p.mce_inline = true;
bgneal@45 72 p.mce_window_id = id;
bgneal@45 73 p.mce_auto_focus = f.auto_focus;
bgneal@45 74
bgneal@45 75 // Transpose
bgneal@45 76 // po = DOM.getPos(ed.getContainer());
bgneal@45 77 // f.left -= po.x;
bgneal@45 78 // f.top -= po.y;
bgneal@45 79
bgneal@45 80 t.features = f;
bgneal@45 81 t.params = p;
bgneal@45 82 t.onOpen.dispatch(t, f, p);
bgneal@45 83
bgneal@45 84 if (f.type) {
bgneal@45 85 opt += ' mceModal';
bgneal@45 86
bgneal@45 87 if (f.type)
bgneal@45 88 opt += ' mce' + f.type.substring(0, 1).toUpperCase() + f.type.substring(1);
bgneal@45 89
bgneal@45 90 f.resizable = false;
bgneal@45 91 }
bgneal@45 92
bgneal@45 93 if (f.statusbar)
bgneal@45 94 opt += ' mceStatusbar';
bgneal@45 95
bgneal@45 96 if (f.resizable)
bgneal@45 97 opt += ' mceResizable';
bgneal@45 98
bgneal@45 99 if (f.minimizable)
bgneal@45 100 opt += ' mceMinimizable';
bgneal@45 101
bgneal@45 102 if (f.maximizable)
bgneal@45 103 opt += ' mceMaximizable';
bgneal@45 104
bgneal@45 105 if (f.movable)
bgneal@45 106 opt += ' mceMovable';
bgneal@45 107
bgneal@45 108 // Create DOM objects
bgneal@45 109 t._addAll(DOM.doc.body,
bgneal@45 110 ['div', {id : id, 'class' : ed.settings.inlinepopups_skin || 'clearlooks2', style : 'width:100px;height:100px'},
bgneal@45 111 ['div', {id : id + '_wrapper', 'class' : 'mceWrapper' + opt},
bgneal@45 112 ['div', {id : id + '_top', 'class' : 'mceTop'},
bgneal@45 113 ['div', {'class' : 'mceLeft'}],
bgneal@45 114 ['div', {'class' : 'mceCenter'}],
bgneal@45 115 ['div', {'class' : 'mceRight'}],
bgneal@45 116 ['span', {id : id + '_title'}, f.title || '']
bgneal@45 117 ],
bgneal@45 118
bgneal@45 119 ['div', {id : id + '_middle', 'class' : 'mceMiddle'},
bgneal@45 120 ['div', {id : id + '_left', 'class' : 'mceLeft'}],
bgneal@45 121 ['span', {id : id + '_content'}],
bgneal@45 122 ['div', {id : id + '_right', 'class' : 'mceRight'}]
bgneal@45 123 ],
bgneal@45 124
bgneal@45 125 ['div', {id : id + '_bottom', 'class' : 'mceBottom'},
bgneal@45 126 ['div', {'class' : 'mceLeft'}],
bgneal@45 127 ['div', {'class' : 'mceCenter'}],
bgneal@45 128 ['div', {'class' : 'mceRight'}],
bgneal@45 129 ['span', {id : id + '_status'}, 'Content']
bgneal@45 130 ],
bgneal@45 131
bgneal@45 132 ['a', {'class' : 'mceMove', tabindex : '-1', href : 'javascript:;'}],
bgneal@45 133 ['a', {'class' : 'mceMin', tabindex : '-1', href : 'javascript:;', onmousedown : 'return false;'}],
bgneal@45 134 ['a', {'class' : 'mceMax', tabindex : '-1', href : 'javascript:;', onmousedown : 'return false;'}],
bgneal@45 135 ['a', {'class' : 'mceMed', tabindex : '-1', href : 'javascript:;', onmousedown : 'return false;'}],
bgneal@45 136 ['a', {'class' : 'mceClose', tabindex : '-1', href : 'javascript:;', onmousedown : 'return false;'}],
bgneal@45 137 ['a', {id : id + '_resize_n', 'class' : 'mceResize mceResizeN', tabindex : '-1', href : 'javascript:;'}],
bgneal@45 138 ['a', {id : id + '_resize_s', 'class' : 'mceResize mceResizeS', tabindex : '-1', href : 'javascript:;'}],
bgneal@45 139 ['a', {id : id + '_resize_w', 'class' : 'mceResize mceResizeW', tabindex : '-1', href : 'javascript:;'}],
bgneal@45 140 ['a', {id : id + '_resize_e', 'class' : 'mceResize mceResizeE', tabindex : '-1', href : 'javascript:;'}],
bgneal@45 141 ['a', {id : id + '_resize_nw', 'class' : 'mceResize mceResizeNW', tabindex : '-1', href : 'javascript:;'}],
bgneal@45 142 ['a', {id : id + '_resize_ne', 'class' : 'mceResize mceResizeNE', tabindex : '-1', href : 'javascript:;'}],
bgneal@45 143 ['a', {id : id + '_resize_sw', 'class' : 'mceResize mceResizeSW', tabindex : '-1', href : 'javascript:;'}],
bgneal@45 144 ['a', {id : id + '_resize_se', 'class' : 'mceResize mceResizeSE', tabindex : '-1', href : 'javascript:;'}]
bgneal@45 145 ]
bgneal@45 146 ]
bgneal@45 147 );
bgneal@45 148
bgneal@45 149 DOM.setStyles(id, {top : -10000, left : -10000});
bgneal@45 150
bgneal@45 151 // Fix gecko rendering bug, where the editors iframe messed with window contents
bgneal@45 152 if (tinymce.isGecko)
bgneal@45 153 DOM.setStyle(id, 'overflow', 'auto');
bgneal@45 154
bgneal@45 155 // Measure borders
bgneal@45 156 if (!f.type) {
bgneal@45 157 dw += DOM.get(id + '_left').clientWidth;
bgneal@45 158 dw += DOM.get(id + '_right').clientWidth;
bgneal@45 159 dh += DOM.get(id + '_top').clientHeight;
bgneal@45 160 dh += DOM.get(id + '_bottom').clientHeight;
bgneal@45 161 }
bgneal@45 162
bgneal@45 163 // Resize window
bgneal@45 164 DOM.setStyles(id, {top : f.top, left : f.left, width : f.width + dw, height : f.height + dh});
bgneal@45 165
bgneal@45 166 u = f.url || f.file;
bgneal@45 167 if (u) {
bgneal@45 168 if (tinymce.relaxedDomain)
bgneal@45 169 u += (u.indexOf('?') == -1 ? '?' : '&') + 'mce_rdomain=' + tinymce.relaxedDomain;
bgneal@45 170
bgneal@45 171 u = tinymce._addVer(u);
bgneal@45 172 }
bgneal@45 173
bgneal@45 174 if (!f.type) {
bgneal@45 175 DOM.add(id + '_content', 'iframe', {id : id + '_ifr', src : 'javascript:""', frameBorder : 0, style : 'border:0;width:10px;height:10px'});
bgneal@45 176 DOM.setStyles(id + '_ifr', {width : f.width, height : f.height});
bgneal@45 177 DOM.setAttrib(id + '_ifr', 'src', u);
bgneal@45 178 } else {
bgneal@45 179 DOM.add(id + '_wrapper', 'a', {id : id + '_ok', 'class' : 'mceButton mceOk', href : 'javascript:;', onmousedown : 'return false;'}, 'Ok');
bgneal@45 180
bgneal@45 181 if (f.type == 'confirm')
bgneal@45 182 DOM.add(id + '_wrapper', 'a', {'class' : 'mceButton mceCancel', href : 'javascript:;', onmousedown : 'return false;'}, 'Cancel');
bgneal@45 183
bgneal@45 184 DOM.add(id + '_middle', 'div', {'class' : 'mceIcon'});
bgneal@45 185 DOM.setHTML(id + '_content', f.content.replace('\n', '<br />'));
bgneal@45 186 }
bgneal@45 187
bgneal@45 188 // Register events
bgneal@45 189 mdf = Event.add(id, 'mousedown', function(e) {
bgneal@45 190 var n = e.target, w, vp;
bgneal@45 191
bgneal@45 192 w = t.windows[id];
bgneal@45 193 t.focus(id);
bgneal@45 194
bgneal@45 195 if (n.nodeName == 'A' || n.nodeName == 'a') {
bgneal@45 196 if (n.className == 'mceMax') {
bgneal@45 197 w.oldPos = w.element.getXY();
bgneal@45 198 w.oldSize = w.element.getSize();
bgneal@45 199
bgneal@45 200 vp = DOM.getViewPort();
bgneal@45 201
bgneal@45 202 // Reduce viewport size to avoid scrollbars
bgneal@45 203 vp.w -= 2;
bgneal@45 204 vp.h -= 2;
bgneal@45 205
bgneal@45 206 w.element.moveTo(vp.x, vp.y);
bgneal@45 207 w.element.resizeTo(vp.w, vp.h);
bgneal@45 208 DOM.setStyles(id + '_ifr', {width : vp.w - w.deltaWidth, height : vp.h - w.deltaHeight});
bgneal@45 209 DOM.addClass(id + '_wrapper', 'mceMaximized');
bgneal@45 210 } else if (n.className == 'mceMed') {
bgneal@45 211 // Reset to old size
bgneal@45 212 w.element.moveTo(w.oldPos.x, w.oldPos.y);
bgneal@45 213 w.element.resizeTo(w.oldSize.w, w.oldSize.h);
bgneal@45 214 w.iframeElement.resizeTo(w.oldSize.w - w.deltaWidth, w.oldSize.h - w.deltaHeight);
bgneal@45 215
bgneal@45 216 DOM.removeClass(id + '_wrapper', 'mceMaximized');
bgneal@45 217 } else if (n.className == 'mceMove')
bgneal@45 218 return t._startDrag(id, e, n.className);
bgneal@45 219 else if (DOM.hasClass(n, 'mceResize'))
bgneal@45 220 return t._startDrag(id, e, n.className.substring(13));
bgneal@45 221 }
bgneal@45 222 });
bgneal@45 223
bgneal@45 224 clf = Event.add(id, 'click', function(e) {
bgneal@45 225 var n = e.target;
bgneal@45 226
bgneal@45 227 t.focus(id);
bgneal@45 228
bgneal@45 229 if (n.nodeName == 'A' || n.nodeName == 'a') {
bgneal@45 230 switch (n.className) {
bgneal@45 231 case 'mceClose':
bgneal@45 232 t.close(null, id);
bgneal@45 233 return Event.cancel(e);
bgneal@45 234
bgneal@45 235 case 'mceButton mceOk':
bgneal@45 236 case 'mceButton mceCancel':
bgneal@45 237 f.button_func(n.className == 'mceButton mceOk');
bgneal@45 238 return Event.cancel(e);
bgneal@45 239 }
bgneal@45 240 }
bgneal@45 241 });
bgneal@45 242
bgneal@45 243 // Add window
bgneal@45 244 w = t.windows[id] = {
bgneal@45 245 id : id,
bgneal@45 246 mousedown_func : mdf,
bgneal@45 247 click_func : clf,
bgneal@45 248 element : new Element(id, {blocker : 1, container : ed.getContainer()}),
bgneal@45 249 iframeElement : new Element(id + '_ifr'),
bgneal@45 250 features : f,
bgneal@45 251 deltaWidth : dw,
bgneal@45 252 deltaHeight : dh
bgneal@45 253 };
bgneal@45 254
bgneal@45 255 w.iframeElement.on('focus', function() {
bgneal@45 256 t.focus(id);
bgneal@45 257 });
bgneal@45 258
bgneal@45 259 // Setup blocker
bgneal@45 260 if (t.count == 0 && t.editor.getParam('dialog_type', 'modal') == 'modal') {
bgneal@45 261 DOM.add(DOM.doc.body, 'div', {
bgneal@45 262 id : 'mceModalBlocker',
bgneal@45 263 'class' : (t.editor.settings.inlinepopups_skin || 'clearlooks2') + '_modalBlocker',
bgneal@45 264 style : {zIndex : t.zIndex - 1}
bgneal@45 265 });
bgneal@45 266
bgneal@45 267 DOM.show('mceModalBlocker'); // Reduces flicker in IE
bgneal@45 268 } else
bgneal@45 269 DOM.setStyle('mceModalBlocker', 'z-index', t.zIndex - 1);
bgneal@45 270
bgneal@45 271 if (tinymce.isIE6 || /Firefox\/2\./.test(navigator.userAgent) || (tinymce.isIE && !DOM.boxModel))
bgneal@45 272 DOM.setStyles('mceModalBlocker', {position : 'absolute', left : vp.x, top : vp.y, width : vp.w - 2, height : vp.h - 2});
bgneal@45 273
bgneal@45 274 t.focus(id);
bgneal@45 275 t._fixIELayout(id, 1);
bgneal@45 276
bgneal@45 277 // Focus ok button
bgneal@45 278 if (DOM.get(id + '_ok'))
bgneal@45 279 DOM.get(id + '_ok').focus();
bgneal@45 280
bgneal@45 281 t.count++;
bgneal@45 282
bgneal@45 283 return w;
bgneal@45 284 },
bgneal@45 285
bgneal@45 286 focus : function(id) {
bgneal@45 287 var t = this, w;
bgneal@45 288
bgneal@45 289 if (w = t.windows[id]) {
bgneal@45 290 w.zIndex = this.zIndex++;
bgneal@45 291 w.element.setStyle('zIndex', w.zIndex);
bgneal@45 292 w.element.update();
bgneal@45 293
bgneal@45 294 id = id + '_wrapper';
bgneal@45 295 DOM.removeClass(t.lastId, 'mceFocus');
bgneal@45 296 DOM.addClass(id, 'mceFocus');
bgneal@45 297 t.lastId = id;
bgneal@45 298 }
bgneal@45 299 },
bgneal@45 300
bgneal@45 301 _addAll : function(te, ne) {
bgneal@45 302 var i, n, t = this, dom = tinymce.DOM;
bgneal@45 303
bgneal@45 304 if (is(ne, 'string'))
bgneal@45 305 te.appendChild(dom.doc.createTextNode(ne));
bgneal@45 306 else if (ne.length) {
bgneal@45 307 te = te.appendChild(dom.create(ne[0], ne[1]));
bgneal@45 308
bgneal@45 309 for (i=2; i<ne.length; i++)
bgneal@45 310 t._addAll(te, ne[i]);
bgneal@45 311 }
bgneal@45 312 },
bgneal@45 313
bgneal@45 314 _startDrag : function(id, se, ac) {
bgneal@45 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;
bgneal@45 316
bgneal@45 317 // Get positons and sizes
bgneal@45 318 // cp = DOM.getPos(t.editor.getContainer());
bgneal@45 319 cp = {x : 0, y : 0};
bgneal@45 320 vp = DOM.getViewPort();
bgneal@45 321
bgneal@45 322 // Reduce viewport size to avoid scrollbars while dragging
bgneal@45 323 vp.w -= 2;
bgneal@45 324 vp.h -= 2;
bgneal@45 325
bgneal@45 326 sex = se.screenX;
bgneal@45 327 sey = se.screenY;
bgneal@45 328 dx = dy = dw = dh = 0;
bgneal@45 329
bgneal@45 330 // Handle mouse up
bgneal@45 331 mu = Event.add(d, 'mouseup', function(e) {
bgneal@45 332 Event.remove(d, 'mouseup', mu);
bgneal@45 333 Event.remove(d, 'mousemove', mm);
bgneal@45 334
bgneal@45 335 if (eb)
bgneal@45 336 eb.remove();
bgneal@45 337
bgneal@45 338 we.moveBy(dx, dy);
bgneal@45 339 we.resizeBy(dw, dh);
bgneal@45 340 sz = we.getSize();
bgneal@45 341 DOM.setStyles(id + '_ifr', {width : sz.w - w.deltaWidth, height : sz.h - w.deltaHeight});
bgneal@45 342 t._fixIELayout(id, 1);
bgneal@45 343
bgneal@45 344 return Event.cancel(e);
bgneal@45 345 });
bgneal@45 346
bgneal@45 347 if (ac != 'Move')
bgneal@45 348 startMove();
bgneal@45 349
bgneal@45 350 function startMove() {
bgneal@45 351 if (eb)
bgneal@45 352 return;
bgneal@45 353
bgneal@45 354 t._fixIELayout(id, 0);
bgneal@45 355
bgneal@45 356 // Setup event blocker
bgneal@45 357 DOM.add(d.body, 'div', {
bgneal@45 358 id : 'mceEventBlocker',
bgneal@45 359 'class' : 'mceEventBlocker ' + (t.editor.settings.inlinepopups_skin || 'clearlooks2'),
bgneal@45 360 style : {zIndex : t.zIndex + 1}
bgneal@45 361 });
bgneal@45 362
bgneal@45 363 if (tinymce.isIE6 || (tinymce.isIE && !DOM.boxModel))
bgneal@45 364 DOM.setStyles('mceEventBlocker', {position : 'absolute', left : vp.x, top : vp.y, width : vp.w - 2, height : vp.h - 2});
bgneal@45 365
bgneal@45 366 eb = new Element('mceEventBlocker');
bgneal@45 367 eb.update();
bgneal@45 368
bgneal@45 369 // Setup placeholder
bgneal@45 370 p = we.getXY();
bgneal@45 371 sz = we.getSize();
bgneal@45 372 sx = cp.x + p.x - vp.x;
bgneal@45 373 sy = cp.y + p.y - vp.y;
bgneal@45 374 DOM.add(eb.get(), 'div', {id : 'mcePlaceHolder', 'class' : 'mcePlaceHolder', style : {left : sx, top : sy, width : sz.w, height : sz.h}});
bgneal@45 375 ph = new Element('mcePlaceHolder');
bgneal@45 376 };
bgneal@45 377
bgneal@45 378 // Handle mouse move/drag
bgneal@45 379 mm = Event.add(d, 'mousemove', function(e) {
bgneal@45 380 var x, y, v;
bgneal@45 381
bgneal@45 382 startMove();
bgneal@45 383
bgneal@45 384 x = e.screenX - sex;
bgneal@45 385 y = e.screenY - sey;
bgneal@45 386
bgneal@45 387 switch (ac) {
bgneal@45 388 case 'ResizeW':
bgneal@45 389 dx = x;
bgneal@45 390 dw = 0 - x;
bgneal@45 391 break;
bgneal@45 392
bgneal@45 393 case 'ResizeE':
bgneal@45 394 dw = x;
bgneal@45 395 break;
bgneal@45 396
bgneal@45 397 case 'ResizeN':
bgneal@45 398 case 'ResizeNW':
bgneal@45 399 case 'ResizeNE':
bgneal@45 400 if (ac == "ResizeNW") {
bgneal@45 401 dx = x;
bgneal@45 402 dw = 0 - x;
bgneal@45 403 } else if (ac == "ResizeNE")
bgneal@45 404 dw = x;
bgneal@45 405
bgneal@45 406 dy = y;
bgneal@45 407 dh = 0 - y;
bgneal@45 408 break;
bgneal@45 409
bgneal@45 410 case 'ResizeS':
bgneal@45 411 case 'ResizeSW':
bgneal@45 412 case 'ResizeSE':
bgneal@45 413 if (ac == "ResizeSW") {
bgneal@45 414 dx = x;
bgneal@45 415 dw = 0 - x;
bgneal@45 416 } else if (ac == "ResizeSE")
bgneal@45 417 dw = x;
bgneal@45 418
bgneal@45 419 dh = y;
bgneal@45 420 break;
bgneal@45 421
bgneal@45 422 case 'mceMove':
bgneal@45 423 dx = x;
bgneal@45 424 dy = y;
bgneal@45 425 break;
bgneal@45 426 }
bgneal@45 427
bgneal@45 428 // Boundary check
bgneal@45 429 if (dw < (v = w.features.min_width - sz.w)) {
bgneal@45 430 if (dx !== 0)
bgneal@45 431 dx += dw - v;
bgneal@45 432
bgneal@45 433 dw = v;
bgneal@45 434 }
bgneal@45 435
bgneal@45 436 if (dh < (v = w.features.min_height - sz.h)) {
bgneal@45 437 if (dy !== 0)
bgneal@45 438 dy += dh - v;
bgneal@45 439
bgneal@45 440 dh = v;
bgneal@45 441 }
bgneal@45 442
bgneal@45 443 dw = Math.min(dw, w.features.max_width - sz.w);
bgneal@45 444 dh = Math.min(dh, w.features.max_height - sz.h);
bgneal@45 445 dx = Math.max(dx, vp.x - (sx + vp.x));
bgneal@45 446 dy = Math.max(dy, vp.y - (sy + vp.y));
bgneal@45 447 dx = Math.min(dx, (vp.w + vp.x) - (sx + sz.w + vp.x));
bgneal@45 448 dy = Math.min(dy, (vp.h + vp.y) - (sy + sz.h + vp.y));
bgneal@45 449
bgneal@45 450 // Move if needed
bgneal@45 451 if (dx + dy !== 0) {
bgneal@45 452 if (sx + dx < 0)
bgneal@45 453 dx = 0;
bgneal@45 454
bgneal@45 455 if (sy + dy < 0)
bgneal@45 456 dy = 0;
bgneal@45 457
bgneal@45 458 ph.moveTo(sx + dx, sy + dy);
bgneal@45 459 }
bgneal@45 460
bgneal@45 461 // Resize if needed
bgneal@45 462 if (dw + dh !== 0)
bgneal@45 463 ph.resizeTo(sz.w + dw, sz.h + dh);
bgneal@45 464
bgneal@45 465 return Event.cancel(e);
bgneal@45 466 });
bgneal@45 467
bgneal@45 468 return Event.cancel(se);
bgneal@45 469 },
bgneal@45 470
bgneal@45 471 resizeBy : function(dw, dh, id) {
bgneal@45 472 var w = this.windows[id];
bgneal@45 473
bgneal@45 474 if (w) {
bgneal@45 475 w.element.resizeBy(dw, dh);
bgneal@45 476 w.iframeElement.resizeBy(dw, dh);
bgneal@45 477 }
bgneal@45 478 },
bgneal@45 479
bgneal@45 480 close : function(win, id) {
bgneal@45 481 var t = this, w, d = DOM.doc, ix = 0, fw, id;
bgneal@45 482
bgneal@45 483 id = t._findId(id || win);
bgneal@45 484
bgneal@45 485 // Probably not inline
bgneal@45 486 if (!t.windows[id]) {
bgneal@45 487 t.parent(win);
bgneal@45 488 return;
bgneal@45 489 }
bgneal@45 490
bgneal@45 491 t.count--;
bgneal@45 492
bgneal@45 493 if (t.count == 0)
bgneal@45 494 DOM.remove('mceModalBlocker');
bgneal@45 495
bgneal@45 496 if (w = t.windows[id]) {
bgneal@45 497 t.onClose.dispatch(t);
bgneal@45 498 Event.remove(d, 'mousedown', w.mousedownFunc);
bgneal@45 499 Event.remove(d, 'click', w.clickFunc);
bgneal@45 500 Event.clear(id);
bgneal@45 501 Event.clear(id + '_ifr');
bgneal@45 502
bgneal@45 503 DOM.setAttrib(id + '_ifr', 'src', 'javascript:""'); // Prevent leak
bgneal@45 504 w.element.remove();
bgneal@45 505 delete t.windows[id];
bgneal@45 506
bgneal@45 507 // Find front most window and focus that
bgneal@45 508 each (t.windows, function(w) {
bgneal@45 509 if (w.zIndex > ix) {
bgneal@45 510 fw = w;
bgneal@45 511 ix = w.zIndex;
bgneal@45 512 }
bgneal@45 513 });
bgneal@45 514
bgneal@45 515 if (fw)
bgneal@45 516 t.focus(fw.id);
bgneal@45 517 }
bgneal@45 518 },
bgneal@45 519
bgneal@45 520 setTitle : function(w, ti) {
bgneal@45 521 var e;
bgneal@45 522
bgneal@45 523 w = this._findId(w);
bgneal@45 524
bgneal@45 525 if (e = DOM.get(w + '_title'))
bgneal@45 526 e.innerHTML = DOM.encode(ti);
bgneal@45 527 },
bgneal@45 528
bgneal@45 529 alert : function(txt, cb, s) {
bgneal@45 530 var t = this, w;
bgneal@45 531
bgneal@45 532 w = t.open({
bgneal@45 533 title : t,
bgneal@45 534 type : 'alert',
bgneal@45 535 button_func : function(s) {
bgneal@45 536 if (cb)
bgneal@45 537 cb.call(s || t, s);
bgneal@45 538
bgneal@45 539 t.close(null, w.id);
bgneal@45 540 },
bgneal@45 541 content : DOM.encode(t.editor.getLang(txt, txt)),
bgneal@45 542 inline : 1,
bgneal@45 543 width : 400,
bgneal@45 544 height : 130
bgneal@45 545 });
bgneal@45 546 },
bgneal@45 547
bgneal@45 548 confirm : function(txt, cb, s) {
bgneal@45 549 var t = this, w;
bgneal@45 550
bgneal@45 551 w = t.open({
bgneal@45 552 title : t,
bgneal@45 553 type : 'confirm',
bgneal@45 554 button_func : function(s) {
bgneal@45 555 if (cb)
bgneal@45 556 cb.call(s || t, s);
bgneal@45 557
bgneal@45 558 t.close(null, w.id);
bgneal@45 559 },
bgneal@45 560 content : DOM.encode(t.editor.getLang(txt, txt)),
bgneal@45 561 inline : 1,
bgneal@45 562 width : 400,
bgneal@45 563 height : 130
bgneal@45 564 });
bgneal@45 565 },
bgneal@45 566
bgneal@45 567 // Internal functions
bgneal@45 568
bgneal@45 569 _findId : function(w) {
bgneal@45 570 var t = this;
bgneal@45 571
bgneal@45 572 if (typeof(w) == 'string')
bgneal@45 573 return w;
bgneal@45 574
bgneal@45 575 each(t.windows, function(wo) {
bgneal@45 576 var ifr = DOM.get(wo.id + '_ifr');
bgneal@45 577
bgneal@45 578 if (ifr && w == ifr.contentWindow) {
bgneal@45 579 w = wo.id;
bgneal@45 580 return false;
bgneal@45 581 }
bgneal@45 582 });
bgneal@45 583
bgneal@45 584 return w;
bgneal@45 585 },
bgneal@45 586
bgneal@45 587 _fixIELayout : function(id, s) {
bgneal@45 588 var w, img;
bgneal@45 589
bgneal@45 590 if (!tinymce.isIE6)
bgneal@45 591 return;
bgneal@45 592
bgneal@45 593 // Fixes the bug where hover flickers and does odd things in IE6
bgneal@45 594 each(['n','s','w','e','nw','ne','sw','se'], function(v) {
bgneal@45 595 var e = DOM.get(id + '_resize_' + v);
bgneal@45 596
bgneal@45 597 DOM.setStyles(e, {
bgneal@45 598 width : s ? e.clientWidth : '',
bgneal@45 599 height : s ? e.clientHeight : '',
bgneal@45 600 cursor : DOM.getStyle(e, 'cursor', 1)
bgneal@45 601 });
bgneal@45 602
bgneal@45 603 DOM.setStyle(id + "_bottom", 'bottom', '-1px');
bgneal@45 604
bgneal@45 605 e = 0;
bgneal@45 606 });
bgneal@45 607
bgneal@45 608 // Fixes graphics glitch
bgneal@45 609 if (w = this.windows[id]) {
bgneal@45 610 // Fixes rendering bug after resize
bgneal@45 611 w.element.hide();
bgneal@45 612 w.element.show();
bgneal@45 613
bgneal@45 614 // Forced a repaint of the window
bgneal@45 615 //DOM.get(id).style.filter = '';
bgneal@45 616
bgneal@45 617 // IE has a bug where images used in CSS won't get loaded
bgneal@45 618 // sometimes when the cache in the browser is disabled
bgneal@45 619 // This fix tries to solve it by loading the images using the image object
bgneal@45 620 each(DOM.select('div,a', id), function(e, i) {
bgneal@45 621 if (e.currentStyle.backgroundImage != 'none') {
bgneal@45 622 img = new Image();
bgneal@45 623 img.src = e.currentStyle.backgroundImage.replace(/url\(\"(.+)\"\)/, '$1');
bgneal@45 624 }
bgneal@45 625 });
bgneal@45 626
bgneal@45 627 DOM.get(id).style.filter = '';
bgneal@45 628 }
bgneal@45 629 }
bgneal@45 630 });
bgneal@45 631
bgneal@45 632 // Register plugin
bgneal@45 633 tinymce.PluginManager.add('inlinepopups', tinymce.plugins.InlinePopups);
bgneal@45 634 })();
bgneal@45 635