includes/clientside/tinymce/plugins/inlinepopups/editor_plugin_src.js
changeset 335 67bd3121a12e
parent 1 fe660c52c48f
child 395 fa4c5ecb7c9a
equal deleted inserted replaced
334:c72b545f1304 335:67bd3121a12e
     1 /**
     1 /**
     2  * $Id: editor_plugin_src.js 201 2007-02-12 15:56:56Z spocke $
     2  * $Id: editor_plugin_src.js 450 2007-11-27 13:42:19Z spocke $
     3  *
       
     4  * Moxiecode DHTML Windows script.
       
     5  *
     3  *
     6  * @author Moxiecode
     4  * @author Moxiecode
     7  * @copyright Copyright © 2004-2007, Moxiecode Systems AB, All rights reserved.
     5  * @copyright Copyright © 2004-2007, Moxiecode Systems AB, All rights reserved.
     8  */
     6  */
     9 
     7 
    10 // Patch openWindow, closeWindow TinyMCE functions
     8 (function() {
    11 
     9 	var DOM = tinymce.DOM, Element = tinymce.dom.Element, Event = tinymce.dom.Event, each = tinymce.each, is = tinymce.is;
    12 var TinyMCE_InlinePopupsPlugin = {
    10 
    13 	getInfo : function() {
    11 	tinymce.create('tinymce.plugins.InlinePopups', {
    14 		return {
    12 		init : function(ed, url) {
    15 			longname : 'Inline Popups',
    13 			// Replace window manager
    16 			author : 'Moxiecode Systems AB',
    14 			ed.onBeforeRenderUI.add(function() {
    17 			authorurl : 'http://tinymce.moxiecode.com',
    15 				ed.windowManager = new tinymce.InlineWindowManager(ed);
    18 			infourl : 'http://wiki.moxiecode.com/index.php/TinyMCE:Plugins/inlinepopups',
    16 				DOM.loadCSS(url + '/skins/' + (ed.settings.inlinepopups_skin || 'clearlooks2') + "/window.css");
    19 			version : tinyMCE.majorVersion + "." + tinyMCE.minorVersion
    17 			});
    20 		};
    18 		},
    21 	}
    19 
    22 };
    20 		getInfo : function() {
    23 
    21 			return {
    24 tinyMCE.addPlugin("inlinepopups", TinyMCE_InlinePopupsPlugin);
    22 				longname : 'InlinePopups',
    25 
    23 				author : 'Moxiecode Systems AB',
    26 // Patch openWindow, closeWindow TinyMCE functions
    24 				authorurl : 'http://tinymce.moxiecode.com',
    27 
    25 				infourl : 'http://wiki.moxiecode.com/index.php/TinyMCE:Plugins/inlinepopups',
    28 TinyMCE_Engine.prototype.orgOpenWindow = TinyMCE_Engine.prototype.openWindow;
    26 				version : tinymce.majorVersion + "." + tinymce.minorVersion
    29 TinyMCE_Engine.prototype.orgCloseWindow = TinyMCE_Engine.prototype.closeWindow;
    27 			};
    30 
       
    31 TinyMCE_Engine.prototype.openWindow = function(template, args) {
       
    32 	// Does the caller support inline
       
    33 	if (args['inline'] != "yes" || tinyMCE.isOpera || tinyMCE.getParam("plugins").indexOf('inlinepopups') == -1) {
       
    34 		mcWindows.selectedWindow = null;
       
    35 		args['mce_inside_iframe'] = false;
       
    36 		this.orgOpenWindow(template, args);
       
    37 		return;
       
    38 	}
       
    39 
       
    40 	var url, resizable, scrollbars;
       
    41 
       
    42 	args['mce_inside_iframe'] = true;
       
    43 	tinyMCE.windowArgs = args;
       
    44 
       
    45 	if (template['file'].charAt(0) != '/' && template['file'].indexOf('://') == -1)
       
    46 		url = tinyMCE.baseURL + "/themes/" + tinyMCE.getParam("theme") + "/" + template['file'];
       
    47 	else
       
    48 		url = template['file'];
       
    49 
       
    50 	if (!(width = parseInt(template['width'])))
       
    51 		width = 320;
       
    52 
       
    53 	if (!(height = parseInt(template['height'])))
       
    54 		height = 200;
       
    55 
       
    56 	if (!(minWidth = parseInt(template['minWidth'])))
       
    57 		minWidth = 100;
       
    58 
       
    59 	if (!(minHeight = parseInt(template['minHeight'])))
       
    60 		minHeight = 100;
       
    61 
       
    62 	resizable = (args && args['resizable']) ? args['resizable'] : "no";
       
    63 	scrollbars = (args && args['scrollbars']) ? args['scrollbars'] : "no";
       
    64 
       
    65 	height += 18;
       
    66 
       
    67 	// Replace all args as variables in URL
       
    68 	for (var name in args) {
       
    69 		if (typeof(args[name]) == 'function')
       
    70 			continue;
       
    71 
       
    72 		url = tinyMCE.replaceVar(url, name, escape(args[name]));
       
    73 	}
       
    74 
       
    75 	var elm = document.getElementById(this.selectedInstance.editorId + '_parent');
       
    76 
       
    77 	if (tinyMCE.hasPlugin('fullscreen') && this.selectedInstance.getData('fullscreen').enabled)
       
    78 		pos = { absLeft: 0, absTop: 0 };
       
    79 	else
       
    80 		pos = tinyMCE.getAbsPosition(elm);
       
    81 
       
    82 	// Center div in editor area
       
    83 	pos.absLeft += Math.round((elm.firstChild.clientWidth / 2) - (width / 2));
       
    84 	pos.absTop += Math.round((elm.firstChild.clientHeight / 2) - (height / 2));
       
    85 
       
    86 	mcWindows.open(url, mcWindows.idCounter++, "modal=yes,width=" + width+ ",height=" + height + ",resizable=" + resizable + ",scrollbars=" + scrollbars + ",statusbar=" + resizable + ",left=" + pos.absLeft + ",top=" + pos.absTop + ",minWidth=" + minWidth + ",minHeight=" + minHeight );
       
    87 };
       
    88 
       
    89 TinyMCE_Engine.prototype.closeWindow = function(win) {
       
    90 	var gotit = false, n, w;
       
    91 	for (n in mcWindows.windows) {
       
    92 		w = mcWindows.windows[n];
       
    93 		if (typeof(w) == 'function') continue;
       
    94 		if (win.name == w.id + '_iframe') {
       
    95 			w.close();
       
    96 			gotit = true;
       
    97 		}
    28 		}
    98 	}
    29 	});
    99 	if (!gotit)
    30 
   100 		this.orgCloseWindow(win);
    31 	tinymce.create('tinymce.InlineWindowManager:tinymce.WindowManager', {
   101 
    32 		InlineWindowManager : function(ed) {
   102 	tinyMCE.selectedInstance.getWin().focus(); 
    33 			var t = this;
   103 };
    34 
   104 
    35 			t.parent(ed);
   105 TinyMCE_Engine.prototype.setWindowTitle = function(win_ref, title) {
    36 			t.zIndex = 1000;
   106 	for (var n in mcWindows.windows) {
    37 		},
   107 		var win = mcWindows.windows[n];
    38 
   108 		if (typeof(win) == 'function')
    39 		open : function(f, p) {
   109 			continue;
    40 			var t = this, id, opt = '', ed = t.editor, dw = 0, dh = 0, vp, po, mdf, clf, we, w;
   110 
    41 
   111 		if (win_ref.name == win.id + "_iframe")
    42 			f = f || {};
   112 			window.frames[win.id + "_iframe"].document.getElementById(win.id + '_title').innerHTML = title;
    43 			p = p || {};
   113 	}
    44 
   114 };
    45 			// Run native windows
   115 
    46 			if (!f.inline)
   116 // * * * * * TinyMCE_Windows classes below
    47 				return t.parent(f, p);
   117 
    48 
   118 // Windows handler
    49 			t.bookmark = ed.selection.getBookmark('simple');
   119 function TinyMCE_Windows() {
    50 			id = DOM.uniqueId();
   120 	this.settings = new Array();
    51 			vp = DOM.getViewPort();
   121 	this.windows = new Array();
    52 			f.width = parseInt(f.width || 320);
   122 	this.isMSIE = (navigator.appName == "Microsoft Internet Explorer");
    53 			f.height = parseInt(f.height || 240) + (tinymce.isIE ? 8 : 0);
   123 	this.isGecko = navigator.userAgent.indexOf('Gecko') != -1;
    54 			f.min_width = parseInt(f.min_width || 150);
   124 	this.isSafari = navigator.userAgent.indexOf('Safari') != -1;
    55 			f.min_height = parseInt(f.min_height || 100);
   125 	this.isMac = navigator.userAgent.indexOf('Mac') != -1;
    56 			f.max_width = parseInt(f.max_width || 2000);
   126 	this.isMSIE5_0 = this.isMSIE && (navigator.userAgent.indexOf('MSIE 5.0') != -1);
    57 			f.max_height = parseInt(f.max_height || 2000);
   127 	this.action = "none";
    58 			f.left = f.left || Math.round(Math.max(vp.x, vp.x + (vp.w / 2.0) - (f.width / 2.0)));
   128 	this.selectedWindow = null;
    59 			f.top = f.top || Math.round(Math.max(vp.y, vp.y + (vp.h / 2.0) - (f.height / 2.0)));
   129 	this.lastSelectedWindow = null;
    60 			f.movable = f.resizable = true;
   130 	this.zindex = 1001;
    61 			p.mce_width = f.width;
   131 	this.mouseDownScreenX = 0;
    62 			p.mce_height = f.height;
   132 	this.mouseDownScreenY = 0;
    63 			p.mce_inline = true;
   133 	this.mouseDownLayerX = 0;
    64 			p.mce_window_id = id;
   134 	this.mouseDownLayerY = 0;
    65 
   135 	this.mouseDownWidth = 0;
    66 			// Transpose
   136 	this.mouseDownHeight = 0;
    67 //			po = DOM.getPos(ed.getContainer());
   137 	this.idCounter = 0;
    68 //			f.left -= po.x;
   138 };
    69 //			f.top -= po.y;
   139 
    70 
   140 TinyMCE_Windows.prototype.init = function(settings) {
    71 			t.features = f;
   141 	this.settings = settings;
    72 			t.params = p;
   142 
    73 			t.onOpen.dispatch(t, f, p);
   143 	if (this.isMSIE)
    74 
   144 		this.addEvent(document, "mousemove", mcWindows.eventDispatcher);
    75 			if (f.type) {
   145 	else
    76 				opt += ' modal ' + f.type;
   146 		this.addEvent(window, "mousemove", mcWindows.eventDispatcher);
    77 				f.resizable = false;
   147 
    78 			}
   148 	this.addEvent(document, "mouseup", mcWindows.eventDispatcher);
    79 
   149 
    80 			if (f.statusbar)
   150 	this.addEvent(window, "resize", mcWindows.eventDispatcher);
    81 				opt += ' statusbar';
   151 	this.addEvent(document, "scroll", mcWindows.eventDispatcher);
    82 
   152 
    83 			if (f.resizable)
   153 	this.doc = document;
    84 				opt += ' resizable';
   154 };
    85 
   155 
    86 			if (f.minimizable)
   156 TinyMCE_Windows.prototype.getBounds = function() {
    87 				opt += ' minimizable';
   157 	if (!this.bounds) {
    88 
   158 		var vp = tinyMCE.getViewPort(window);
    89 			if (f.maximizable)
   159 		var top, left, bottom, right, docEl = this.doc.documentElement;
    90 				opt += ' maximizable';
   160 
    91 
   161 		top    = vp.top;
    92 			if (f.movable)
   162 		left   = vp.left;
    93 				opt += ' movable';
   163 		bottom = vp.height + top - 2;
    94 
   164 		right  = vp.width  + left - 22; // TODO this number is platform dependant
    95 			// Create DOM objects
   165 		// x1, y1, x2, y2
    96 			t._addAll(document.body, 
   166 		this.bounds = [left, top, right, bottom];
    97 				['div', {id : id, 'class' : ed.settings.inlinepopups_skin || 'clearlooks2', style : 'width:100px;height:100px'}, 
   167 	}
    98 					['div', {id : id + '_wrapper', 'class' : 'wrapper' + opt},
   168 	return this.bounds;
    99 						['div', {id : id + '_top', 'class' : 'top'}, 
   169 };
   100 							['div', {'class' : 'left'}],
   170 
   101 							['div', {'class' : 'center'}],
   171 TinyMCE_Windows.prototype.clampBoxPosition = function(x, y, w, h, minW, minH) {
   102 							['div', {'class' : 'right'}],
   172 	var bounds = this.getBounds();
   103 							['span', {id : id + '_title'}, f.title || '']
   173 
   104 						],
   174 	x = Math.max(bounds[0], Math.min(bounds[2], x + w) - w);
   105 
   175 	y = Math.max(bounds[1], Math.min(bounds[3], y + h) - h);
   106 						['div', {id : id + '_middle', 'class' : 'middle'}, 
   176 
   107 							['div', {id : id + '_left', 'class' : 'left'}],
   177 	return this.clampBoxSize(x, y, w, h, minW, minH);
   108 							['span', {id : id + '_content'}],
   178 };
   109 							['div', {id : id + '_right', 'class' : 'right'}]
   179 
   110 						],
   180 TinyMCE_Windows.prototype.clampBoxSize = function(x, y, w, h, minW, minH) {
   111 
   181 	var bounds = this.getBounds();
   112 						['div', {id : id + '_bottom', 'class' : 'bottom'},
   182 
   113 							['div', {'class' : 'left'}],
   183 	return [
   114 							['div', {'class' : 'center'}],
   184 		x, y,
   115 							['div', {'class' : 'right'}],
   185 		Math.max(minW, Math.min(bounds[2], x + w) - x),
   116 							['span', {id : id + '_status'}, 'Content']
   186 		Math.max(minH, Math.min(bounds[3], y + h) - y)
   117 						],
   187 	];
   118 
   188 };
   119 						['a', {'class' : 'move', href : 'javascript:;'}],
   189 
   120 						['a', {'class' : 'min', href : 'javascript:;', onmousedown : 'return false;'}],
   190 TinyMCE_Windows.prototype.getParam = function(name, default_value) {
   121 						['a', {'class' : 'max', href : 'javascript:;', onmousedown : 'return false;'}],
   191 	var value = null;
   122 						['a', {'class' : 'med', href : 'javascript:;', onmousedown : 'return false;'}],
   192 
   123 						['a', {'class' : 'close', href : 'javascript:;', onmousedown : 'return false;'}],
   193 	value = (typeof(this.settings[name]) == "undefined") ? default_value : this.settings[name];
   124 						['a', {id : id + '_resize_n', 'class' : 'resize resize-n', href : 'javascript:;'}],
   194 
   125 						['a', {id : id + '_resize_s', 'class' : 'resize resize-s', href : 'javascript:;'}],
   195 	// Fix bool values
   126 						['a', {id : id + '_resize_w', 'class' : 'resize resize-w', href : 'javascript:;'}],
   196 	if (value == "true" || value == "false")
   127 						['a', {id : id + '_resize_e', 'class' : 'resize resize-e', href : 'javascript:;'}],
   197 		return (value == "true");
   128 						['a', {id : id + '_resize_nw', 'class' : 'resize resize-nw', href : 'javascript:;'}],
   198 
   129 						['a', {id : id + '_resize_ne', 'class' : 'resize resize-ne', href : 'javascript:;'}],
   199 	return value;
   130 						['a', {id : id + '_resize_sw', 'class' : 'resize resize-sw', href : 'javascript:;'}],
   200 };
   131 						['a', {id : id + '_resize_se', 'class' : 'resize resize-se', href : 'javascript:;'}]
   201 
   132 					]
   202 TinyMCE_Windows.prototype.eventDispatcher = function(e) {
   133 				]
   203 	e = typeof(e) == "undefined" ? window.event : e;
   134 			);
   204 
   135 
   205 	if (mcWindows.selectedWindow == null)
   136 			DOM.setStyles(id, {top : -10000, left : -10000});
   206 		return;
   137 
   207 
   138 			// Fix gecko rendering bug, where the editors iframe messed with window contents
   208 	// Switch focus
   139 			if (tinymce.isGecko)
   209 	if (mcWindows.isGecko && e.type == "mousedown") {
   140 				DOM.setStyle(id, 'overflow', 'auto');
   210 		var elm = e.currentTarget;
   141 
   211 
   142 			// Measure borders
   212 		for (var n in mcWindows.windows) {
   143 			if (!f.type) {
   213 			var win = mcWindows.windows[n];
   144 				dw += DOM.get(id + '_left').clientWidth;
   214 
   145 				dw += DOM.get(id + '_right').clientWidth;
   215 			if (win.headElement == elm || win.resizeElement == elm) {
   146 				dh += DOM.get(id + '_top').clientHeight;
   216 				win.focus();
   147 				dh += DOM.get(id + '_bottom').clientHeight;
   217 				break;
   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 : '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') {
       
   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') {
       
   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 = '';
   218 			}
   552 			}
   219 		}
   553 		}
   220 	}
   554 	});
   221 
   555 
   222 	switch (e.type) {
   556 	// Register plugin
   223 		case "mousemove":
   557 	tinymce.PluginManager.add('inlinepopups', tinymce.plugins.InlinePopups);
   224 			mcWindows.selectedWindow.onMouseMove(e);
   558 })();
   225 			break;
   559 
   226 
       
   227 		case "mouseup":
       
   228 			mcWindows.selectedWindow.onMouseUp(e);
       
   229 			break;
       
   230 
       
   231 		case "mousedown":
       
   232 			mcWindows.selectedWindow.onMouseDown(e);
       
   233 			break;
       
   234 
       
   235 		case "focus":
       
   236 			mcWindows.selectedWindow.onFocus(e);
       
   237 			break;
       
   238 		case "scroll":
       
   239 		case "resize":
       
   240 			if (mcWindows.clampUpdateTimeout)
       
   241 				clearTimeout(mcWindows.clampUpdateTimeout);
       
   242 			mcWindows.clampEventType = e.type;
       
   243 			mcWindows.clampUpdateTimeout =
       
   244 				setTimeout(function () {mcWindows.updateClamping()}, 100);
       
   245 			break;
       
   246 	}
       
   247 };
       
   248 
       
   249 TinyMCE_Windows.prototype.updateClamping = function () {
       
   250 	var clamp, oversize, etype = mcWindows.clampEventType;
       
   251 
       
   252 	this.bounds = null; // Recalc window bounds on resize/scroll
       
   253 	this.clampUpdateTimeout = null;
       
   254 
       
   255 	for (var n in this.windows) {
       
   256 		win = this.windows[n];
       
   257 		if (typeof(win) == 'function' || ! win.winElement) continue;
       
   258 
       
   259 		clamp = mcWindows.clampBoxPosition(
       
   260 			win.left, win.top,
       
   261 			win.winElement.scrollWidth,
       
   262 			win.winElement.scrollHeight,
       
   263 			win.features.minWidth,
       
   264 			win.features.minHeight
       
   265 		);
       
   266 		oversize = (
       
   267 			clamp[2] != win.winElement.scrollWidth ||
       
   268 			clamp[3] != win.winElement.scrollHeight
       
   269 		) ? true : false;
       
   270 
       
   271 		if (!oversize || win.features.resizable == "yes" || etype != "scroll")
       
   272 			win.moveTo(clamp[0], clamp[1]);
       
   273 		if (oversize && win.features.resizable == "yes")
       
   274 			win.resizeTo(clamp[2], clamp[3]);
       
   275 	}
       
   276 };
       
   277 
       
   278 TinyMCE_Windows.prototype.addEvent = function(obj, name, handler) {
       
   279 	if (this.isMSIE)
       
   280 		obj.attachEvent("on" + name, handler);
       
   281 	else
       
   282 		obj.addEventListener(name, handler, false);
       
   283 };
       
   284 
       
   285 TinyMCE_Windows.prototype.cancelEvent = function(e) {
       
   286 	if (this.isMSIE) {
       
   287 		e.returnValue = false;
       
   288 		e.cancelBubble = true;
       
   289 	} else
       
   290 		e.preventDefault();
       
   291 };
       
   292 
       
   293 TinyMCE_Windows.prototype.parseFeatures = function(opts) {
       
   294 	// Cleanup the options
       
   295 	opts = opts.toLowerCase();
       
   296 	opts = opts.replace(/;/g, ",");
       
   297 	opts = opts.replace(/[^0-9a-z=,]/g, "");
       
   298 
       
   299 	var optionChunks = opts.split(',');
       
   300 	var options = new Array();
       
   301 
       
   302 	options['left'] = "10";
       
   303 	options['top'] = "10";
       
   304 	options['width'] = "300";
       
   305 	options['height'] = "300";
       
   306 	options['minwidth'] = "100";
       
   307 	options['minheight'] = "100";
       
   308 	options['resizable'] = "yes";
       
   309 	options['minimizable'] = "yes";
       
   310 	options['maximizable'] = "yes";
       
   311 	options['close'] = "yes";
       
   312 	options['movable'] = "yes";
       
   313 	options['statusbar'] = "yes";
       
   314 	options['scrollbars'] = "auto";
       
   315 	options['modal'] = "no";
       
   316 
       
   317 	if (opts == "")
       
   318 		return options;
       
   319 
       
   320 	for (var i=0; i<optionChunks.length; i++) {
       
   321 		var parts = optionChunks[i].split('=');
       
   322 
       
   323 		if (parts.length == 2)
       
   324 			options[parts[0]] = parts[1];
       
   325 	}
       
   326 
       
   327 	options['left'] = parseInt(options['left']);
       
   328 	options['top'] = parseInt(options['top']);
       
   329 	options['width'] = parseInt(options['width']);
       
   330 	options['height'] = parseInt(options['height']);
       
   331 	options['minWidth'] = parseInt(options['minwidth']);
       
   332 	options['minHeight'] = parseInt(options['minheight']);
       
   333 
       
   334 	return options;
       
   335 };
       
   336 
       
   337 TinyMCE_Windows.prototype.open = function(url, name, features) {
       
   338 	this.lastSelectedWindow = this.selectedWindow;
       
   339 
       
   340 	var win = new TinyMCE_Window();
       
   341 	var winDiv, html = "", id;
       
   342 	var imgPath = this.getParam("images_path");
       
   343 
       
   344 	features = this.parseFeatures(features);
       
   345 
       
   346 	// Clamp specified dimensions
       
   347 	var clamp = mcWindows.clampBoxPosition(
       
   348 		features['left'], features['top'],
       
   349 		features['width'], features['height'],
       
   350 		features['minWidth'], features['minHeight']
       
   351 	);
       
   352 
       
   353 	features['left'] = clamp[0];
       
   354 	features['top'] = clamp[1];
       
   355 
       
   356 	if (features['resizable'] == "yes") {
       
   357 		features['width'] = clamp[2];
       
   358 		features['height'] = clamp[3];
       
   359 	}
       
   360 
       
   361 	// Create div
       
   362 	id = "mcWindow_" + name;
       
   363 	win.deltaHeight = 18;
       
   364 
       
   365 	if (features['statusbar'] == "yes") {
       
   366 		win.deltaHeight += 13;
       
   367 
       
   368 		if (this.isMSIE)
       
   369 			win.deltaHeight += 1;
       
   370 	}
       
   371 
       
   372 	width = parseInt(features['width']);
       
   373 	height = parseInt(features['height'])-win.deltaHeight;
       
   374 
       
   375 	if (this.isMSIE)
       
   376 		width -= 2;
       
   377 
       
   378 	// Setup first part of window
       
   379 	win.id = id;
       
   380 	win.url = url;
       
   381 	win.name = name;
       
   382 	win.features = features;
       
   383 	this.windows[name] = win;
       
   384 
       
   385 	iframeWidth = width;
       
   386 	iframeHeight = height;
       
   387 
       
   388 	// Create inner content
       
   389 	html += '<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">';
       
   390 	html += '<html>';
       
   391 	html += '<head>';
       
   392 	html += '<title>Wrapper iframe</title>';
       
   393 	html += '<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">';
       
   394 	html += '<link href="' + this.getParam("css_file") + '" rel="stylesheet" type="text/css" />';
       
   395 	html += '</head>';
       
   396 	html += '<body onload="parent.mcWindows.onLoad(\'' + name + '\');">';
       
   397 
       
   398 	html += '<div id="' + id + '_container" class="mceWindow">';
       
   399 	html += '<div id="' + id + '_head" class="mceWindowHead" onmousedown="parent.mcWindows.windows[\'' + name + '\'].focus();">';
       
   400 	html += '  <div id="' + id + '_title" class="mceWindowTitle"';
       
   401 	html += '  onselectstart="return false;" unselectable="on" style="-moz-user-select: none !important;"></div>';
       
   402 	html += '    <div class="mceWindowHeadTools">';
       
   403 	html += '      <a href="javascript:parent.mcWindows.windows[\'' + name + '\'].close();" target="_self" onmousedown="return false;" class="mceWindowClose"><img border="0" src="' + imgPath + '/window_close.gif" /></a>';
       
   404 	if (features['resizable'] == "yes" && features['maximizable'] == "yes")
       
   405 		html += '      <a href="javascript:parent.mcWindows.windows[\'' + name + '\'].maximize();" target="_self" onmousedown="return false;" class="mceWindowMaximize"><img border="0" src="' + imgPath + '/window_maximize.gif" /></a>';
       
   406 	// html += '      <a href="javascript:mcWindows.windows[\'' + name + '\'].minimize();" target="_self" onmousedown="return false;" class="mceWindowMinimize"></a>';
       
   407 	html += '    </div>';
       
   408 	html += '</div><div id="' + id + '_body" class="mceWindowBody" style="width: ' + width + 'px; height: ' + height + 'px;">';
       
   409 	html += '<iframe id="' + id + '_iframe" name="' + id + '_iframe" frameborder="0" width="' + iframeWidth + '" height="' + iframeHeight + '" src="' + url + '" class="mceWindowBodyIframe" scrolling="' + features['scrollbars'] + '"></iframe></div>';
       
   410 
       
   411 	if (features['statusbar'] == "yes") {
       
   412 		html += '<div id="' + id + '_statusbar" class="mceWindowStatusbar" onmousedown="parent.mcWindows.windows[\'' + name + '\'].focus();">';
       
   413 
       
   414 		if (features['resizable'] == "yes") {
       
   415 			if (this.isGecko)
       
   416 				html += '<div id="' + id + '_resize" class="mceWindowResize"><div style="background-image: url(\'' + imgPath + '/window_resize.gif\'); width: 12px; height: 12px;"></div></div>';
       
   417 			else
       
   418 				html += '<div id="' + id + '_resize" class="mceWindowResize"><img onmousedown="parent.mcWindows.windows[\'' + name + '\'].focus();" border="0" src="' + imgPath + '/window_resize.gif" /></div>';
       
   419 		}
       
   420 
       
   421 		html += '</div>';
       
   422 	}
       
   423 
       
   424 	html += '</div>';
       
   425 
       
   426 	html += '</body>';
       
   427 	html += '</html>';
       
   428 
       
   429 	// Create iframe
       
   430 	this.createFloatingIFrame(id, features['left'], features['top'], features['width'], features['height'], html);
       
   431 };
       
   432 
       
   433 // Blocks the document events by placing a image over the whole document
       
   434 TinyMCE_Windows.prototype.setDocumentLock = function(state) {
       
   435 	var elm = document.getElementById('mcWindowEventBlocker');
       
   436 
       
   437 	if (state) {
       
   438 		if (elm == null) {
       
   439 			elm = document.createElement("div");
       
   440 
       
   441 			elm.id = "mcWindowEventBlocker";
       
   442 			elm.style.position = "absolute";
       
   443 			elm.style.left = "0";
       
   444 			elm.style.top = "0";
       
   445 
       
   446 			document.body.appendChild(elm);
       
   447 		}
       
   448 
       
   449 		elm.style.display = "none";
       
   450 
       
   451 		var imgPath = this.getParam("images_path");
       
   452 		var width = document.body.clientWidth;
       
   453 		var height = document.body.clientHeight;
       
   454 
       
   455 		elm.style.width = width;
       
   456 		elm.style.height = height;
       
   457 		elm.innerHTML = '<img src="' + imgPath + '/spacer.gif" width="' + width + '" height="' + height + '" />';
       
   458 
       
   459 		elm.style.zIndex = mcWindows.zindex-1;
       
   460 		elm.style.display = "block";
       
   461 	} else if (elm != null) {
       
   462 		if (mcWindows.windows.length == 0)
       
   463 			elm.parentNode.removeChild(elm);
       
   464 		else
       
   465 			elm.style.zIndex = mcWindows.zindex-1;
       
   466 	}
       
   467 };
       
   468 
       
   469 // Gets called when wrapper iframe is initialized
       
   470 TinyMCE_Windows.prototype.onLoad = function(name) {
       
   471 	var win = mcWindows.windows[name];
       
   472 	var id = "mcWindow_" + name;
       
   473 	var wrapperIframe = window.frames[id + "_iframe"].frames[0];
       
   474 	var wrapperDoc = window.frames[id + "_iframe"].document;
       
   475 	var doc = window.frames[id + "_iframe"].document;
       
   476 	var winDiv = document.getElementById("mcWindow_" + name + "_div");
       
   477 	var realIframe = window.frames[id + "_iframe"].frames[0];
       
   478 
       
   479 	// Set window data
       
   480 	win.id = "mcWindow_" + name;
       
   481 	win.winElement = winDiv;
       
   482 	win.bodyElement = doc.getElementById(id + '_body');
       
   483 	win.iframeElement = doc.getElementById(id + '_iframe');
       
   484 	win.headElement = doc.getElementById(id + '_head');
       
   485 	win.titleElement = doc.getElementById(id + '_title');
       
   486 	win.resizeElement = doc.getElementById(id + '_resize');
       
   487 	win.containerElement = doc.getElementById(id + '_container');
       
   488 	win.left = win.features['left'];
       
   489 	win.top = win.features['top'];
       
   490 	win.frame = window.frames[id + '_iframe'].frames[0];
       
   491 	win.wrapperFrame = window.frames[id + '_iframe'];
       
   492 	win.wrapperIFrameElement = document.getElementById(id + "_iframe");
       
   493 
       
   494 	// Add event handlers
       
   495 	mcWindows.addEvent(win.headElement, "mousedown", mcWindows.eventDispatcher);
       
   496 
       
   497 	if (win.resizeElement != null)
       
   498 		mcWindows.addEvent(win.resizeElement, "mousedown", mcWindows.eventDispatcher);
       
   499 
       
   500 	if (mcWindows.isMSIE) {
       
   501 		mcWindows.addEvent(realIframe.document, "mousemove", mcWindows.eventDispatcher);
       
   502 		mcWindows.addEvent(realIframe.document, "mouseup", mcWindows.eventDispatcher);
       
   503 	} else {
       
   504 		mcWindows.addEvent(realIframe, "mousemove", mcWindows.eventDispatcher);
       
   505 		mcWindows.addEvent(realIframe, "mouseup", mcWindows.eventDispatcher);
       
   506 		mcWindows.addEvent(realIframe, "focus", mcWindows.eventDispatcher);
       
   507 	}
       
   508 
       
   509 	for (var i=0; i<window.frames.length; i++) {
       
   510 		if (!window.frames[i]._hasMouseHandlers) {
       
   511 			if (mcWindows.isMSIE) {
       
   512 				mcWindows.addEvent(window.frames[i].document, "mousemove", mcWindows.eventDispatcher);
       
   513 				mcWindows.addEvent(window.frames[i].document, "mouseup", mcWindows.eventDispatcher);
       
   514 			} else {
       
   515 				mcWindows.addEvent(window.frames[i], "mousemove", mcWindows.eventDispatcher);
       
   516 				mcWindows.addEvent(window.frames[i], "mouseup", mcWindows.eventDispatcher);
       
   517 			}
       
   518 
       
   519 			window.frames[i]._hasMouseHandlers = true;
       
   520 		}
       
   521 	}
       
   522 
       
   523 	if (mcWindows.isMSIE) {
       
   524 		mcWindows.addEvent(win.frame.document, "mousemove", mcWindows.eventDispatcher);
       
   525 		mcWindows.addEvent(win.frame.document, "mouseup", mcWindows.eventDispatcher);
       
   526 	} else {
       
   527 		mcWindows.addEvent(win.frame, "mousemove", mcWindows.eventDispatcher);
       
   528 		mcWindows.addEvent(win.frame, "mouseup", mcWindows.eventDispatcher);
       
   529 		mcWindows.addEvent(win.frame, "focus", mcWindows.eventDispatcher);
       
   530 	}
       
   531 
       
   532 	// Dispatch open window event
       
   533 	var func = this.getParam("on_open_window", "");
       
   534 	if (func != "")
       
   535 		eval(func + "(win);");
       
   536 
       
   537 	win.focus();
       
   538 
       
   539 	if (win.features['modal'] == "yes")
       
   540 		mcWindows.setDocumentLock(true);
       
   541 };
       
   542 
       
   543 TinyMCE_Windows.prototype.createFloatingIFrame = function(id_prefix, left, top, width, height, html) {
       
   544 	var iframe = document.createElement("iframe");
       
   545 	var div = document.createElement("div"), doc;
       
   546 
       
   547 	width = parseInt(width);
       
   548 	height = parseInt(height)+1;
       
   549 
       
   550 	// Create wrapper div
       
   551 	div.setAttribute("id", id_prefix + "_div");
       
   552 	div.setAttribute("width", width);
       
   553 	div.setAttribute("height", (height));
       
   554 	div.style.position = "absolute";
       
   555 
       
   556 	div.style.left = left + "px";
       
   557 	div.style.top = top + "px";
       
   558 	div.style.width = width + "px";
       
   559 	div.style.height = (height) + "px";
       
   560 	div.style.backgroundColor = "white";
       
   561 	div.style.display = "none";
       
   562 
       
   563 	if (this.isGecko) {
       
   564 		iframeWidth = width + 2;
       
   565 		iframeHeight = height + 2;
       
   566 	} else {
       
   567 		iframeWidth = width;
       
   568 		iframeHeight = height + 1;
       
   569 	}
       
   570 
       
   571 	// Create iframe
       
   572 	iframe.setAttribute("id", id_prefix + "_iframe");
       
   573 	iframe.setAttribute("name", id_prefix + "_iframe");
       
   574 	iframe.setAttribute("border", "0");
       
   575 	iframe.setAttribute("frameBorder", "0");
       
   576 	iframe.setAttribute("marginWidth", "0");
       
   577 	iframe.setAttribute("marginHeight", "0");
       
   578 	iframe.setAttribute("leftMargin", "0");
       
   579 	iframe.setAttribute("topMargin", "0");
       
   580 	iframe.setAttribute("width", iframeWidth);
       
   581 	iframe.setAttribute("height", iframeHeight);
       
   582 	// iframe.setAttribute("src", "../jscripts/tiny_mce/blank.htm");
       
   583 	// iframe.setAttribute("allowtransparency", "false");
       
   584 	iframe.setAttribute("scrolling", "no");
       
   585 	iframe.style.width = iframeWidth + "px";
       
   586 	iframe.style.height = iframeHeight + "px";
       
   587 	iframe.style.backgroundColor = "white";
       
   588 	div.appendChild(iframe);
       
   589 
       
   590 	document.body.appendChild(div);
       
   591 
       
   592 	// Fixed MSIE 5.0 issue
       
   593 	div.innerHTML = div.innerHTML;
       
   594 
       
   595 	if (this.isSafari) {
       
   596 		// Give Safari some time to setup
       
   597 		window.setTimeout(function() {
       
   598 			var doc = window.frames[id_prefix + '_iframe'].document;
       
   599 			doc.open();
       
   600 			doc.write(html);
       
   601 			doc.close();
       
   602 		}, 10);
       
   603 	} else {
       
   604 		doc = window.frames[id_prefix + '_iframe'].window.document;
       
   605 		doc.open();
       
   606 		doc.write(html);
       
   607 		doc.close();
       
   608 	}
       
   609 
       
   610 	div.style.display = "block";
       
   611 
       
   612 	return div;
       
   613 };
       
   614 
       
   615 // Window instance
       
   616 function TinyMCE_Window() {
       
   617 };
       
   618 
       
   619 TinyMCE_Window.prototype.focus = function() {
       
   620 	if (this != mcWindows.selectedWindow) {
       
   621 		this.winElement.style.zIndex = ++mcWindows.zindex;
       
   622 		mcWindows.lastSelectedWindow = mcWindows.selectedWindow;
       
   623 		mcWindows.selectedWindow = this;
       
   624 	}
       
   625 };
       
   626 
       
   627 TinyMCE_Window.prototype.minimize = function() {
       
   628 };
       
   629 
       
   630 TinyMCE_Window.prototype.maximize = function() {
       
   631 	if (this.restoreSize) {
       
   632 		this.moveTo(this.restoreSize[0], this.restoreSize[1]);
       
   633 		this.resizeTo(this.restoreSize[2], this.restoreSize[3]);
       
   634 		this.updateClamping();
       
   635 		this.restoreSize = null;
       
   636 	} else {
       
   637 		var bounds = mcWindows.getBounds();
       
   638 		this.restoreSize = [
       
   639 			this.left, this.top,
       
   640 			this.winElement.scrollWidth,
       
   641 			this.winElement.scrollHeight
       
   642 		];
       
   643 		this.moveTo(bounds[0], bounds[1]);
       
   644 		this.resizeTo(
       
   645 			bounds[2] - bounds[0],
       
   646 			bounds[3] - bounds[1]
       
   647 		);
       
   648 	}
       
   649 };
       
   650 
       
   651 TinyMCE_Window.prototype.startResize = function() {
       
   652 	mcWindows.action = "resize";
       
   653 };
       
   654 
       
   655 TinyMCE_Window.prototype.startMove = function(e) {
       
   656 	mcWindows.action = "move";
       
   657 };
       
   658 
       
   659 TinyMCE_Window.prototype.close = function() {
       
   660 	if (this.frame && this.frame['tinyMCEPopup'])
       
   661 		this.frame['tinyMCEPopup'].restoreSelection();
       
   662 
       
   663 	if (mcWindows.lastSelectedWindow != null)
       
   664 		mcWindows.lastSelectedWindow.focus();
       
   665 
       
   666 	var mcWindowsNew = new Array();
       
   667 	for (var n in mcWindows.windows) {
       
   668 		var win = mcWindows.windows[n];
       
   669 		if (typeof(win) == 'function')
       
   670 			continue;
       
   671 
       
   672 		if (win.name != this.name)
       
   673 			mcWindowsNew[n] = win;
       
   674 	}
       
   675 
       
   676 	mcWindows.windows = mcWindowsNew;
       
   677 
       
   678 	// alert(mcWindows.doc.getElementById(this.id + "_iframe"));
       
   679 
       
   680 	var e = mcWindows.doc.getElementById(this.id + "_iframe");
       
   681 	e.parentNode.removeChild(e);
       
   682 
       
   683 	var e = mcWindows.doc.getElementById(this.id + "_div");
       
   684 	e.parentNode.removeChild(e);
       
   685 
       
   686 	mcWindows.setDocumentLock(false);
       
   687 };
       
   688 
       
   689 TinyMCE_Window.prototype.onMouseMove = function(e) {
       
   690 	var clamp;
       
   691 	// Calculate real X, Y
       
   692 	var dx = e.screenX - mcWindows.mouseDownScreenX;
       
   693 	var dy = e.screenY - mcWindows.mouseDownScreenY;
       
   694 
       
   695 	switch (mcWindows.action) {
       
   696 		case "resize":
       
   697 			clamp = mcWindows.clampBoxSize(
       
   698 				this.left, this.top,
       
   699 				mcWindows.mouseDownWidth + (e.screenX - mcWindows.mouseDownScreenX),
       
   700 				mcWindows.mouseDownHeight + (e.screenY - mcWindows.mouseDownScreenY),
       
   701 				this.features.minWidth, this.features.minHeight
       
   702 			);
       
   703 
       
   704 			this.resizeTo(clamp[2], clamp[3]);
       
   705 
       
   706 			mcWindows.cancelEvent(e);
       
   707 			break;
       
   708 
       
   709 		case "move":
       
   710 			this.left = mcWindows.mouseDownLayerX + (e.screenX - mcWindows.mouseDownScreenX);
       
   711 			this.top = mcWindows.mouseDownLayerY + (e.screenY - mcWindows.mouseDownScreenY);
       
   712 			this.updateClamping();
       
   713 
       
   714 			mcWindows.cancelEvent(e);
       
   715 			break;
       
   716 	}
       
   717 };
       
   718 
       
   719 TinyMCE_Window.prototype.moveTo = function (x, y) {
       
   720 	this.left = x;
       
   721 	this.top = y;
       
   722 
       
   723 	this.winElement.style.left = this.left + "px";
       
   724 	this.winElement.style.top = this.top + "px";
       
   725 };
       
   726 
       
   727 TinyMCE_Window.prototype.resizeTo = function (width, height) {
       
   728 	this.wrapperIFrameElement.style.width = (width+2) + 'px';
       
   729 	this.wrapperIFrameElement.style.height = (height+2) + 'px';
       
   730 	this.wrapperIFrameElement.width = width+2;
       
   731 	this.wrapperIFrameElement.height = height+2;
       
   732 	this.winElement.style.width = width + 'px';
       
   733 	this.winElement.style.height = height + 'px';
       
   734 
       
   735 	height = height - this.deltaHeight;
       
   736 
       
   737 	this.containerElement.style.width = width + 'px';
       
   738 	this.iframeElement.style.width = width + 'px';
       
   739 	this.iframeElement.style.height = height + 'px';
       
   740 	this.bodyElement.style.width = width + 'px';
       
   741 	this.bodyElement.style.height = height + 'px';
       
   742 	this.headElement.style.width = width + 'px';
       
   743 	//this.statusElement.style.width = width + 'px';
       
   744 };
       
   745 
       
   746 TinyMCE_Window.prototype.updateClamping = function () {
       
   747 	var clamp, oversize;
       
   748 
       
   749 	clamp = mcWindows.clampBoxPosition(
       
   750 		this.left, this.top,
       
   751 		this.winElement.scrollWidth,
       
   752 		this.winElement.scrollHeight,
       
   753 		this.features.minWidth, this.features.minHeight
       
   754 	);
       
   755 	oversize = (
       
   756 		clamp[2] != this.winElement.scrollWidth ||
       
   757 		clamp[3] != this.winElement.scrollHeight
       
   758 	) ? true : false;
       
   759 
       
   760 	this.moveTo(clamp[0], clamp[1]);
       
   761 	if (this.features.resizable == "yes" && oversize)
       
   762 		this.resizeTo(clamp[2], clamp[3]);
       
   763 };
       
   764 
       
   765 function debug(msg) {
       
   766 	document.getElementById('debug').value += msg + "\n";
       
   767 }
       
   768 
       
   769 TinyMCE_Window.prototype.onMouseUp = function(e) {
       
   770 	mcWindows.action = "none";
       
   771 };
       
   772 
       
   773 TinyMCE_Window.prototype.onFocus = function(e) {
       
   774 	// Gecko only handler
       
   775 	var winRef = e.currentTarget;
       
   776 
       
   777 	for (var n in mcWindows.windows) {
       
   778 		var win = mcWindows.windows[n];
       
   779 		if (typeof(win) == 'function')
       
   780 			continue;
       
   781 
       
   782 		if (winRef.name == win.id + "_iframe") {
       
   783 			win.focus();
       
   784 			return;
       
   785 		}
       
   786 	}
       
   787 };
       
   788 
       
   789 TinyMCE_Window.prototype.onMouseDown = function(e) {
       
   790 	var elm = mcWindows.isMSIE ? this.wrapperFrame.event.srcElement : e.target;
       
   791 
       
   792 	mcWindows.mouseDownScreenX = e.screenX;
       
   793 	mcWindows.mouseDownScreenY = e.screenY;
       
   794 	mcWindows.mouseDownLayerX = this.left;
       
   795 	mcWindows.mouseDownLayerY = this.top;
       
   796 	mcWindows.mouseDownWidth = parseInt(this.winElement.style.width);
       
   797 	mcWindows.mouseDownHeight = parseInt(this.winElement.style.height);
       
   798 
       
   799 	if (this.resizeElement != null && elm == this.resizeElement.firstChild)
       
   800 		this.startResize(e);
       
   801 	else
       
   802 		this.startMove(e);
       
   803 
       
   804 	mcWindows.cancelEvent(e);
       
   805 };
       
   806 
       
   807 // Global instance
       
   808 var mcWindows = new TinyMCE_Windows();
       
   809 
       
   810 // Initialize windows
       
   811 mcWindows.init({
       
   812 	images_path : tinyMCE.baseURL + "/plugins/inlinepopups/images",
       
   813 	css_file : tinyMCE.baseURL + "/plugins/inlinepopups/css/inlinepopup.css"
       
   814 });