includes/clientside/tinymce/themes/advanced/editor_template_src.js
changeset 543 dffcbfbc4e59
parent 476 f26a69c40431
child 588 20484deb89cd
equal deleted inserted replaced
542:5841df0ab575 543:dffcbfbc4e59
     1 /**
     1 /**
     2  * $Id: editor_template_src.js 641 2008-02-26 17:01:30Z spocke $
     2  * $Id: editor_template_src.js 829 2008-04-30 14:35:32Z spocke $
     3  *
     3  *
     4  * @author Moxiecode
     4  * @author Moxiecode
     5  * @copyright Copyright © 2004-2008, Moxiecode Systems AB, All rights reserved.
     5  * @copyright Copyright © 2004-2008, Moxiecode Systems AB, All rights reserved.
     6  */
     6  */
     7 
     7 
     8 (function() {
     8 (function() {
     9 	var DOM = tinymce.DOM, Event = tinymce.dom.Event, extend = tinymce.extend, each = tinymce.each, Cookie = tinymce.util.Cookie, lastExtID;
     9 	var DOM = tinymce.DOM, Event = tinymce.dom.Event, extend = tinymce.extend, each = tinymce.each, Cookie = tinymce.util.Cookie, lastExtID, explode = tinymce.explode;
    10 
    10 
    11 	// Tell it to load theme specific language pack(s)
    11 	// Tell it to load theme specific language pack(s)
    12 	tinymce.ThemeManager.requireLangPack('advanced');
    12 	tinymce.ThemeManager.requireLangPack('advanced');
    13 
    13 
    14 	tinymce.create('tinymce.themes.AdvancedTheme', {
    14 	tinymce.create('tinymce.themes.AdvancedTheme', {
    53 		},
    53 		},
    54 
    54 
    55 		stateControls : ['bold', 'italic', 'underline', 'strikethrough', 'bullist', 'numlist', 'justifyleft', 'justifycenter', 'justifyright', 'justifyfull', 'sub', 'sup', 'blockquote'],
    55 		stateControls : ['bold', 'italic', 'underline', 'strikethrough', 'bullist', 'numlist', 'justifyleft', 'justifycenter', 'justifyright', 'justifyfull', 'sub', 'sup', 'blockquote'],
    56 
    56 
    57 		init : function(ed, url) {
    57 		init : function(ed, url) {
    58 			var t = this, s;
    58 			var t = this, s, v;
    59 
    59 	
    60 			t.editor = ed;
    60 			t.editor = ed;
    61 			t.url = url;
    61 			t.url = url;
    62 			t.onResolveName = new tinymce.util.Dispatcher(this);
    62 			t.onResolveName = new tinymce.util.Dispatcher(this);
    63 
    63 
    64 			// Default settings
    64 			// Default settings
    76 				theme_advanced_row_height : 23,
    76 				theme_advanced_row_height : 23,
    77 				theme_advanced_resize_horizontal : 1,
    77 				theme_advanced_resize_horizontal : 1,
    78 				theme_advanced_resizing_use_cookie : 1
    78 				theme_advanced_resizing_use_cookie : 1
    79 			}, ed.settings);
    79 			}, ed.settings);
    80 
    80 
    81 			if (s.theme_advanced_path_location)
    81 			if ((v = s.theme_advanced_path_location) && v != 'none')
    82 				s.theme_advanced_statusbar_location = s.theme_advanced_path_location;
    82 				s.theme_advanced_statusbar_location = s.theme_advanced_path_location;
    83 
    83 
    84 			if (s.theme_advanced_statusbar_location == 'none')
    84 			if (s.theme_advanced_statusbar_location == 'none')
    85 				s.theme_advanced_statusbar_location = 0;
    85 				s.theme_advanced_statusbar_location = 0;
    86 
    86 
    87 			// Init editor
    87 			// Init editor
    88 			ed.onInit.add(function() {
    88 			ed.onInit.add(function() {
    89 				ed.onNodeChange.add(t._nodeChanged, t);
    89 				ed.onNodeChange.add(t._nodeChanged, t);
    90 				ed.dom.loadCSS(ed.baseURI.toAbsolute("themes/advanced/skins/" + ed.settings.skin + "/content.css"));
    90 
       
    91 				if (ed.settings.content_css !== false)
       
    92 					ed.dom.loadCSS(ed.baseURI.toAbsolute("themes/advanced/skins/" + ed.settings.skin + "/content.css"));
    91 			});
    93 			});
    92 
    94 
    93 			ed.onSetProgressState.add(function(ed, b, ti) {
    95 			ed.onSetProgressState.add(function(ed, b, ti) {
    94 				var co, id = ed.id, tb;
    96 				var co, id = ed.id, tb;
    95 
    97 
   177 					} else
   179 					} else
   178 						ed.execCommand('mceSetCSSClass', 0, v);
   180 						ed.execCommand('mceSetCSSClass', 0, v);
   179 				}
   181 				}
   180 			});
   182 			});
   181 
   183 
   182 			each(ed.getParam('theme_advanced_styles', '', 'hash'), function(v, k) {
   184 			if (c) {
   183 				if (v)
   185 				each(ed.getParam('theme_advanced_styles', '', 'hash'), function(v, k) {
   184 					c.add(t.editor.translate(k), v);
   186 					if (v)
   185 			});
   187 						c.add(t.editor.translate(k), v);
   186 
   188 				});
   187 			c.onPostRender.add(function(ed, n) {
   189 
   188 				Event.add(n, 'focus', t._importClasses, t);
   190 				c.onPostRender.add(function(ed, n) {
   189 				Event.add(n, 'mousedown', t._importClasses, t);
   191 					Event.add(n, 'focus', t._importClasses, t);
   190 			});
   192 					Event.add(n, 'mousedown', t._importClasses, t);
       
   193 				});
       
   194 			}
   191 
   195 
   192 			return c;
   196 			return c;
   193 		},
   197 		},
   194 
   198 
   195 		_createFontSelect : function() {
   199 		_createFontSelect : function() {
   196 			var c, t = this, ed = t.editor;
   200 			var c, t = this, ed = t.editor;
   197 
   201 
   198 			c = ed.controlManager.createListBox('fontselect', {title : 'advanced.fontdefault', cmd : 'FontName'});
   202 			c = ed.controlManager.createListBox('fontselect', {title : 'advanced.fontdefault', cmd : 'FontName'});
   199 
   203 			if (c) {
   200 			each(ed.getParam('theme_advanced_fonts', t.settings.theme_advanced_fonts, 'hash'), function(v, k) {
   204 				each(ed.getParam('theme_advanced_fonts', t.settings.theme_advanced_fonts, 'hash'), function(v, k) {
   201 				c.add(ed.translate(k), v, {style : v.indexOf('dings') == -1 ? 'font-family:' + v : ''});
   205 					c.add(ed.translate(k), v, {style : v.indexOf('dings') == -1 ? 'font-family:' + v : ''});
   202 			});
   206 				});
       
   207 			}
   203 
   208 
   204 			return c;
   209 			return c;
   205 		},
   210 		},
   206 
   211 
   207 		_createFontSizeSelect : function() {
   212 		_createFontSizeSelect : function() {
   208 			var c, t = this, lo = [
   213 			var t = this, ed = t.editor, c, lo = [
   209 				"1 (8 pt)",
   214 				"1 (8 pt)",
   210 				"2 (10 pt)",
   215 				"2 (10 pt)",
   211 				"3 (12 pt)",
   216 				"3 (12 pt)",
   212 				"4 (14 pt)",
   217 				"4 (14 pt)",
   213 				"5 (18 pt)",
   218 				"5 (18 pt)",
   214 				"6 (24 pt)",
   219 				"6 (24 pt)",
   215 				"7 (36 pt)"
   220 				"7 (36 pt)"
   216 			], fz = [8, 10, 12, 14, 18, 24, 36];
   221 			], fz = [8, 10, 12, 14, 18, 24, 36];
   217 
   222 
   218 			c = t.editor.controlManager.createListBox('fontsizeselect', {title : 'advanced.font_size', cmd : 'FontSize'});
   223 			c = ed.controlManager.createListBox('fontsizeselect', {title : 'advanced.font_size', cmd : 'FontSize'});
   219 
   224 			if (c) {
   220 			each(t.settings.theme_advanced_font_sizes.split(','), function(v) {
   225 				each(ed.getParam('theme_advanced_font_sizes', t.settings.theme_advanced_font_sizes, 'hash'), function(v, k) {
   221 				c.add(lo[parseInt(v) - 1], v, {'style' : 'font-size:' + fz[v - 1] + 'pt', 'class' : 'mceFontSize' + v});
   226 					c.add(k != v ? k : lo[parseInt(v) - 1], v, {'style' : 'font-size:' + fz[v - 1] + 'pt', 'class' : 'mceFontSize' + v});
   222 			});
   227 				});
       
   228 			}
   223 
   229 
   224 			return c;
   230 			return c;
   225 		},
   231 		},
   226 
   232 
   227 		_createBlockFormats : function() {
   233 		_createBlockFormats : function() {
   242 				dd : 'advanced.dd',
   248 				dd : 'advanced.dd',
   243 				samp : 'advanced.samp'
   249 				samp : 'advanced.samp'
   244 			}, t = this;
   250 			}, t = this;
   245 
   251 
   246 			c = t.editor.controlManager.createListBox('formatselect', {title : 'advanced.block', cmd : 'FormatBlock'});
   252 			c = t.editor.controlManager.createListBox('formatselect', {title : 'advanced.block', cmd : 'FormatBlock'});
   247 
   253 			if (c) {
   248 			each(t.settings.theme_advanced_blockformats.split(','), function(v) {
   254 				each(t.editor.getParam('theme_advanced_blockformats', t.settings.theme_advanced_blockformats, 'hash'), function(v, k) {
   249 				c.add(t.editor.translate(fmts[v]), v, {element : v, 'class' : v.indexOf('h') == 0 ? '' : 'mcePreview'});
   255 					c.add(t.editor.translate(k != v ? k : fmts[v]), v, {'class' : 'mce_formatPreview mce_' + v});
   250 			});
   256 				});
       
   257 			}
   251 
   258 
   252 			return c;
   259 			return c;
   253 		},
   260 		},
   254 
   261 
   255 		_createForeColorMenu : function() {
   262 		_createForeColorMenu : function() {
   329 			}
   336 			}
   330 
   337 
   331 			n = o.targetNode;
   338 			n = o.targetNode;
   332 
   339 
   333 			// Add classes to first and last TRs
   340 			// Add classes to first and last TRs
   334 			nl = sc.rows;
   341 			nl = DOM.stdMode ? sc.getElementsByTagName('tr') : sc.rows; // Quick fix for IE 8
   335 			DOM.addClass(nl[0], 'mceFirst');
   342 			DOM.addClass(nl[0], 'mceFirst');
   336 			DOM.addClass(nl[nl.length - 1], 'mceLast');
   343 			DOM.addClass(nl[nl.length - 1], 'mceLast');
   337 
   344 
   338 			// Add classes to first and last TDs
   345 			// Add classes to first and last TDs
   339 			each(DOM.select('tr', tb), function(n) {
   346 			each(DOM.select('tr', tb), function(n) {
   423 			dh = e.clientHeight - ifr.clientHeight;
   430 			dh = e.clientHeight - ifr.clientHeight;
   424 
   431 
   425 			// Resize iframe and container
   432 			// Resize iframe and container
   426 			DOM.setStyle(ifr, 'height', h - dh);
   433 			DOM.setStyle(ifr, 'height', h - dh);
   427 			DOM.setStyles(e, {width : w, height : h});
   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');
   428 		},
   443 		},
   429 
   444 
   430 		// Internal functions
   445 		// Internal functions
   431 
   446 
   432 		_simpleLayout : function(s, tb, o, p) {
   447 		_simpleLayout : function(s, tb, o, p) {
   499 			var t = this, ed = t.editor, dc, da, cf = ed.controlManager, n, ic, to, a;
   514 			var t = this, ed = t.editor, dc, da, cf = ed.controlManager, n, ic, to, a;
   500 
   515 
   501 			dc = s.theme_advanced_containers_default_class || '';
   516 			dc = s.theme_advanced_containers_default_class || '';
   502 			da = s.theme_advanced_containers_default_align || 'center';
   517 			da = s.theme_advanced_containers_default_align || 'center';
   503 
   518 
   504 			each((s.theme_advanced_containers || '').split(','), function(c, i) {
   519 			each(explode(s.theme_advanced_containers || ''), function(c, i) {
   505 				var v = s['theme_advanced_container_' + c] || '';
   520 				var v = s['theme_advanced_container_' + c] || '';
   506 
   521 
   507 				switch (c.toLowerCase()) {
   522 				switch (v.toLowerCase()) {
   508 					case 'mceeditor':
   523 					case 'mceeditor':
   509 						n = DOM.add(tb, 'tr');
   524 						n = DOM.add(tb, 'tr');
   510 						n = ic = DOM.add(n, 'td', {'class' : 'mceIframeContainer'});
   525 						n = ic = DOM.add(n, 'td', {'class' : 'mceIframeContainer'});
   511 						break;
   526 						break;
   512 
   527 
   513 					case 'mceelementpath':
   528 					case 'mceelementpath':
   514 						t._addStatusBar(tb, o);
   529 						t._addStatusBar(tb, o);
   515 						break;
   530 						break;
   516 
   531 
   517 					default:
   532 					default:
   518 						a = s['theme_advanced_container_' + c + '_align'].toLowerCase();
   533 						a = (s['theme_advanced_container_' + c + '_align'] || da).toLowerCase();
   519 						a = 'mce' + t._ufirst(a);
   534 						a = 'mce' + t._ufirst(a);
   520 
   535 
   521 						n = DOM.add(DOM.add(tb, 'tr'), 'td', {
   536 						n = DOM.add(DOM.add(tb, 'tr'), 'td', {
   522 							'class' : 'mceToolbar ' + (s['theme_advanced_container_' + c + '_class'] || dc) + ' ' + a || da
   537 							'class' : 'mceToolbar ' + (s['theme_advanced_container_' + c + '_class'] || dc) + ' ' + a || da
   523 						});
   538 						});
   536 			var t = this, s = t.settings, di, cf = t.editor.controlManager;
   551 			var t = this, s = t.settings, di, cf = t.editor.controlManager;
   537 
   552 
   538 			if (s.theme_advanced_disable && !t._disabled) {
   553 			if (s.theme_advanced_disable && !t._disabled) {
   539 				di = {};
   554 				di = {};
   540 
   555 
   541 				each(s.theme_advanced_disable.split(','), function(v) {
   556 				each(explode(s.theme_advanced_disable), function(v) {
   542 					di[v] = 1;
   557 					di[v] = 1;
   543 				});
   558 				});
   544 
   559 
   545 				t._disabled = di;
   560 				t._disabled = di;
   546 			} else
   561 			} else
   547 				di = t._disabled;
   562 				di = t._disabled;
   548 
   563 
   549 			each(v.split(','), function(n) {
   564 			each(explode(v), function(n) {
   550 				var c;
   565 				var c;
   551 
   566 
   552 				if (di && di[n])
   567 				if (di && di[n])
   553 					return;
   568 					return;
   554 
   569 
   623 
   638 
   624 						if (!o)
   639 						if (!o)
   625 							return;
   640 							return;
   626 
   641 
   627 						if (s.theme_advanced_resize_horizontal)
   642 						if (s.theme_advanced_resize_horizontal)
   628 							c.style.width = o.cw + 'px';
   643 							c.style.width = Math.max(10, o.cw) + 'px';
   629 
   644 
   630 						c.style.height = o.ch + 'px';
   645 						c.style.height = Math.max(10, o.ch) + 'px';
   631 						DOM.get(ed.id + '_ifr').style.height = (parseInt(o.ch) + t.deltaHeight) + 'px';
   646 						DOM.get(ed.id + '_ifr').style.height = Math.max(10, parseInt(o.ch) + t.deltaHeight) + 'px';
   632 					});
   647 					});
   633 				}
   648 				}
   634 
   649 
   635 				ed.onPostRender.add(function() {
   650 				ed.onPostRender.add(function() {
   636 					Event.add(ed.id + '_resize', 'mousedown', function(e) {
   651 					Event.add(ed.id + '_resize', 'mousedown', function(e) {
   663 							dx : null,
   678 							dx : null,
   664 							dy : null
   679 							dy : null
   665 						};
   680 						};
   666 
   681 
   667 						// Start listening
   682 						// Start listening
   668 						mf = Event.add(document, 'mousemove', function(e) {
   683 						mf = Event.add(DOM.doc, 'mousemove', function(e) {
   669 							var w, h;
   684 							var w, h;
   670 
   685 
   671 							// Calc delta values
   686 							// Calc delta values
   672 							r.dx = e.screenX - r.x;
   687 							r.dx = e.screenX - r.x;
   673 							r.dy = e.screenY - r.y;
   688 							r.dy = e.screenY - r.y;
   685 							p.style.height = h + 'px';
   700 							p.style.height = h + 'px';
   686 
   701 
   687 							return Event.cancel(e);
   702 							return Event.cancel(e);
   688 						});
   703 						});
   689 
   704 
   690 						me = Event.add(document, 'mouseup', function(e) {
   705 						me = Event.add(DOM.doc, 'mouseup', function(e) {
   691 							var ifr;
   706 							var ifr;
   692 
   707 
   693 							// Stop listening
   708 							// Stop listening
   694 							Event.remove(document, 'mousemove', mf);
   709 							Event.remove(DOM.doc, 'mousemove', mf);
   695 							Event.remove(document, 'mouseup', me);
   710 							Event.remove(DOM.doc, 'mouseup', me);
   696 
   711 
   697 							c.style.display = '';
   712 							c.style.display = '';
   698 							DOM.remove(p);
   713 							DOM.remove(p);
   699 
   714 
   700 							if (r.dx === null)
   715 							if (r.dx === null)
   701 								return;
   716 								return;
   702 
   717 
   703 							ifr = DOM.get(ed.id + '_ifr');
   718 							ifr = DOM.get(ed.id + '_ifr');
   704 
   719 
   705 							if (s.theme_advanced_resize_horizontal)
   720 							if (s.theme_advanced_resize_horizontal)
   706 								c.style.width = (r.w + r.dx) + 'px';
   721 								c.style.width = Math.max(10, r.w + r.dx) + 'px';
   707 
   722 
   708 							c.style.height = (r.h + r.dy) + 'px';
   723 							c.style.height = Math.max(10, r.h + r.dy) + 'px';
   709 							ifr.style.height = (ifr.clientHeight + r.dy) + 'px';
   724 							ifr.style.height = Math.max(10, ifr.clientHeight + r.dy) + 'px';
   710 
   725 
   711 							if (s.theme_advanced_resizing_use_cookie) {
   726 							if (s.theme_advanced_resizing_use_cookie) {
   712 								Cookie.setHash("TinyMCE_" + ed.id + "_size", {
   727 								Cookie.setHash("TinyMCE_" + ed.id + "_size", {
   713 									cw : r.w + r.dx,
   728 									cw : r.w + r.dx,
   714 									ch : r.h + r.dy
   729 									ch : r.h + r.dy
   780 
   795 
   781 			if (c = cm.get('fontselect'))
   796 			if (c = cm.get('fontselect'))
   782 				c.select(ed.queryCommandValue('FontName'));
   797 				c.select(ed.queryCommandValue('FontName'));
   783 
   798 
   784 			if (c = cm.get('fontsizeselect'))
   799 			if (c = cm.get('fontsizeselect'))
   785 				c.select(ed.queryCommandValue('FontSize'));
   800 				c.select('' + ed.queryCommandValue('FontSize'));
   786 
   801 
   787 			if (s.theme_advanced_path && s.theme_advanced_statusbar_location) {
   802 			if (s.theme_advanced_path && s.theme_advanced_statusbar_location) {
   788 				p = DOM.get(ed.id + '_path') || DOM.add(ed.id + '_path_row', 'span', {id : ed.id + '_path'});
   803 				p = DOM.get(ed.id + '_path') || DOM.add(ed.id + '_path_row', 'span', {id : ed.id + '_path'});
   789 				DOM.setHTML(p, '');
   804 				DOM.setHTML(p, '');
   790 
   805 
   877 
   892 
   878 					//u = "javascript:tinymce.EditorManager.get('" + ed.id + "').theme._sel('" + (de++) + "');";
   893 					//u = "javascript:tinymce.EditorManager.get('" + ed.id + "').theme._sel('" + (de++) + "');";
   879 					pi = DOM.create('a', {'href' : "javascript:;", onmousedown : "return false;", title : ti, 'class' : 'mcePath_' + (de++)}, na);
   894 					pi = DOM.create('a', {'href' : "javascript:;", onmousedown : "return false;", title : ti, 'class' : 'mcePath_' + (de++)}, na);
   880 
   895 
   881 					if (p.hasChildNodes()) {
   896 					if (p.hasChildNodes()) {
   882 						p.insertBefore(document.createTextNode(' \u00bb '), p.firstChild);
   897 						p.insertBefore(DOM.doc.createTextNode(' \u00bb '), p.firstChild);
   883 						p.insertBefore(pi, p.firstChild);
   898 						p.insertBefore(pi, p.firstChild);
   884 					} else
   899 					} else
   885 						p.appendChild(pi);
   900 						p.appendChild(pi);
   886 				}, ed.getBody());
   901 				}, ed.getBody());
   887 			}
   902 			}
   966 		},
   981 		},
   967 
   982 
   968 		_mceImage : function(ui, val) {
   983 		_mceImage : function(ui, val) {
   969 			var ed = this.editor;
   984 			var ed = this.editor;
   970 
   985 
       
   986 			// Internal image object like a flash placeholder
       
   987 			if (ed.dom.getAttrib(ed.selection.getNode(), 'class').indexOf('mceItem') != -1)
       
   988 				return;
       
   989 
   971 			ed.windowManager.open({
   990 			ed.windowManager.open({
   972 				url : tinymce.baseURL + '/themes/advanced/image.htm',
   991 				url : tinymce.baseURL + '/themes/advanced/image.htm',
   973 				width : 355 + parseInt(ed.getLang('advanced.image_delta_width', 0)),
   992 				width : 355 + parseInt(ed.getLang('advanced.image_delta_width', 0)),
   974 				height : 275 + parseInt(ed.getLang('advanced.image_delta_height', 0)),
   993 				height : 275 + parseInt(ed.getLang('advanced.image_delta_height', 0)),
   975 				inline : true
   994 				inline : true
  1002 
  1021 
  1003 		_mceForeColor : function() {
  1022 		_mceForeColor : function() {
  1004 			var t = this;
  1023 			var t = this;
  1005 
  1024 
  1006 			this._mceColorPicker(0, {
  1025 			this._mceColorPicker(0, {
       
  1026 				color: t.fgColor,
  1007 				func : function(co) {
  1027 				func : function(co) {
       
  1028 					t.fgColor = co;
  1008 					t.editor.execCommand('ForeColor', false, co);
  1029 					t.editor.execCommand('ForeColor', false, co);
  1009 				}
  1030 				}
  1010 			});
  1031 			});
  1011 		},
  1032 		},
  1012 
  1033 
  1013 		_mceBackColor : function() {
  1034 		_mceBackColor : function() {
  1014 			var t = this;
  1035 			var t = this;
  1015 
  1036 
  1016 			this._mceColorPicker(0, {
  1037 			this._mceColorPicker(0, {
       
  1038 				color: t.bgColor,
  1017 				func : function(co) {
  1039 				func : function(co) {
       
  1040 					t.bgColor = co;
  1018 					t.editor.execCommand('HiliteColor', false, co);
  1041 					t.editor.execCommand('HiliteColor', false, co);
  1019 				}
  1042 				}
  1020 			});
  1043 			});
  1021 		},
  1044 		},
  1022 
  1045