includes/clientside/tinymce/plugins/inlinepopups/editor_plugin_src.js
changeset 543 dffcbfbc4e59
parent 476 f26a69c40431
child 778 57ce13805b6f
equal deleted inserted replaced
542:5841df0ab575 543:dffcbfbc4e59
     1 /**
     1 /**
     2  * $Id: editor_plugin_src.js 644 2008-02-26 18:03:45Z spocke $
     2  * $Id: editor_plugin_src.js 809 2008-04-17 14:41:31Z spocke $
     3  *
     3  *
     4  * @author Moxiecode
     4  * @author Moxiecode
     5  * @copyright Copyright © 2004-2008, Moxiecode Systems AB, All rights reserved.
     5  * @copyright Copyright © 2004-2008, Moxiecode Systems AB, All rights reserved.
     6  */
     6  */
     7 
     7 
    31 	tinymce.create('tinymce.InlineWindowManager:tinymce.WindowManager', {
    31 	tinymce.create('tinymce.InlineWindowManager:tinymce.WindowManager', {
    32 		InlineWindowManager : function(ed) {
    32 		InlineWindowManager : function(ed) {
    33 			var t = this;
    33 			var t = this;
    34 
    34 
    35 			t.parent(ed);
    35 			t.parent(ed);
    36 			t.zIndex = 1000;
    36 			t.zIndex = 300000;
       
    37 			t.count = 0;
    37 		},
    38 		},
    38 
    39 
    39 		open : function(f, p) {
    40 		open : function(f, p) {
    40 			var t = this, id, opt = '', ed = t.editor, dw = 0, dh = 0, vp, po, mdf, clf, we, w, u;
    41 			var t = this, id, opt = '', ed = t.editor, dw = 0, dh = 0, vp, po, mdf, clf, we, w, u;
    41 
    42 
    44 
    45 
    45 			// Run native windows
    46 			// Run native windows
    46 			if (!f.inline)
    47 			if (!f.inline)
    47 				return t.parent(f, p);
    48 				return t.parent(f, p);
    48 
    49 
    49 			t.bookmark = ed.selection.getBookmark('simple');
    50 			// Only store selection if the type is a normal window
       
    51 			if (!f.type)
       
    52 				t.bookmark = ed.selection.getBookmark('simple');
       
    53 
    50 			id = DOM.uniqueId();
    54 			id = DOM.uniqueId();
    51 			vp = DOM.getViewPort();
    55 			vp = DOM.getViewPort();
    52 			f.width = parseInt(f.width || 320);
    56 			f.width = parseInt(f.width || 320);
    53 			f.height = parseInt(f.height || 240) + (tinymce.isIE ? 8 : 0);
    57 			f.height = parseInt(f.height || 240) + (tinymce.isIE ? 8 : 0);
    54 			f.min_width = parseInt(f.min_width || 150);
    58 			f.min_width = parseInt(f.min_width || 150);
    60 			f.movable = f.resizable = true;
    64 			f.movable = f.resizable = true;
    61 			p.mce_width = f.width;
    65 			p.mce_width = f.width;
    62 			p.mce_height = f.height;
    66 			p.mce_height = f.height;
    63 			p.mce_inline = true;
    67 			p.mce_inline = true;
    64 			p.mce_window_id = id;
    68 			p.mce_window_id = id;
       
    69 			p.mce_auto_focus = f.auto_focus;
    65 
    70 
    66 			// Transpose
    71 			// Transpose
    67 //			po = DOM.getPos(ed.getContainer());
    72 //			po = DOM.getPos(ed.getContainer());
    68 //			f.left -= po.x;
    73 //			f.left -= po.x;
    69 //			f.top -= po.y;
    74 //			f.top -= po.y;
    95 
   100 
    96 			if (f.movable)
   101 			if (f.movable)
    97 				opt += ' mceMovable';
   102 				opt += ' mceMovable';
    98 
   103 
    99 			// Create DOM objects
   104 			// Create DOM objects
   100 			t._addAll(document.body, 
   105 			t._addAll(DOM.doc.body, 
   101 				['div', {id : id, 'class' : ed.settings.inlinepopups_skin || 'clearlooks2', style : 'width:100px;height:100px'}, 
   106 				['div', {id : id, 'class' : ed.settings.inlinepopups_skin || 'clearlooks2', style : 'width:100px;height:100px'}, 
   102 					['div', {id : id + '_wrapper', 'class' : 'mceWrapper' + opt},
   107 					['div', {id : id + '_wrapper', 'class' : 'mceWrapper' + opt},
   103 						['div', {id : id + '_top', 'class' : 'mceTop'}, 
   108 						['div', {id : id + '_top', 'class' : 'mceTop'}, 
   104 							['div', {'class' : 'mceLeft'}],
   109 							['div', {'class' : 'mceLeft'}],
   105 							['div', {'class' : 'mceCenter'}],
   110 							['div', {'class' : 'mceCenter'}],
   118 							['div', {'class' : 'mceCenter'}],
   123 							['div', {'class' : 'mceCenter'}],
   119 							['div', {'class' : 'mceRight'}],
   124 							['div', {'class' : 'mceRight'}],
   120 							['span', {id : id + '_status'}, 'Content']
   125 							['span', {id : id + '_status'}, 'Content']
   121 						],
   126 						],
   122 
   127 
   123 						['a', {'class' : 'mceMove', href : 'javascript:;'}],
   128 						['a', {'class' : 'mceMove', tabindex : '-1', href : 'javascript:;'}],
   124 						['a', {'class' : 'mceMin', href : 'javascript:;', onmousedown : 'return false;'}],
   129 						['a', {'class' : 'mceMin', tabindex : '-1', href : 'javascript:;', onmousedown : 'return false;'}],
   125 						['a', {'class' : 'mceMax', href : 'javascript:;', onmousedown : 'return false;'}],
   130 						['a', {'class' : 'mceMax', tabindex : '-1', href : 'javascript:;', onmousedown : 'return false;'}],
   126 						['a', {'class' : 'mceMed', href : 'javascript:;', onmousedown : 'return false;'}],
   131 						['a', {'class' : 'mceMed', tabindex : '-1', href : 'javascript:;', onmousedown : 'return false;'}],
   127 						['a', {'class' : 'mceClose', href : 'javascript:;', onmousedown : 'return false;'}],
   132 						['a', {'class' : 'mceClose', tabindex : '-1', href : 'javascript:;', onmousedown : 'return false;'}],
   128 						['a', {id : id + '_resize_n', 'class' : 'mceResize mceResizeN', href : 'javascript:;'}],
   133 						['a', {id : id + '_resize_n', 'class' : 'mceResize mceResizeN', tabindex : '-1', href : 'javascript:;'}],
   129 						['a', {id : id + '_resize_s', 'class' : 'mceResize mceResizeS', href : 'javascript:;'}],
   134 						['a', {id : id + '_resize_s', 'class' : 'mceResize mceResizeS', tabindex : '-1', href : 'javascript:;'}],
   130 						['a', {id : id + '_resize_w', 'class' : 'mceResize mceResizeW', href : 'javascript:;'}],
   135 						['a', {id : id + '_resize_w', 'class' : 'mceResize mceResizeW', tabindex : '-1', href : 'javascript:;'}],
   131 						['a', {id : id + '_resize_e', 'class' : 'mceResize mceResizeE', href : 'javascript:;'}],
   136 						['a', {id : id + '_resize_e', 'class' : 'mceResize mceResizeE', tabindex : '-1', href : 'javascript:;'}],
   132 						['a', {id : id + '_resize_nw', 'class' : 'mceResize mceResizeNW', href : 'javascript:;'}],
   137 						['a', {id : id + '_resize_nw', 'class' : 'mceResize mceResizeNW', tabindex : '-1', href : 'javascript:;'}],
   133 						['a', {id : id + '_resize_ne', 'class' : 'mceResize mceResizeNE', href : 'javascript:;'}],
   138 						['a', {id : id + '_resize_ne', 'class' : 'mceResize mceResizeNE', tabindex : '-1', href : 'javascript:;'}],
   134 						['a', {id : id + '_resize_sw', 'class' : 'mceResize mceResizeSW', href : 'javascript:;'}],
   139 						['a', {id : id + '_resize_sw', 'class' : 'mceResize mceResizeSW', tabindex : '-1', href : 'javascript:;'}],
   135 						['a', {id : id + '_resize_se', 'class' : 'mceResize mceResizeSE', href : 'javascript:;'}]
   140 						['a', {id : id + '_resize_se', 'class' : 'mceResize mceResizeSE', tabindex : '-1', href : 'javascript:;'}]
   136 					]
   141 					]
   137 				]
   142 				]
   138 			);
   143 			);
   139 
   144 
   140 			DOM.setStyles(id, {top : -10000, left : -10000});
   145 			DOM.setStyles(id, {top : -10000, left : -10000});
   153 
   158 
   154 			// Resize window
   159 			// Resize window
   155 			DOM.setStyles(id, {top : f.top, left : f.left, width : f.width + dw, height : f.height + dh});
   160 			DOM.setStyles(id, {top : f.top, left : f.left, width : f.width + dw, height : f.height + dh});
   156 
   161 
   157 			u = f.url || f.file;
   162 			u = f.url || f.file;
   158 			if (tinymce.relaxedDomain)
   163 			if (u) {
   159 				u += (u.indexOf('?') == -1 ? '?' : '&') + 'mce_rdomain=' + tinymce.relaxedDomain;
   164 				if (tinymce.relaxedDomain)
       
   165 					u += (u.indexOf('?') == -1 ? '?' : '&') + 'mce_rdomain=' + tinymce.relaxedDomain;
       
   166 
       
   167 				u = tinymce._addVer(u);
       
   168 			}
   160 
   169 
   161 			if (!f.type) {
   170 			if (!f.type) {
   162 				DOM.add(id + '_content', 'iframe', {id : id + '_ifr', src : 'javascript:""', frameBorder : 0, style : 'border:0;width:10px;height:10px'});
   171 				DOM.add(id + '_content', 'iframe', {id : id + '_ifr', src : 'javascript:""', frameBorder : 0, style : 'border:0;width:10px;height:10px'});
   163 				DOM.setStyles(id + '_ifr', {width : f.width, height : f.height});
   172 				DOM.setStyles(id + '_ifr', {width : f.width, height : f.height});
   164 				DOM.setAttrib(id + '_ifr', 'src', u);
   173 				DOM.setAttrib(id + '_ifr', 'src', u);
   242 
   251 
   243 			w.iframeElement.on('focus', function() {
   252 			w.iframeElement.on('focus', function() {
   244 				t.focus(id);
   253 				t.focus(id);
   245 			});
   254 			});
   246 
   255 
       
   256 			// Setup blocker
       
   257 			if (t.count == 0 && t.editor.getParam('dialog_type') == 'modal') {
       
   258 				DOM.add(DOM.doc.body, 'div', {
       
   259 					id : 'mceModalBlocker',
       
   260 					'class' : (t.editor.settings.inlinepopups_skin || 'clearlooks2') + '_modalBlocker',
       
   261 					style : {left : vp.x, top : vp.y, zIndex : t.zIndex - 1}
       
   262 				});
       
   263 
       
   264 				DOM.show('mceModalBlocker'); // Reduces flicker in IE
       
   265 			} else
       
   266 				DOM.setStyle('mceModalBlocker', 'z-index', t.zIndex - 1);
       
   267 
   247 			t.focus(id);
   268 			t.focus(id);
   248 			t._fixIELayout(id, 1);
   269 			t._fixIELayout(id, 1);
   249 
   270 
   250 //			if (DOM.get(id + '_ok'))
   271 			// Focus ok button
   251 //				DOM.get(id + '_ok').focus();
   272 			if (DOM.get(id + '_ok'))
       
   273 				DOM.get(id + '_ok').focus();
       
   274 
       
   275 			t.count++;
   252 
   276 
   253 			return w;
   277 			return w;
   254 		},
   278 		},
   255 
   279 
   256 		focus : function(id) {
   280 		focus : function(id) {
   278 					t._addAll(te, ne[i]);
   302 					t._addAll(te, ne[i]);
   279 			}
   303 			}
   280 		},
   304 		},
   281 
   305 
   282 		_startDrag : function(id, se, ac) {
   306 		_startDrag : function(id, se, ac) {
   283 			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;
   307 			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;
   284 
   308 
   285 			// Get positons and sizes
   309 			// Get positons and sizes
   286 //			cp = DOM.getPos(t.editor.getContainer());
   310 //			cp = DOM.getPos(t.editor.getContainer());
   287 			cp = {x : 0, y : 0};
   311 			cp = {x : 0, y : 0};
   288 			vp = DOM.getViewPort();
   312 			vp = DOM.getViewPort();
   289 
   313 
   290 			// Reduce viewport size to avoid scrollbars
   314 			// Reduce viewport size to avoid scrollbars while dragging
   291 			vp.w -= 2;
   315 			vp.w -= 2;
   292 			vp.h -= 2;
   316 			vp.h -= 2;
   293 
   317 
   294 			sex = se.screenX;
   318 			sex = se.screenX;
   295 			sey = se.screenY;
   319 			sey = se.screenY;
   323 
   347 
   324 				// Setup event blocker
   348 				// Setup event blocker
   325 				DOM.add(d.body, 'div', {
   349 				DOM.add(d.body, 'div', {
   326 					id : 'mceEventBlocker',
   350 					id : 'mceEventBlocker',
   327 					'class' : 'mceEventBlocker ' + (t.editor.settings.inlinepopups_skin || 'clearlooks2'),
   351 					'class' : 'mceEventBlocker ' + (t.editor.settings.inlinepopups_skin || 'clearlooks2'),
   328 					style : {left : vp.x, top : vp.y, width : vp.w - 20, height : vp.h - 20, zIndex : 20001}
   352 					style : {left : vp.x, top : vp.y, zIndex : t.zIndex + 1}
   329 				});
   353 				});
   330 				eb = new Element('mceEventBlocker');
   354 				eb = new Element('mceEventBlocker');
   331 				eb.update();
   355 				eb.update();
   332 
   356 
   333 				// Setup placeholder
   357 				// Setup placeholder
   440 				w.iframeElement.resizeBy(dw, dh);
   464 				w.iframeElement.resizeBy(dw, dh);
   441 			}
   465 			}
   442 		},
   466 		},
   443 
   467 
   444 		close : function(win, id) {
   468 		close : function(win, id) {
   445 			var t = this, w, d = document, ix = 0, fw;
   469 			var t = this, w, d = DOM.doc, ix = 0, fw, id;
       
   470 
       
   471 			id = t._findId(id || win);
       
   472 
       
   473 			t.count--;
       
   474 
       
   475 			if (t.count == 0)
       
   476 				DOM.remove('mceModalBlocker');
   446 
   477 
   447 			// Probably not inline
   478 			// Probably not inline
   448 			if (!id && win) {
   479 			if (!id && win) {
   449 				t.parent(win);
   480 				t.parent(win);
   450 				return;
   481 				return;
   452 
   483 
   453 			if (w = t.windows[id]) {
   484 			if (w = t.windows[id]) {
   454 				t.onClose.dispatch(t);
   485 				t.onClose.dispatch(t);
   455 				Event.remove(d, 'mousedown', w.mousedownFunc);
   486 				Event.remove(d, 'mousedown', w.mousedownFunc);
   456 				Event.remove(d, 'click', w.clickFunc);
   487 				Event.remove(d, 'click', w.clickFunc);
       
   488 				Event.clear(id);
       
   489 				Event.clear(id + '_ifr');
   457 
   490 
   458 				DOM.setAttrib(id + '_ifr', 'src', 'javascript:""'); // Prevent leak
   491 				DOM.setAttrib(id + '_ifr', 'src', 'javascript:""'); // Prevent leak
   459 				w.element.remove();
   492 				w.element.remove();
   460 				delete t.windows[id];
   493 				delete t.windows[id];
   461 
   494 
   470 				if (fw)
   503 				if (fw)
   471 					t.focus(fw.id);
   504 					t.focus(fw.id);
   472 			}
   505 			}
   473 		},
   506 		},
   474 
   507 
   475 		setTitle : function(ti, id) {
   508 		setTitle : function(w, ti) {
   476 			DOM.get(id + '_title').innerHTML = DOM.encode(ti);
   509 			var e;
       
   510 
       
   511 			w = this._findId(w);
       
   512 
       
   513 			if (e = DOM.get(w + '_title'))
       
   514 				e.innerHTML = DOM.encode(ti);
   477 		},
   515 		},
   478 
   516 
   479 		alert : function(txt, cb, s) {
   517 		alert : function(txt, cb, s) {
   480 			var t = this, w;
   518 			var t = this, w;
   481 
   519 
   513 				height : 130
   551 				height : 130
   514 			});
   552 			});
   515 		},
   553 		},
   516 
   554 
   517 		// Internal functions
   555 		// Internal functions
       
   556 
       
   557 		_findId : function(w) {
       
   558 			var t = this;
       
   559 
       
   560 			if (typeof(w) == 'string')
       
   561 				return w;
       
   562 
       
   563 			each(t.windows, function(wo) {
       
   564 				var ifr = DOM.get(wo.id + '_ifr');
       
   565 
       
   566 				if (ifr && w == ifr.contentWindow) {
       
   567 					w = wo.id;
       
   568 					return false;
       
   569 				}
       
   570 			});
       
   571 
       
   572 			return w;
       
   573 		},
   518 
   574 
   519 		_fixIELayout : function(id, s) {
   575 		_fixIELayout : function(id, s) {
   520 			var w, img;
   576 			var w, img;
   521 
   577 
   522 			if (!tinymce.isIE6)
   578 			if (!tinymce.isIE6)