annotate media/js/tiny_mce/plugins/inlinepopups/editor_plugin_src.js @ 137:c7d75cdfea21

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