app/tiny_mce/themes/advanced/editor_template_src.js
changeset 154 d2377425d3f2
parent 126 6186c115a210
equal deleted inserted replaced
153:79d52c2d50a2 154:d2377425d3f2
       
     1 /**
       
     2  * $Id: editor_template_src.js 901 2008-08-18 11:44:21Z spocke $
       
     3  *
       
     4  * @author Moxiecode
       
     5  * @copyright Copyright © 2004-2008, Moxiecode Systems AB, All rights reserved.
       
     6  */
       
     7 
       
     8 (function() {
       
     9 	var DOM = tinymce.DOM, Event = tinymce.dom.Event, extend = tinymce.extend, each = tinymce.each, Cookie = tinymce.util.Cookie, lastExtID, explode = tinymce.explode;
       
    10 
       
    11 	// Tell it to load theme specific language pack(s)
       
    12 	tinymce.ThemeManager.requireLangPack('advanced');
       
    13 
       
    14 	tinymce.create('tinymce.themes.AdvancedTheme', {
       
    15 		// Control name lookup, format: title, command
       
    16 		controls : {
       
    17 			bold : ['bold_desc', 'Bold'],
       
    18 			italic : ['italic_desc', 'Italic'],
       
    19 			underline : ['underline_desc', 'Underline'],
       
    20 			strikethrough : ['striketrough_desc', 'Strikethrough'],
       
    21 			justifyleft : ['justifyleft_desc', 'JustifyLeft'],
       
    22 			justifycenter : ['justifycenter_desc', 'JustifyCenter'],
       
    23 			justifyright : ['justifyright_desc', 'JustifyRight'],
       
    24 			justifyfull : ['justifyfull_desc', 'JustifyFull'],
       
    25 			bullist : ['bullist_desc', 'InsertUnorderedList'],
       
    26 			numlist : ['numlist_desc', 'InsertOrderedList'],
       
    27 			outdent : ['outdent_desc', 'Outdent'],
       
    28 			indent : ['indent_desc', 'Indent'],
       
    29 			cut : ['cut_desc', 'Cut'],
       
    30 			copy : ['copy_desc', 'Copy'],
       
    31 			paste : ['paste_desc', 'Paste'],
       
    32 			undo : ['undo_desc', 'Undo'],
       
    33 			redo : ['redo_desc', 'Redo'],
       
    34 			link : ['link_desc', 'mceLink'],
       
    35 			unlink : ['unlink_desc', 'unlink'],
       
    36 			image : ['image_desc', 'mceImage'],
       
    37 			cleanup : ['cleanup_desc', 'mceCleanup'],
       
    38 			help : ['help_desc', 'mceHelp'],
       
    39 			code : ['code_desc', 'mceCodeEditor'],
       
    40 			hr : ['hr_desc', 'InsertHorizontalRule'],
       
    41 			removeformat : ['removeformat_desc', 'RemoveFormat'],
       
    42 			sub : ['sub_desc', 'subscript'],
       
    43 			sup : ['sup_desc', 'superscript'],
       
    44 			forecolor : ['forecolor_desc', 'ForeColor'],
       
    45 			forecolorpicker : ['forecolor_desc', 'mceForeColor'],
       
    46 			backcolor : ['backcolor_desc', 'HiliteColor'],
       
    47 			backcolorpicker : ['backcolor_desc', 'mceBackColor'],
       
    48 			charmap : ['charmap_desc', 'mceCharMap'],
       
    49 			visualaid : ['visualaid_desc', 'mceToggleVisualAid'],
       
    50 			anchor : ['anchor_desc', 'mceInsertAnchor'],
       
    51 			newdocument : ['newdocument_desc', 'mceNewDocument'],
       
    52 			blockquote : ['blockquote_desc', 'mceBlockQuote']
       
    53 		},
       
    54 
       
    55 		stateControls : ['bold', 'italic', 'underline', 'strikethrough', 'bullist', 'numlist', 'justifyleft', 'justifycenter', 'justifyright', 'justifyfull', 'sub', 'sup', 'blockquote'],
       
    56 
       
    57 		init : function(ed, url) {
       
    58 			var t = this, s, v;
       
    59 	
       
    60 			t.editor = ed;
       
    61 			t.url = url;
       
    62 			t.onResolveName = new tinymce.util.Dispatcher(this);
       
    63 
       
    64 			// Default settings
       
    65 			t.settings = s = extend({
       
    66 				theme_advanced_path : true,
       
    67 				theme_advanced_toolbar_location : 'bottom',
       
    68 				theme_advanced_buttons1 : "bold,italic,underline,strikethrough,|,justifyleft,justifycenter,justifyright,justifyfull,|,styleselect,formatselect",
       
    69 				theme_advanced_buttons2 : "bullist,numlist,|,outdent,indent,|,undo,redo,|,link,unlink,anchor,image,cleanup,help,code",
       
    70 				theme_advanced_buttons3 : "hr,removeformat,visualaid,|,sub,sup,|,charmap",
       
    71 				theme_advanced_blockformats : "p,address,pre,h1,h2,h3,h4,h5,h6",
       
    72 				theme_advanced_toolbar_align : "center",
       
    73 				theme_advanced_fonts : "Andale Mono=andale mono,times;Arial=arial,helvetica,sans-serif;Arial Black=arial black,avant garde;Book Antiqua=book antiqua,palatino;Comic Sans MS=comic sans ms,sans-serif;Courier New=courier new,courier;Georgia=georgia,palatino;Helvetica=helvetica;Impact=impact,chicago;Symbol=symbol;Tahoma=tahoma,arial,helvetica,sans-serif;Terminal=terminal,monaco;Times New Roman=times new roman,times;Trebuchet MS=trebuchet ms,geneva;Verdana=verdana,geneva;Webdings=webdings;Wingdings=wingdings,zapf dingbats",
       
    74 				theme_advanced_font_sizes : "1,2,3,4,5,6,7",
       
    75 				theme_advanced_more_colors : 1,
       
    76 				theme_advanced_row_height : 23,
       
    77 				theme_advanced_resize_horizontal : 1,
       
    78 				theme_advanced_resizing_use_cookie : 1,
       
    79 				readonly : ed.settings.readonly
       
    80 			}, ed.settings);
       
    81 
       
    82 			if ((v = s.theme_advanced_path_location) && v != 'none')
       
    83 				s.theme_advanced_statusbar_location = s.theme_advanced_path_location;
       
    84 
       
    85 			if (s.theme_advanced_statusbar_location == 'none')
       
    86 				s.theme_advanced_statusbar_location = 0;
       
    87 
       
    88 			// Init editor
       
    89 			ed.onInit.add(function() {
       
    90 				ed.onNodeChange.add(t._nodeChanged, t);
       
    91 
       
    92 				if (ed.settings.content_css !== false)
       
    93 					ed.dom.loadCSS(ed.baseURI.toAbsolute("themes/advanced/skins/" + ed.settings.skin + "/content.css"));
       
    94 			});
       
    95 
       
    96 			ed.onSetProgressState.add(function(ed, b, ti) {
       
    97 				var co, id = ed.id, tb;
       
    98 
       
    99 				if (b) {
       
   100 					t.progressTimer = setTimeout(function() {
       
   101 						co = ed.getContainer();
       
   102 						co = co.insertBefore(DOM.create('DIV', {style : 'position:relative'}), co.firstChild);
       
   103 						tb = DOM.get(ed.id + '_tbl');
       
   104 
       
   105 						DOM.add(co, 'div', {id : id + '_blocker', 'class' : 'mceBlocker', style : {width : tb.clientWidth + 2, height : tb.clientHeight + 2}});
       
   106 						DOM.add(co, 'div', {id : id + '_progress', 'class' : 'mceProgress', style : {left : tb.clientWidth / 2, top : tb.clientHeight / 2}});
       
   107 					}, ti || 0);
       
   108 				} else {
       
   109 					DOM.remove(id + '_blocker');
       
   110 					DOM.remove(id + '_progress');
       
   111 					clearTimeout(t.progressTimer);
       
   112 				}
       
   113 			});
       
   114 
       
   115 			DOM.loadCSS(ed.baseURI.toAbsolute(s.editor_css || "themes/advanced/skins/" + ed.settings.skin + "/ui.css"));
       
   116 
       
   117 			if (s.skin_variant)
       
   118 				DOM.loadCSS(ed.baseURI.toAbsolute(s.editor_css || "themes/advanced/skins/" + ed.settings.skin + "/ui_" + s.skin_variant + ".css"));
       
   119 		},
       
   120 
       
   121 		createControl : function(n, cf) {
       
   122 			var cd, c;
       
   123 
       
   124 			if (c = cf.createControl(n))
       
   125 				return c;
       
   126 
       
   127 			switch (n) {
       
   128 				case "styleselect":
       
   129 					return this._createStyleSelect();
       
   130 
       
   131 				case "formatselect":
       
   132 					return this._createBlockFormats();
       
   133 
       
   134 				case "fontselect":
       
   135 					return this._createFontSelect();
       
   136 
       
   137 				case "fontsizeselect":
       
   138 					return this._createFontSizeSelect();
       
   139 
       
   140 				case "forecolor":
       
   141 					return this._createForeColorMenu();
       
   142 
       
   143 				case "backcolor":
       
   144 					return this._createBackColorMenu();
       
   145 			}
       
   146 
       
   147 			if ((cd = this.controls[n]))
       
   148 				return cf.createButton(n, {title : "advanced." + cd[0], cmd : cd[1], ui : cd[2], value : cd[3]});
       
   149 		},
       
   150 
       
   151 		execCommand : function(cmd, ui, val) {
       
   152 			var f = this['_' + cmd];
       
   153 
       
   154 			if (f) {
       
   155 				f.call(this, ui, val);
       
   156 				return true;
       
   157 			}
       
   158 
       
   159 			return false;
       
   160 		},
       
   161 
       
   162 		_importClasses : function(e) {
       
   163 			var ed = this.editor, c = ed.controlManager.get('styleselect');
       
   164 
       
   165 			if (c.getLength() == 0) {
       
   166 				each(ed.dom.getClasses(), function(o) {
       
   167 					c.add(o['class'], o['class']);
       
   168 				});
       
   169 			}
       
   170 		},
       
   171 
       
   172 		_createStyleSelect : function(n) {
       
   173 			var t = this, ed = t.editor, cf = ed.controlManager, c = cf.createListBox('styleselect', {
       
   174 				title : 'advanced.style_select',
       
   175 				onselect : function(v) {
       
   176 					if (c.selectedValue === v) {
       
   177 						ed.execCommand('mceSetStyleInfo', 0, {command : 'removeformat'});
       
   178 						c.select();
       
   179 						return false;
       
   180 					} else
       
   181 						ed.execCommand('mceSetCSSClass', 0, v);
       
   182 				}
       
   183 			});
       
   184 
       
   185 			if (c) {
       
   186 				each(ed.getParam('theme_advanced_styles', '', 'hash'), function(v, k) {
       
   187 					if (v)
       
   188 						c.add(t.editor.translate(k), v);
       
   189 				});
       
   190 
       
   191 				c.onPostRender.add(function(ed, n) {
       
   192 					Event.add(n.id + '_text', 'focus', t._importClasses, t);
       
   193 					Event.add(n.id + '_text', 'mousedown', t._importClasses, t);
       
   194 				});
       
   195 			}
       
   196 
       
   197 			return c;
       
   198 		},
       
   199 
       
   200 		_createFontSelect : function() {
       
   201 			var c, t = this, ed = t.editor;
       
   202 
       
   203 			c = ed.controlManager.createListBox('fontselect', {title : 'advanced.fontdefault', cmd : 'FontName'});
       
   204 			if (c) {
       
   205 				each(ed.getParam('theme_advanced_fonts', t.settings.theme_advanced_fonts, 'hash'), function(v, k) {
       
   206 					c.add(ed.translate(k), v, {style : v.indexOf('dings') == -1 ? 'font-family:' + v : ''});
       
   207 				});
       
   208 			}
       
   209 
       
   210 			return c;
       
   211 		},
       
   212 
       
   213 		_createFontSizeSelect : function() {
       
   214 			var t = this, ed = t.editor, c, lo = [
       
   215 				"1 (8 pt)",
       
   216 				"2 (10 pt)",
       
   217 				"3 (12 pt)",
       
   218 				"4 (14 pt)",
       
   219 				"5 (18 pt)",
       
   220 				"6 (24 pt)",
       
   221 				"7 (36 pt)"
       
   222 			], fz = [8, 10, 12, 14, 18, 24, 36];
       
   223 
       
   224 			c = ed.controlManager.createListBox('fontsizeselect', {title : 'advanced.font_size', cmd : 'FontSize'});
       
   225 			if (c) {
       
   226 				each(ed.getParam('theme_advanced_font_sizes', t.settings.theme_advanced_font_sizes, 'hash'), function(v, k) {
       
   227 					c.add(k != v ? k : lo[parseInt(v) - 1], v, {'style' : 'font-size:' + fz[v - 1] + 'pt', 'class' : 'mceFontSize' + v});
       
   228 				});
       
   229 			}
       
   230 
       
   231 			return c;
       
   232 		},
       
   233 
       
   234 		_createBlockFormats : function() {
       
   235 			var c, fmts = {
       
   236 				p : 'advanced.paragraph',
       
   237 				address : 'advanced.address',
       
   238 				pre : 'advanced.pre',
       
   239 				h1 : 'advanced.h1',
       
   240 				h2 : 'advanced.h2',
       
   241 				h3 : 'advanced.h3',
       
   242 				h4 : 'advanced.h4',
       
   243 				h5 : 'advanced.h5',
       
   244 				h6 : 'advanced.h6',
       
   245 				div : 'advanced.div',
       
   246 				blockquote : 'advanced.blockquote',
       
   247 				code : 'advanced.code',
       
   248 				dt : 'advanced.dt',
       
   249 				dd : 'advanced.dd',
       
   250 				samp : 'advanced.samp'
       
   251 			}, t = this;
       
   252 
       
   253 			c = t.editor.controlManager.createListBox('formatselect', {title : 'advanced.block', cmd : 'FormatBlock'});
       
   254 			if (c) {
       
   255 				each(t.editor.getParam('theme_advanced_blockformats', t.settings.theme_advanced_blockformats, 'hash'), function(v, k) {
       
   256 					c.add(t.editor.translate(k != v ? k : fmts[v]), v, {'class' : 'mce_formatPreview mce_' + v});
       
   257 				});
       
   258 			}
       
   259 
       
   260 			return c;
       
   261 		},
       
   262 
       
   263 		_createForeColorMenu : function() {
       
   264 			var c, t = this, s = t.settings, o = {}, v;
       
   265 
       
   266 			if (s.theme_advanced_more_colors) {
       
   267 				o.more_colors_func = function() {
       
   268 					t._mceColorPicker(0, {
       
   269 						color : c.value,
       
   270 						func : function(co) {
       
   271 							c.setColor(co);
       
   272 						}
       
   273 					});
       
   274 				};
       
   275 			}
       
   276 
       
   277 			if (v = s.theme_advanced_text_colors)
       
   278 				o.colors = v;
       
   279 
       
   280 			o.title = 'advanced.forecolor_desc';
       
   281 			o.cmd = 'ForeColor';
       
   282 			o.scope = this;
       
   283 
       
   284 			c = t.editor.controlManager.createColorSplitButton('forecolor', o);
       
   285 
       
   286 			return c;
       
   287 		},
       
   288 
       
   289 		_createBackColorMenu : function() {
       
   290 			var c, t = this, s = t.settings, o = {}, v;
       
   291 
       
   292 			if (s.theme_advanced_more_colors) {
       
   293 				o.more_colors_func = function() {
       
   294 					t._mceColorPicker(0, {
       
   295 						color : c.value,
       
   296 						func : function(co) {
       
   297 							c.setColor(co);
       
   298 						}
       
   299 					});
       
   300 				};
       
   301 			}
       
   302 
       
   303 			if (v = s.theme_advanced_background_colors)
       
   304 				o.colors = v;
       
   305 
       
   306 			o.title = 'advanced.backcolor_desc';
       
   307 			o.cmd = 'HiliteColor';
       
   308 			o.scope = this;
       
   309 
       
   310 			c = t.editor.controlManager.createColorSplitButton('backcolor', o);
       
   311 
       
   312 			return c;
       
   313 		},
       
   314 
       
   315 		renderUI : function(o) {
       
   316 			var n, ic, tb, t = this, ed = t.editor, s = t.settings, sc, p, nl;
       
   317 
       
   318 			n = p = DOM.create('span', {id : ed.id + '_parent', 'class' : 'mceEditor ' + ed.settings.skin + 'Skin' + (s.skin_variant ? ' ' + ed.settings.skin + 'Skin' + t._ufirst(s.skin_variant) : '')});
       
   319 
       
   320 			if (!DOM.boxModel)
       
   321 				n = DOM.add(n, 'div', {'class' : 'mceOldBoxModel'});
       
   322 
       
   323 			n = sc = DOM.add(n, 'table', {id : ed.id + '_tbl', 'class' : 'mceLayout', cellSpacing : 0, cellPadding : 0});
       
   324 			n = tb = DOM.add(n, 'tbody');
       
   325 
       
   326 			switch ((s.theme_advanced_layout_manager || '').toLowerCase()) {
       
   327 				case "rowlayout":
       
   328 					ic = t._rowLayout(s, tb, o);
       
   329 					break;
       
   330 
       
   331 				case "customlayout":
       
   332 					ic = ed.execCallback("theme_advanced_custom_layout", s, tb, o, p);
       
   333 					break;
       
   334 
       
   335 				default:
       
   336 					ic = t._simpleLayout(s, tb, o, p);
       
   337 			}
       
   338 
       
   339 			n = o.targetNode;
       
   340 
       
   341 			// Add classes to first and last TRs
       
   342 			nl = DOM.stdMode ? sc.getElementsByTagName('tr') : sc.rows; // Quick fix for IE 8
       
   343 			DOM.addClass(nl[0], 'mceFirst');
       
   344 			DOM.addClass(nl[nl.length - 1], 'mceLast');
       
   345 
       
   346 			// Add classes to first and last TDs
       
   347 			each(DOM.select('tr', tb), function(n) {
       
   348 				DOM.addClass(n.firstChild, 'mceFirst');
       
   349 				DOM.addClass(n.childNodes[n.childNodes.length - 1], 'mceLast');
       
   350 			});
       
   351 
       
   352 			if (DOM.get(s.theme_advanced_toolbar_container))
       
   353 				DOM.get(s.theme_advanced_toolbar_container).appendChild(p);
       
   354 			else
       
   355 				DOM.insertAfter(p, n);
       
   356 
       
   357 			Event.add(ed.id + '_path_row', 'click', function(e) {
       
   358 				e = e.target;
       
   359 
       
   360 				if (e.nodeName == 'A') {
       
   361 					t._sel(e.className.replace(/^.*mcePath_([0-9]+).*$/, '$1'));
       
   362 
       
   363 					return Event.cancel(e);
       
   364 				}
       
   365 			});
       
   366 /*
       
   367 			if (DOM.get(ed.id + '_path_row')) {
       
   368 				Event.add(ed.id + '_tbl', 'mouseover', function(e) {
       
   369 					var re;
       
   370 	
       
   371 					e = e.target;
       
   372 
       
   373 					if (e.nodeName == 'SPAN' && DOM.hasClass(e.parentNode, 'mceButton')) {
       
   374 						re = DOM.get(ed.id + '_path_row');
       
   375 						t.lastPath = re.innerHTML;
       
   376 						DOM.setHTML(re, e.parentNode.title);
       
   377 					}
       
   378 				});
       
   379 
       
   380 				Event.add(ed.id + '_tbl', 'mouseout', function(e) {
       
   381 					if (t.lastPath) {
       
   382 						DOM.setHTML(ed.id + '_path_row', t.lastPath);
       
   383 						t.lastPath = 0;
       
   384 					}
       
   385 				});
       
   386 			}
       
   387 */
       
   388 
       
   389 			if (!ed.getParam('accessibility_focus') || ed.getParam('tab_focus'))
       
   390 				Event.add(DOM.add(p, 'a', {href : '#'}, '<!-- IE -->'), 'focus', function() {tinyMCE.get(ed.id).focus();});
       
   391 
       
   392 			if (s.theme_advanced_toolbar_location == 'external')
       
   393 				o.deltaHeight = 0;
       
   394 
       
   395 			t.deltaHeight = o.deltaHeight;
       
   396 			o.targetNode = null;
       
   397 
       
   398 			return {
       
   399 				iframeContainer : ic,
       
   400 				editorContainer : ed.id + '_parent',
       
   401 				sizeContainer : sc,
       
   402 				deltaHeight : o.deltaHeight
       
   403 			};
       
   404 		},
       
   405 
       
   406 		getInfo : function() {
       
   407 			return {
       
   408 				longname : 'Advanced theme',
       
   409 				author : 'Moxiecode Systems AB',
       
   410 				authorurl : 'http://tinymce.moxiecode.com',
       
   411 				version : tinymce.majorVersion + "." + tinymce.minorVersion
       
   412 			}
       
   413 		},
       
   414 
       
   415 		resizeBy : function(dw, dh) {
       
   416 			var e = DOM.get(this.editor.id + '_tbl');
       
   417 
       
   418 			this.resizeTo(e.clientWidth + dw, e.clientHeight + dh);
       
   419 		},
       
   420 
       
   421 		resizeTo : function(w, h) {
       
   422 			var ed = this.editor, s = ed.settings, e = DOM.get(ed.id + '_tbl'), ifr = DOM.get(ed.id + '_ifr'), dh;
       
   423 
       
   424 			// Boundery fix box
       
   425 			w = Math.max(s.theme_advanced_resizing_min_width || 100, w);
       
   426 			h = Math.max(s.theme_advanced_resizing_min_height || 100, h);
       
   427 			w = Math.min(s.theme_advanced_resizing_max_width || 0xFFFF, w);
       
   428 			h = Math.min(s.theme_advanced_resizing_max_height || 0xFFFF, h);
       
   429 
       
   430 			// Calc difference between iframe and container
       
   431 			dh = e.clientHeight - ifr.clientHeight;
       
   432 
       
   433 			// Resize iframe and container
       
   434 			DOM.setStyle(ifr, 'height', h - dh);
       
   435 			DOM.setStyles(e, {width : w, height : h});
       
   436 		},
       
   437 
       
   438 		destroy : function() {
       
   439 			var id = this.editor.id;
       
   440 
       
   441 			Event.clear(id + '_resize');
       
   442 			Event.clear(id + '_path_row');
       
   443 			Event.clear(id + '_external_close');
       
   444 		},
       
   445 
       
   446 		// Internal functions
       
   447 
       
   448 		_simpleLayout : function(s, tb, o, p) {
       
   449 			var t = this, ed = t.editor, lo = s.theme_advanced_toolbar_location, sl = s.theme_advanced_statusbar_location, n, ic, etb, c;
       
   450 
       
   451 			if (s.readonly) {
       
   452 				n = DOM.add(tb, 'tr');
       
   453 				n = ic = DOM.add(n, 'td', {'class' : 'mceIframeContainer'});
       
   454 				return ic;
       
   455 			}
       
   456 
       
   457 			// Create toolbar container at top
       
   458 			if (lo == 'top')
       
   459 				t._addToolbars(tb, o);
       
   460 
       
   461 			// Create external toolbar
       
   462 			if (lo == 'external') {
       
   463 				n = c = DOM.create('div', {style : 'position:relative'});
       
   464 				n = DOM.add(n, 'div', {id : ed.id + '_external', 'class' : 'mceExternalToolbar'});
       
   465 				DOM.add(n, 'a', {id : ed.id + '_external_close', href : 'javascript:;', 'class' : 'mceExternalClose'});
       
   466 				n = DOM.add(n, 'table', {id : ed.id + '_tblext', cellSpacing : 0, cellPadding : 0});
       
   467 				etb = DOM.add(n, 'tbody');
       
   468 
       
   469 				if (p.firstChild.className == 'mceOldBoxModel')
       
   470 					p.firstChild.appendChild(c);
       
   471 				else
       
   472 					p.insertBefore(c, p.firstChild);
       
   473 
       
   474 				t._addToolbars(etb, o);
       
   475 
       
   476 				ed.onMouseUp.add(function() {
       
   477 					var e = DOM.get(ed.id + '_external');
       
   478 					DOM.show(e);
       
   479 
       
   480 					DOM.hide(lastExtID);
       
   481 
       
   482 					var f = Event.add(ed.id + '_external_close', 'click', function() {
       
   483 						DOM.hide(ed.id + '_external');
       
   484 						Event.remove(ed.id + '_external_close', 'click', f);
       
   485 					});
       
   486 
       
   487 					DOM.show(e);
       
   488 					DOM.setStyle(e, 'top', 0 - DOM.getRect(ed.id + '_tblext').h - 1);
       
   489 
       
   490 					// Fixes IE rendering bug
       
   491 					DOM.hide(e);
       
   492 					DOM.show(e);
       
   493 					e.style.filter = '';
       
   494 
       
   495 					lastExtID = ed.id + '_external';
       
   496 
       
   497 					e = null;
       
   498 				});
       
   499 			}
       
   500 
       
   501 			if (sl == 'top')
       
   502 				t._addStatusBar(tb, o);
       
   503 
       
   504 			// Create iframe container
       
   505 			if (!s.theme_advanced_toolbar_container) {
       
   506 				n = DOM.add(tb, 'tr');
       
   507 				n = ic = DOM.add(n, 'td', {'class' : 'mceIframeContainer'});
       
   508 			}
       
   509 
       
   510 			// Create toolbar container at bottom
       
   511 			if (lo == 'bottom')
       
   512 				t._addToolbars(tb, o);
       
   513 
       
   514 			if (sl == 'bottom')
       
   515 				t._addStatusBar(tb, o);
       
   516 
       
   517 			return ic;
       
   518 		},
       
   519 
       
   520 		_rowLayout : function(s, tb, o) {
       
   521 			var t = this, ed = t.editor, dc, da, cf = ed.controlManager, n, ic, to, a;
       
   522 
       
   523 			dc = s.theme_advanced_containers_default_class || '';
       
   524 			da = s.theme_advanced_containers_default_align || 'center';
       
   525 
       
   526 			each(explode(s.theme_advanced_containers || ''), function(c, i) {
       
   527 				var v = s['theme_advanced_container_' + c] || '';
       
   528 
       
   529 				switch (v.toLowerCase()) {
       
   530 					case 'mceeditor':
       
   531 						n = DOM.add(tb, 'tr');
       
   532 						n = ic = DOM.add(n, 'td', {'class' : 'mceIframeContainer'});
       
   533 						break;
       
   534 
       
   535 					case 'mceelementpath':
       
   536 						t._addStatusBar(tb, o);
       
   537 						break;
       
   538 
       
   539 					default:
       
   540 						a = (s['theme_advanced_container_' + c + '_align'] || da).toLowerCase();
       
   541 						a = 'mce' + t._ufirst(a);
       
   542 
       
   543 						n = DOM.add(DOM.add(tb, 'tr'), 'td', {
       
   544 							'class' : 'mceToolbar ' + (s['theme_advanced_container_' + c + '_class'] || dc) + ' ' + a || da
       
   545 						});
       
   546 
       
   547 						to = cf.createToolbar("toolbar" + i);
       
   548 						t._addControls(v, to);
       
   549 						DOM.setHTML(n, to.renderHTML());
       
   550 						o.deltaHeight -= s.theme_advanced_row_height;
       
   551 				}
       
   552 			});
       
   553 
       
   554 			return ic;
       
   555 		},
       
   556 
       
   557 		_addControls : function(v, tb) {
       
   558 			var t = this, s = t.settings, di, cf = t.editor.controlManager;
       
   559 
       
   560 			if (s.theme_advanced_disable && !t._disabled) {
       
   561 				di = {};
       
   562 
       
   563 				each(explode(s.theme_advanced_disable), function(v) {
       
   564 					di[v] = 1;
       
   565 				});
       
   566 
       
   567 				t._disabled = di;
       
   568 			} else
       
   569 				di = t._disabled;
       
   570 
       
   571 			each(explode(v), function(n) {
       
   572 				var c;
       
   573 
       
   574 				if (di && di[n])
       
   575 					return;
       
   576 
       
   577 				// Compatiblity with 2.x
       
   578 				if (n == 'tablecontrols') {
       
   579 					each(["table","|","row_props","cell_props","|","row_before","row_after","delete_row","|","col_before","col_after","delete_col","|","split_cells","merge_cells"], function(n) {
       
   580 						n = t.createControl(n, cf);
       
   581 
       
   582 						if (n)
       
   583 							tb.add(n);
       
   584 					});
       
   585 
       
   586 					return;
       
   587 				}
       
   588 
       
   589 				c = t.createControl(n, cf);
       
   590 
       
   591 				if (c)
       
   592 					tb.add(c);
       
   593 			});
       
   594 		},
       
   595 
       
   596 		_addToolbars : function(c, o) {
       
   597 			var t = this, i, tb, ed = t.editor, s = t.settings, v, cf = ed.controlManager, di, n, h = [], a;
       
   598 
       
   599 			a = s.theme_advanced_toolbar_align.toLowerCase();
       
   600 			a = 'mce' + t._ufirst(a);
       
   601 
       
   602 			n = DOM.add(DOM.add(c, 'tr'), 'td', {'class' : 'mceToolbar ' + a});
       
   603 
       
   604 			if (!ed.getParam('accessibility_focus') || ed.getParam('tab_focus'))
       
   605 				h.push(DOM.createHTML('a', {href : '#', onfocus : 'tinyMCE.get(\'' + ed.id + '\').focus();'}, '<!-- IE -->'));
       
   606 
       
   607 			h.push(DOM.createHTML('a', {href : '#', accesskey : 'q', title : ed.getLang("advanced.toolbar_focus")}, '<!-- IE -->'));
       
   608 
       
   609 			// Create toolbar and add the controls
       
   610 			for (i=1; (v = s['theme_advanced_buttons' + i]); i++) {
       
   611 				tb = cf.createToolbar("toolbar" + i, {'class' : 'mceToolbarRow' + i});
       
   612 
       
   613 				if (s['theme_advanced_buttons' + i + '_add'])
       
   614 					v += ',' + s['theme_advanced_buttons' + i + '_add'];
       
   615 
       
   616 				if (s['theme_advanced_buttons' + i + '_add_before'])
       
   617 					v = s['theme_advanced_buttons' + i + '_add_before'] + ',' + v;
       
   618 
       
   619 				t._addControls(v, tb);
       
   620 
       
   621 				//n.appendChild(n = tb.render());
       
   622 				h.push(tb.renderHTML());
       
   623 
       
   624 				o.deltaHeight -= s.theme_advanced_row_height;
       
   625 			}
       
   626 
       
   627 			h.push(DOM.createHTML('a', {href : '#', accesskey : 'z', title : ed.getLang("advanced.toolbar_focus"), onfocus : 'tinyMCE.getInstanceById(\'' + ed.id + '\').focus();'}, '<!-- IE -->'));
       
   628 			DOM.setHTML(n, h.join(''));
       
   629 		},
       
   630 
       
   631 		_addStatusBar : function(tb, o) {
       
   632 			var n, t = this, ed = t.editor, s = t.settings, r, mf, me, td;
       
   633 
       
   634 			n = DOM.add(tb, 'tr');
       
   635 			n = td = DOM.add(n, 'td', {'class' : 'mceStatusbar'});
       
   636 			n = DOM.add(n, 'div', {id : ed.id + '_path_row'}, s.theme_advanced_path ? ed.translate('advanced.path') + ': ' : '&nbsp;');
       
   637 			DOM.add(n, 'a', {href : '#', accesskey : 'x'});
       
   638 
       
   639 			if (s.theme_advanced_resizing && !tinymce.isOldWebKit) {
       
   640 				DOM.add(td, 'a', {id : ed.id + '_resize', href : 'javascript:;', onclick : "return false;", 'class' : 'mceResize'});
       
   641 
       
   642 				if (s.theme_advanced_resizing_use_cookie) {
       
   643 					ed.onPostRender.add(function() {
       
   644 						var o = Cookie.getHash("TinyMCE_" + ed.id + "_size"), c = DOM.get(ed.id + '_tbl');
       
   645 
       
   646 						if (!o)
       
   647 							return;
       
   648 
       
   649 						if (s.theme_advanced_resize_horizontal)
       
   650 							c.style.width = Math.max(10, o.cw) + 'px';
       
   651 
       
   652 						c.style.height = Math.max(10, o.ch) + 'px';
       
   653 						DOM.get(ed.id + '_ifr').style.height = Math.max(10, parseInt(o.ch) + t.deltaHeight) + 'px';
       
   654 					});
       
   655 				}
       
   656 
       
   657 				ed.onPostRender.add(function() {
       
   658 					Event.add(ed.id + '_resize', 'mousedown', function(e) {
       
   659 						var c, p, w, h, n, pa;
       
   660 
       
   661 						// Measure container
       
   662 						c = DOM.get(ed.id + '_tbl');
       
   663 						w = c.clientWidth;
       
   664 						h = c.clientHeight;
       
   665 
       
   666 						miw = s.theme_advanced_resizing_min_width || 100;
       
   667 						mih = s.theme_advanced_resizing_min_height || 100;
       
   668 						maw = s.theme_advanced_resizing_max_width || 0xFFFF;
       
   669 						mah = s.theme_advanced_resizing_max_height || 0xFFFF;
       
   670 
       
   671 						// Setup placeholder
       
   672 						p = DOM.add(DOM.get(ed.id + '_parent'), 'div', {'class' : 'mcePlaceHolder'});
       
   673 						DOM.setStyles(p, {width : w, height : h});
       
   674 
       
   675 						// Replace with placeholder
       
   676 						DOM.hide(c);
       
   677 						DOM.show(p);
       
   678 
       
   679 						// Create internal resize obj
       
   680 						r = {
       
   681 							x : e.screenX,
       
   682 							y : e.screenY,
       
   683 							w : w,
       
   684 							h : h,
       
   685 							dx : null,
       
   686 							dy : null
       
   687 						};
       
   688 
       
   689 						// Start listening
       
   690 						mf = Event.add(DOM.doc, 'mousemove', function(e) {
       
   691 							var w, h;
       
   692 
       
   693 							// Calc delta values
       
   694 							r.dx = e.screenX - r.x;
       
   695 							r.dy = e.screenY - r.y;
       
   696 
       
   697 							// Boundery fix box
       
   698 							w = Math.max(miw, r.w + r.dx);
       
   699 							h = Math.max(mih, r.h + r.dy);
       
   700 							w = Math.min(maw, w);
       
   701 							h = Math.min(mah, h);
       
   702 
       
   703 							// Resize placeholder
       
   704 							if (s.theme_advanced_resize_horizontal)
       
   705 								p.style.width = w + 'px';
       
   706 
       
   707 							p.style.height = h + 'px';
       
   708 
       
   709 							return Event.cancel(e);
       
   710 						});
       
   711 
       
   712 						me = Event.add(DOM.doc, 'mouseup', function(e) {
       
   713 							var ifr;
       
   714 
       
   715 							// Stop listening
       
   716 							Event.remove(DOM.doc, 'mousemove', mf);
       
   717 							Event.remove(DOM.doc, 'mouseup', me);
       
   718 
       
   719 							c.style.display = '';
       
   720 							DOM.remove(p);
       
   721 
       
   722 							if (r.dx === null)
       
   723 								return;
       
   724 
       
   725 							ifr = DOM.get(ed.id + '_ifr');
       
   726 
       
   727 							if (s.theme_advanced_resize_horizontal)
       
   728 								c.style.width = Math.max(10, r.w + r.dx) + 'px';
       
   729 
       
   730 							c.style.height = Math.max(10, r.h + r.dy) + 'px';
       
   731 							ifr.style.height = Math.max(10, ifr.clientHeight + r.dy) + 'px';
       
   732 
       
   733 							if (s.theme_advanced_resizing_use_cookie) {
       
   734 								Cookie.setHash("TinyMCE_" + ed.id + "_size", {
       
   735 									cw : r.w + r.dx,
       
   736 									ch : r.h + r.dy
       
   737 								});
       
   738 							}
       
   739 						});
       
   740 
       
   741 						return Event.cancel(e);
       
   742 					});
       
   743 				});
       
   744 			}
       
   745 
       
   746 			o.deltaHeight -= 21;
       
   747 			n = tb = null;
       
   748 		},
       
   749 
       
   750 		_nodeChanged : function(ed, cm, n, co) {
       
   751 			var t = this, p, de = 0, v, c, s = t.settings;
       
   752 
       
   753 			if (s.readonly)
       
   754 				return;
       
   755 
       
   756 			tinymce.each(t.stateControls, function(c) {
       
   757 				cm.setActive(c, ed.queryCommandState(t.controls[c][1]));
       
   758 			});
       
   759 
       
   760 			cm.setActive('visualaid', ed.hasVisual);
       
   761 			cm.setDisabled('undo', !ed.undoManager.hasUndo() && !ed.typing);
       
   762 			cm.setDisabled('redo', !ed.undoManager.hasRedo());
       
   763 			cm.setDisabled('outdent', !ed.queryCommandState('Outdent'));
       
   764 
       
   765 			p = DOM.getParent(n, 'A');
       
   766 			if (c = cm.get('link')) {
       
   767 				if (!p || !p.name) {
       
   768 					c.setDisabled(!p && co);
       
   769 					c.setActive(!!p);
       
   770 				}
       
   771 			}
       
   772 
       
   773 			if (c = cm.get('unlink')) {
       
   774 				c.setDisabled(!p && co);
       
   775 				c.setActive(!!p && !p.name);
       
   776 			}
       
   777 
       
   778 			if (c = cm.get('anchor')) {
       
   779 				c.setActive(!!p && p.name);
       
   780 
       
   781 				if (tinymce.isWebKit) {
       
   782 					p = DOM.getParent(n, 'IMG');
       
   783 					c.setActive(!!p && DOM.getAttrib(p, 'mce_name') == 'a');
       
   784 				}
       
   785 			}
       
   786 
       
   787 			p = DOM.getParent(n, 'IMG');
       
   788 			if (c = cm.get('image'))
       
   789 				c.setActive(!!p && n.className.indexOf('mceItem') == -1);
       
   790 
       
   791 			if (c = cm.get('styleselect')) {
       
   792 				if (n.className) {
       
   793 					t._importClasses();
       
   794 					c.select(n.className);
       
   795 				} else
       
   796 					c.select();
       
   797 			}
       
   798 
       
   799 			if (c = cm.get('formatselect')) {
       
   800 				p = DOM.getParent(n, DOM.isBlock);
       
   801 
       
   802 				if (p)
       
   803 					c.select(p.nodeName.toLowerCase());
       
   804 			}
       
   805 
       
   806 			if (c = cm.get('fontselect'))
       
   807 				c.select(ed.queryCommandValue('FontName'));
       
   808 
       
   809 			if (c = cm.get('fontsizeselect'))
       
   810 				c.select('' + ed.queryCommandValue('FontSize'));
       
   811 
       
   812 			if (s.theme_advanced_path && s.theme_advanced_statusbar_location) {
       
   813 				p = DOM.get(ed.id + '_path') || DOM.add(ed.id + '_path_row', 'span', {id : ed.id + '_path'});
       
   814 				DOM.setHTML(p, '');
       
   815 
       
   816 				ed.dom.getParent(n, function(n) {
       
   817 					var na = n.nodeName.toLowerCase(), u, pi, ti = '';
       
   818 
       
   819 					// Ignore non element and hidden elements
       
   820 					if (n.nodeType != 1 || (DOM.hasClass(n, 'mceItemHidden') || DOM.hasClass(n, 'mceItemRemoved')))
       
   821 						return;
       
   822 
       
   823 					// Fake name
       
   824 					if (v = DOM.getAttrib(n, 'mce_name'))
       
   825 						na = v;
       
   826 	
       
   827 					// Handle prefix
       
   828 					if (tinymce.isIE && n.scopeName !== 'HTML')
       
   829 						na = n.scopeName + ':' + na;
       
   830 
       
   831 					// Remove internal prefix
       
   832 					na = na.replace(/mce\:/g, '');
       
   833 
       
   834 					// Handle node name
       
   835 					switch (na) {
       
   836 						case 'b':
       
   837 							na = 'strong';
       
   838 							break;
       
   839 
       
   840 						case 'i':
       
   841 							na = 'em';
       
   842 							break;
       
   843 
       
   844 						case 'img':
       
   845 							if (v = DOM.getAttrib(n, 'src'))
       
   846 								ti += 'src: ' + v + ' ';
       
   847 
       
   848 							break;
       
   849 
       
   850 						case 'a':
       
   851 							if (v = DOM.getAttrib(n, 'name')) {
       
   852 								ti += 'name: ' + v + ' ';
       
   853 								na += '#' + v;
       
   854 							}
       
   855 
       
   856 							if (v = DOM.getAttrib(n, 'href'))
       
   857 								ti += 'href: ' + v + ' ';
       
   858 
       
   859 							break;
       
   860 
       
   861 						case 'font':
       
   862 							if (s.convert_fonts_to_spans)
       
   863 								na = 'span';
       
   864 
       
   865 							if (v = DOM.getAttrib(n, 'face'))
       
   866 								ti += 'font: ' + v + ' ';
       
   867 
       
   868 							if (v = DOM.getAttrib(n, 'size'))
       
   869 								ti += 'size: ' + v + ' ';
       
   870 
       
   871 							if (v = DOM.getAttrib(n, 'color'))
       
   872 								ti += 'color: ' + v + ' ';
       
   873 
       
   874 							break;
       
   875 
       
   876 						case 'span':
       
   877 							if (v = DOM.getAttrib(n, 'style'))
       
   878 								ti += 'style: ' + v + ' ';
       
   879 
       
   880 							break;
       
   881 					}
       
   882 
       
   883 					if (v = DOM.getAttrib(n, 'id'))
       
   884 						ti += 'id: ' + v + ' ';
       
   885 
       
   886 					if (v = n.className) {
       
   887 						v = v.replace(/(webkit-[\w\-]+|Apple-[\w\-]+|mceItem\w+|mceVisualAid)/g, '');
       
   888 
       
   889 						if (v && v.indexOf('mceItem') == -1) {
       
   890 							ti += 'class: ' + v + ' ';
       
   891 
       
   892 							if (DOM.isBlock(n) || na == 'img' || na == 'span')
       
   893 								na += '.' + v;
       
   894 						}
       
   895 					}
       
   896 
       
   897 					na = na.replace(/(html:)/g, '');
       
   898 					na = {name : na, node : n, title : ti};
       
   899 					t.onResolveName.dispatch(t, na);
       
   900 					ti = na.title;
       
   901 					na = na.name;
       
   902 
       
   903 					//u = "javascript:tinymce.EditorManager.get('" + ed.id + "').theme._sel('" + (de++) + "');";
       
   904 					pi = DOM.create('a', {'href' : "javascript:;", onmousedown : "return false;", title : ti, 'class' : 'mcePath_' + (de++)}, na);
       
   905 
       
   906 					if (p.hasChildNodes()) {
       
   907 						p.insertBefore(DOM.doc.createTextNode(' \u00bb '), p.firstChild);
       
   908 						p.insertBefore(pi, p.firstChild);
       
   909 					} else
       
   910 						p.appendChild(pi);
       
   911 				}, ed.getBody());
       
   912 			}
       
   913 		},
       
   914 
       
   915 		// Commands gets called by execCommand
       
   916 
       
   917 		_sel : function(v) {
       
   918 			this.editor.execCommand('mceSelectNodeDepth', false, v);
       
   919 		},
       
   920 
       
   921 		_mceInsertAnchor : function(ui, v) {
       
   922 			var ed = this.editor;
       
   923 
       
   924 			ed.windowManager.open({
       
   925 				url : tinymce.baseURL + '/themes/advanced/anchor.htm',
       
   926 				width : 320 + parseInt(ed.getLang('advanced.anchor_delta_width', 0)),
       
   927 				height : 90 + parseInt(ed.getLang('advanced.anchor_delta_height', 0)),
       
   928 				inline : true
       
   929 			}, {
       
   930 				theme_url : this.url
       
   931 			});
       
   932 		},
       
   933 
       
   934 		_mceCharMap : function() {
       
   935 			var ed = this.editor;
       
   936 
       
   937 			ed.windowManager.open({
       
   938 				url : tinymce.baseURL + '/themes/advanced/charmap.htm',
       
   939 				width : 550 + parseInt(ed.getLang('advanced.charmap_delta_width', 0)),
       
   940 				height : 250 + parseInt(ed.getLang('advanced.charmap_delta_height', 0)),
       
   941 				inline : true
       
   942 			}, {
       
   943 				theme_url : this.url
       
   944 			});
       
   945 		},
       
   946 
       
   947 		_mceHelp : function() {
       
   948 			var ed = this.editor;
       
   949 
       
   950 			ed.windowManager.open({
       
   951 				url : tinymce.baseURL + '/themes/advanced/about.htm',
       
   952 				width : 480,
       
   953 				height : 380,
       
   954 				inline : true
       
   955 			}, {
       
   956 				theme_url : this.url
       
   957 			});
       
   958 		},
       
   959 
       
   960 		_mceColorPicker : function(u, v) {
       
   961 			var ed = this.editor;
       
   962 
       
   963 			v = v || {};
       
   964 
       
   965 			ed.windowManager.open({
       
   966 				url : tinymce.baseURL + '/themes/advanced/color_picker.htm',
       
   967 				width : 375 + parseInt(ed.getLang('advanced.colorpicker_delta_width', 0)),
       
   968 				height : 250 + parseInt(ed.getLang('advanced.colorpicker_delta_height', 0)),
       
   969 				close_previous : false,
       
   970 				inline : true
       
   971 			}, {
       
   972 				input_color : v.color,
       
   973 				func : v.func,
       
   974 				theme_url : this.url
       
   975 			});
       
   976 		},
       
   977 
       
   978 		_mceCodeEditor : function(ui, val) {
       
   979 			var ed = this.editor;
       
   980 
       
   981 			ed.windowManager.open({
       
   982 				url : tinymce.baseURL + '/themes/advanced/source_editor.htm',
       
   983 				width : parseInt(ed.getParam("theme_advanced_source_editor_width", 720)),
       
   984 				height : parseInt(ed.getParam("theme_advanced_source_editor_height", 580)),
       
   985 				inline : true,
       
   986 				resizable : true,
       
   987 				maximizable : true
       
   988 			}, {
       
   989 				theme_url : this.url
       
   990 			});
       
   991 		},
       
   992 
       
   993 		_mceImage : function(ui, val) {
       
   994 			var ed = this.editor;
       
   995 
       
   996 			// Internal image object like a flash placeholder
       
   997 			if (ed.dom.getAttrib(ed.selection.getNode(), 'class').indexOf('mceItem') != -1)
       
   998 				return;
       
   999 
       
  1000 			ed.windowManager.open({
       
  1001 				url : tinymce.baseURL + '/themes/advanced/image.htm',
       
  1002 				width : 355 + parseInt(ed.getLang('advanced.image_delta_width', 0)),
       
  1003 				height : 275 + parseInt(ed.getLang('advanced.image_delta_height', 0)),
       
  1004 				inline : true
       
  1005 			}, {
       
  1006 				theme_url : this.url
       
  1007 			});
       
  1008 		},
       
  1009 
       
  1010 		_mceLink : function(ui, val) {
       
  1011 			var ed = this.editor;
       
  1012 
       
  1013 			ed.windowManager.open({
       
  1014 				url : tinymce.baseURL + '/themes/advanced/link.htm',
       
  1015 				width : 310 + parseInt(ed.getLang('advanced.link_delta_width', 0)),
       
  1016 				height : 200 + parseInt(ed.getLang('advanced.link_delta_height', 0)),
       
  1017 				inline : true
       
  1018 			}, {
       
  1019 				theme_url : this.url
       
  1020 			});
       
  1021 		},
       
  1022 
       
  1023 		_mceNewDocument : function() {
       
  1024 			var ed = this.editor;
       
  1025 
       
  1026 			ed.windowManager.confirm('advanced.newdocument', function(s) {
       
  1027 				if (s)
       
  1028 					ed.execCommand('mceSetContent', false, '');
       
  1029 			});
       
  1030 		},
       
  1031 
       
  1032 		_mceForeColor : function() {
       
  1033 			var t = this;
       
  1034 
       
  1035 			this._mceColorPicker(0, {
       
  1036 				color: t.fgColor,
       
  1037 				func : function(co) {
       
  1038 					t.fgColor = co;
       
  1039 					t.editor.execCommand('ForeColor', false, co);
       
  1040 				}
       
  1041 			});
       
  1042 		},
       
  1043 
       
  1044 		_mceBackColor : function() {
       
  1045 			var t = this;
       
  1046 
       
  1047 			this._mceColorPicker(0, {
       
  1048 				color: t.bgColor,
       
  1049 				func : function(co) {
       
  1050 					t.bgColor = co;
       
  1051 					t.editor.execCommand('HiliteColor', false, co);
       
  1052 				}
       
  1053 			});
       
  1054 		},
       
  1055 
       
  1056 		_ufirst : function(s) {
       
  1057 			return s.substring(0, 1).toUpperCase() + s.substring(1);
       
  1058 		}
       
  1059 	});
       
  1060 
       
  1061 	tinymce.ThemeManager.add('advanced', tinymce.themes.AdvancedTheme);
       
  1062 }());