PageRenderTime 1423ms CodeModel.GetById 154ms app.highlight 1169ms RepoModel.GetById 78ms app.codeStats 0ms

/static/scripts/tiny_mce/themes/advanced/editor_template_src.js

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