annotate static/js/tiny_mce/plugins/inlinepopups/editor_plugin_src.js @ 568:7cec8d6f9581

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