includes/clientside/tinymce/themes/advanced/editor_template_src.js
changeset 778 57ce13805b6f
parent 588 20484deb89cd
child 1193 e3b94bd055dc
equal deleted inserted replaced
777:488665d49417 778:57ce13805b6f
     1 /**
     1 /**
     2  * $Id: editor_template_src.js 852 2008-05-27 05:52:09Z spocke $
     2  * $Id: editor_template_src.js 960 2008-11-12 18:30: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 
    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', {
       
    15 		sizes : [8, 10, 12, 14, 18, 24, 36],
       
    16 
    15 		// Control name lookup, format: title, command
    17 		// Control name lookup, format: title, command
    16 		controls : {
    18 		controls : {
    17 			bold : ['bold_desc', 'Bold'],
    19 			bold : ['bold_desc', 'Bold'],
    18 			italic : ['italic_desc', 'Italic'],
    20 			italic : ['italic_desc', 'Italic'],
    19 			underline : ['underline_desc', 'Underline'],
    21 			underline : ['underline_desc', 'Underline'],
    53 		},
    55 		},
    54 
    56 
    55 		stateControls : ['bold', 'italic', 'underline', 'strikethrough', 'bullist', 'numlist', 'justifyleft', 'justifycenter', 'justifyright', 'justifyfull', 'sub', 'sup', 'blockquote'],
    57 		stateControls : ['bold', 'italic', 'underline', 'strikethrough', 'bullist', 'numlist', 'justifyleft', 'justifycenter', 'justifyright', 'justifyfull', 'sub', 'sup', 'blockquote'],
    56 
    58 
    57 		init : function(ed, url) {
    59 		init : function(ed, url) {
    58 			var t = this, s, v;
    60 			var t = this, s, v, o;
    59 	
    61 	
    60 			t.editor = ed;
    62 			t.editor = ed;
    61 			t.url = url;
    63 			t.url = url;
    62 			t.onResolveName = new tinymce.util.Dispatcher(this);
    64 			t.onResolveName = new tinymce.util.Dispatcher(this);
    63 
    65 
    69 				theme_advanced_buttons2 : "bullist,numlist,|,outdent,indent,|,undo,redo,|,link,unlink,anchor,image,cleanup,help,code",
    71 				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",
    72 				theme_advanced_buttons3 : "hr,removeformat,visualaid,|,sub,sup,|,charmap",
    71 				theme_advanced_blockformats : "p,address,pre,h1,h2,h3,h4,h5,h6",
    73 				theme_advanced_blockformats : "p,address,pre,h1,h2,h3,h4,h5,h6",
    72 				theme_advanced_toolbar_align : "center",
    74 				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",
    75 				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_more_colors : 1,
    76 				theme_advanced_row_height : 23,
    77 				theme_advanced_row_height : 23,
    77 				theme_advanced_resize_horizontal : 1,
    78 				theme_advanced_resize_horizontal : 1,
    78 				theme_advanced_resizing_use_cookie : 1
    79 				theme_advanced_resizing_use_cookie : 1,
       
    80 				theme_advanced_font_sizes : "1,2,3,4,5,6,7",
       
    81 				readonly : ed.settings.readonly
    79 			}, ed.settings);
    82 			}, ed.settings);
       
    83 
       
    84 			// Setup default font_size_style_values
       
    85 			if (!s.font_size_style_values)
       
    86 				s.font_size_style_values = "8pt,10pt,12pt,14pt,18pt,24pt,36pt";
       
    87 
       
    88 			if (tinymce.is(s.theme_advanced_font_sizes, 'string')) {
       
    89 				s.font_size_style_values = tinymce.explode(s.font_size_style_values);
       
    90 				s.font_size_classes = tinymce.explode(s.font_size_classes || '');
       
    91 
       
    92 				// Parse string value
       
    93 				o = {};
       
    94 				ed.settings.theme_advanced_font_sizes = s.theme_advanced_font_sizes;
       
    95 				each(ed.getParam('theme_advanced_font_sizes', '', 'hash'), function(v, k) {
       
    96 					var cl;
       
    97 
       
    98 					if (k == v && v >= 1 && v <= 7) {
       
    99 						k = v + ' (' + t.sizes[v - 1] + 'pt)';
       
   100 
       
   101 						if (ed.settings.convert_fonts_to_spans) {
       
   102 							cl = s.font_size_classes[v - 1];
       
   103 							v = s.font_size_style_values[v - 1] || (t.sizes[v - 1] + 'pt');
       
   104 						}
       
   105 					}
       
   106 
       
   107 					if (/\s*\./.test(v))
       
   108 						cl = v.replace(/\./g, '');
       
   109 
       
   110 					o[k] = cl ? {'class' : cl} : {fontSize : v};
       
   111 				});
       
   112 
       
   113 				s.theme_advanced_font_sizes = o;
       
   114 			}
    80 
   115 
    81 			if ((v = s.theme_advanced_path_location) && v != 'none')
   116 			if ((v = s.theme_advanced_path_location) && v != 'none')
    82 				s.theme_advanced_statusbar_location = s.theme_advanced_path_location;
   117 				s.theme_advanced_statusbar_location = s.theme_advanced_path_location;
    83 
   118 
    84 			if (s.theme_advanced_statusbar_location == 'none')
   119 			if (s.theme_advanced_statusbar_location == 'none')
   109 					DOM.remove(id + '_progress');
   144 					DOM.remove(id + '_progress');
   110 					clearTimeout(t.progressTimer);
   145 					clearTimeout(t.progressTimer);
   111 				}
   146 				}
   112 			});
   147 			});
   113 
   148 
   114 			DOM.loadCSS(ed.baseURI.toAbsolute(s.editor_css || "themes/advanced/skins/" + ed.settings.skin + "/ui.css"));
   149 			DOM.loadCSS(s.editor_css ? ed.documentBaseURI.toAbsolute(s.editor_css) : url + "/skins/" + ed.settings.skin + "/ui.css");
   115 
   150 
   116 			if (s.skin_variant)
   151 			if (s.skin_variant)
   117 				DOM.loadCSS(ed.baseURI.toAbsolute(s.editor_css || "themes/advanced/skins/" + ed.settings.skin + "/ui_" + s.skin_variant + ".css"));
   152 				DOM.loadCSS(url + "/skins/" + ed.settings.skin + "/ui_" + s.skin_variant + ".css");
   118 		},
   153 		},
   119 
   154 
   120 		createControl : function(n, cf) {
   155 		createControl : function(n, cf) {
   121 			var cd, c;
   156 			var cd, c;
   122 
   157 
   186 					if (v)
   221 					if (v)
   187 						c.add(t.editor.translate(k), v);
   222 						c.add(t.editor.translate(k), v);
   188 				});
   223 				});
   189 
   224 
   190 				c.onPostRender.add(function(ed, n) {
   225 				c.onPostRender.add(function(ed, n) {
   191 					Event.add(n.id + '_text', 'focus', t._importClasses, t);
   226 					if (!c.NativeListBox) {
   192 					Event.add(n.id + '_text', 'mousedown', t._importClasses, t);
   227 						Event.add(n.id + '_text', 'focus', t._importClasses, t);
       
   228 						Event.add(n.id + '_text', 'mousedown', t._importClasses, t);
       
   229 						Event.add(n.id + '_open', 'focus', t._importClasses, t);
       
   230 						Event.add(n.id + '_open', 'mousedown', t._importClasses, t);
       
   231 					} else
       
   232 						Event.add(n.id, 'focus', t._importClasses, t);
   193 				});
   233 				});
   194 			}
   234 			}
   195 
   235 
   196 			return c;
   236 			return c;
   197 		},
   237 		},
   208 
   248 
   209 			return c;
   249 			return c;
   210 		},
   250 		},
   211 
   251 
   212 		_createFontSizeSelect : function() {
   252 		_createFontSizeSelect : function() {
   213 			var t = this, ed = t.editor, c, lo = [
   253 			var t = this, ed = t.editor, c, i = 0, cl = [];
   214 				"1 (8 pt)",
   254 
   215 				"2 (10 pt)",
   255 			c = ed.controlManager.createListBox('fontsizeselect', {title : 'advanced.font_size', onselect : function(v) {
   216 				"3 (12 pt)",
   256 				if (v.fontSize)
   217 				"4 (14 pt)",
   257 					ed.execCommand('FontSize', false, v.fontSize);
   218 				"5 (18 pt)",
   258 				else {
   219 				"6 (24 pt)",
   259 					each(t.settings.theme_advanced_font_sizes, function(v, k) {
   220 				"7 (36 pt)"
   260 						if (v['class'])
   221 			], fz = [8, 10, 12, 14, 18, 24, 36];
   261 							cl.push(v['class']);
   222 
   262 					});
   223 			c = ed.controlManager.createListBox('fontsizeselect', {title : 'advanced.font_size', cmd : 'FontSize'});
   263 
       
   264 					ed.editorCommands._applyInlineStyle('span', {'class' : v['class']}, {check_classes : cl});
       
   265 				}
       
   266 			}});
       
   267 
   224 			if (c) {
   268 			if (c) {
   225 				each(ed.getParam('theme_advanced_font_sizes', t.settings.theme_advanced_font_sizes, 'hash'), function(v, k) {
   269 				each(t.settings.theme_advanced_font_sizes, function(v, k) {
   226 					c.add(k != v ? k : lo[parseInt(v) - 1], v, {'style' : 'font-size:' + fz[v - 1] + 'pt', 'class' : 'mceFontSize' + v});
   270 					var fz = v.fontSize;
       
   271 
       
   272 					if (fz >= 1 && fz <= 7)
       
   273 						fz = t.sizes[parseInt(fz) - 1] + 'pt';
       
   274 
       
   275 					c.add(k, v, {'style' : 'font-size:' + fz, 'class' : 'mceFontSize' + (i++) + (' ' + (v['class'] || ''))});
   227 				});
   276 				});
   228 			}
   277 			}
   229 
   278 
   230 			return c;
   279 			return c;
   231 		},
   280 		},
   274 			}
   323 			}
   275 
   324 
   276 			if (v = s.theme_advanced_text_colors)
   325 			if (v = s.theme_advanced_text_colors)
   277 				o.colors = v;
   326 				o.colors = v;
   278 
   327 
       
   328 			if (s.theme_advanced_default_foreground_color)
       
   329 				o.default_color = s.theme_advanced_default_foreground_color;
       
   330 
   279 			o.title = 'advanced.forecolor_desc';
   331 			o.title = 'advanced.forecolor_desc';
   280 			o.cmd = 'ForeColor';
   332 			o.cmd = 'ForeColor';
   281 			o.scope = this;
   333 			o.scope = this;
   282 
   334 
   283 			c = t.editor.controlManager.createColorSplitButton('forecolor', o);
   335 			c = t.editor.controlManager.createColorSplitButton('forecolor', o);
   300 			}
   352 			}
   301 
   353 
   302 			if (v = s.theme_advanced_background_colors)
   354 			if (v = s.theme_advanced_background_colors)
   303 				o.colors = v;
   355 				o.colors = v;
   304 
   356 
       
   357 			if (s.theme_advanced_default_background_color)
       
   358 				o.default_color = s.theme_advanced_default_background_color;
       
   359 
   305 			o.title = 'advanced.backcolor_desc';
   360 			o.title = 'advanced.backcolor_desc';
   306 			o.cmd = 'HiliteColor';
   361 			o.cmd = 'HiliteColor';
   307 			o.scope = this;
   362 			o.scope = this;
   308 
   363 
   309 			c = t.editor.controlManager.createColorSplitButton('backcolor', o);
   364 			c = t.editor.controlManager.createColorSplitButton('backcolor', o);
   444 
   499 
   445 		// Internal functions
   500 		// Internal functions
   446 
   501 
   447 		_simpleLayout : function(s, tb, o, p) {
   502 		_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;
   503 			var t = this, ed = t.editor, lo = s.theme_advanced_toolbar_location, sl = s.theme_advanced_statusbar_location, n, ic, etb, c;
       
   504 
       
   505 			if (s.readonly) {
       
   506 				n = DOM.add(tb, 'tr');
       
   507 				n = ic = DOM.add(n, 'td', {'class' : 'mceIframeContainer'});
       
   508 				return ic;
       
   509 			}
   449 
   510 
   450 			// Create toolbar container at top
   511 			// Create toolbar container at top
   451 			if (lo == 'top')
   512 			if (lo == 'top')
   452 				t._addToolbars(tb, o);
   513 				t._addToolbars(tb, o);
   453 
   514 
   739 			o.deltaHeight -= 21;
   800 			o.deltaHeight -= 21;
   740 			n = tb = null;
   801 			n = tb = null;
   741 		},
   802 		},
   742 
   803 
   743 		_nodeChanged : function(ed, cm, n, co) {
   804 		_nodeChanged : function(ed, cm, n, co) {
   744 			var t = this, p, de = 0, v, c, s = t.settings;
   805 			var t = this, p, de = 0, v, c, s = t.settings, cl, fz, fn;
       
   806 
       
   807 			if (s.readonly)
       
   808 				return;
   745 
   809 
   746 			tinymce.each(t.stateControls, function(c) {
   810 			tinymce.each(t.stateControls, function(c) {
   747 				cm.setActive(c, ed.queryCommandState(t.controls[c][1]));
   811 				cm.setActive(c, ed.queryCommandState(t.controls[c][1]));
   748 			});
   812 			});
   749 
   813 
   791 
   855 
   792 				if (p)
   856 				if (p)
   793 					c.select(p.nodeName.toLowerCase());
   857 					c.select(p.nodeName.toLowerCase());
   794 			}
   858 			}
   795 
   859 
   796 			if (c = cm.get('fontselect'))
   860 			if (ed.settings.convert_fonts_to_spans) {
   797 				c.select(ed.queryCommandValue('FontName'));
   861 				ed.dom.getParent(n, function(n) {
   798 
   862 					if (n.nodeName === 'SPAN') {
   799 			if (c = cm.get('fontsizeselect'))
   863 						if (!cl && n.className)
   800 				c.select('' + ed.queryCommandValue('FontSize'));
   864 							cl = n.className;
       
   865 
       
   866 						if (!fz && n.style.fontSize)
       
   867 							fz = n.style.fontSize;
       
   868 
       
   869 						if (!fn && n.style.fontFamily)
       
   870 							fn = n.style.fontFamily.replace(/[\"\']+/g, '').replace(/^([^,]+).*/, '$1').toLowerCase();
       
   871 					}
       
   872 
       
   873 					return false;
       
   874 				});
       
   875 
       
   876 				if (c = cm.get('fontselect')) {
       
   877 					c.select(function(v) {
       
   878 						return v.replace(/^([^,]+).*/, '$1').toLowerCase() == fn;
       
   879 					});
       
   880 				}
       
   881 
       
   882 				if (c = cm.get('fontsizeselect')) {
       
   883 					c.select(function(v) {
       
   884 						if (v.fontSize && v.fontSize === fz)
       
   885 							return true;
       
   886 
       
   887 						if (v['class'] && v['class'] === cl)
       
   888 							return true;
       
   889 					});
       
   890 				}
       
   891 			} else {
       
   892 				if (c = cm.get('fontselect'))
       
   893 					c.select(ed.queryCommandValue('FontName'));
       
   894 
       
   895 				if (c = cm.get('fontsizeselect')) {
       
   896 					v = ed.queryCommandValue('FontSize');
       
   897 					c.select(function(iv) {
       
   898 						return iv.fontSize == v;
       
   899 					});
       
   900 				}
       
   901 			}
   801 
   902 
   802 			if (s.theme_advanced_path && s.theme_advanced_statusbar_location) {
   903 			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'});
   904 				p = DOM.get(ed.id + '_path') || DOM.add(ed.id + '_path_row', 'span', {id : ed.id + '_path'});
   804 				DOM.setHTML(p, '');
   905 				DOM.setHTML(p, '');
   805 
   906 
   806 				ed.dom.getParent(n, function(n) {
   907 				ed.dom.getParent(n, function(n) {
   807 					var na = n.nodeName.toLowerCase(), u, pi, ti = '';
   908 					var na = n.nodeName.toLowerCase(), u, pi, ti = '';
   808 
   909 
   809 					// Ignore non element and hidden elements
   910 					// Ignore non element and hidden elements
   810 					if (n.nodeType != 1 || (DOM.hasClass(n, 'mceItemHidden') || DOM.hasClass(n, 'mceItemRemoved')))
   911 					if (n.nodeType != 1 || n.nodeName === 'BR' || (DOM.hasClass(n, 'mceItemHidden') || DOM.hasClass(n, 'mceItemRemoved')))
   811 						return;
   912 						return;
   812 
   913 
   813 					// Fake name
   914 					// Fake name
   814 					if (v = DOM.getAttrib(n, 'mce_name'))
   915 					if (v = DOM.getAttrib(n, 'mce_name'))
   815 						na = v;
   916 						na = v;
   816 	
   917 
   817 					// Handle prefix
   918 					// Handle prefix
   818 					if (tinymce.isIE && n.scopeName !== 'HTML')
   919 					if (tinymce.isIE && n.scopeName !== 'HTML')
   819 						na = n.scopeName + ':' + na;
   920 						na = n.scopeName + ':' + na;
   820 
   921 
   821 					// Remove internal prefix
   922 					// Remove internal prefix