2 Copyright (c) 2003-2010, CKSource - Frederico Knabben. All rights reserved.
\r
3 For licensing, see LICENSE.html or http://ckeditor.com/license
\r
8 function addCombo( editor, comboName, styleType, lang, entries, defaultLabel, styleDefinition )
\r
10 var config = editor.config;
\r
12 // Gets the list of fonts from the settings.
\r
13 var names = entries.split( ';' ),
\r
16 // Create style objects for all fonts.
\r
18 for ( var i = 0 ; i < names.length ; i++ )
\r
20 var parts = names[ i ];
\r
24 parts = parts.split( '/' );
\r
27 name = names[ i ] = parts[ 0 ];
\r
29 vars[ styleType ] = values[ i ] = parts[ 1 ] || name;
\r
31 styles[ name ] = new CKEDITOR.style( styleDefinition, vars );
\r
34 names.splice( i--, 1 );
\r
37 editor.ui.addRichCombo( comboName,
\r
40 title : lang.panelTitle,
\r
41 voiceLabel : lang.voiceLabel,
\r
42 className : 'cke_' + ( styleType == 'size' ? 'fontSize' : 'font' ),
\r
43 multiSelect : false,
\r
47 css : editor.skin.editor.css.concat( config.contentsCss ),
\r
48 voiceLabel : lang.panelVoiceLabel
\r
53 this.startGroup( lang.panelTitle );
\r
55 for ( var i = 0 ; i < names.length ; i++ )
\r
57 var name = names[ i ];
\r
59 // Add the tag entry to the panel list.
\r
60 this.add( name, '<span style="font-' + styleType + ':' + values[ i ] + '">' + name + '</span>', name );
\r
64 onClick : function( value )
\r
67 editor.fire( 'saveSnapshot' );
\r
69 var style = styles[ value ];
\r
71 if ( this.getValue() == value )
\r
72 style.remove( editor.document );
\r
74 style.apply( editor.document );
\r
76 editor.fire( 'saveSnapshot' );
\r
79 onRender : function()
\r
81 editor.on( 'selectionChange', function( ev )
\r
83 var currentValue = this.getValue();
\r
85 var elementPath = ev.data.path,
\r
86 elements = elementPath.elements;
\r
88 // For each element into the elements path.
\r
89 for ( var i = 0, element ; i < elements.length ; i++ )
\r
91 element = elements[i];
\r
93 // Check if the element is removable by any of
\r
95 for ( var value in styles )
\r
97 if ( styles[ value ].checkElementRemovable( element, true ) )
\r
99 if ( value != currentValue )
\r
100 this.setValue( value );
\r
106 // If no styles match, just empty it.
\r
107 this.setValue( '', defaultLabel );
\r
114 CKEDITOR.plugins.add( 'font',
\r
116 requires : [ 'richcombo', 'styles' ],
\r
118 init : function( editor )
\r
120 var config = editor.config;
\r
122 addCombo( editor, 'Font', 'family', editor.lang.font, config.font_names, config.font_defaultLabel, config.font_style );
\r
123 addCombo( editor, 'FontSize', 'size', editor.lang.fontSize, config.fontSize_sizes, config.fontSize_defaultLabel, config.fontSize_style );
\r
129 * The list of fonts names to be displayed in the Font combo in the toolbar.
\r
130 * Entries are separated by semi-colons (;), while it's possible to have more
\r
131 * than one font for each entry, in the HTML way (separated by comma).
\r
133 * A display name may be optionally defined by prefixing the entries with the
\r
134 * name and the slash character. For example, "Arial/Arial, Helvetica, sans-serif"
\r
135 * will be displayed as "Arial" in the list, but will be outputted as
\r
136 * "Arial, Helvetica, sans-serif".
\r
139 * config.font_names =
\r
140 * 'Arial/Arial, Helvetica, sans-serif;' +
\r
141 * 'Times New Roman/Times New Roman, Times, serif;' +
\r
144 * config.font_names = 'Arial;Times New Roman;Verdana';
\r
146 CKEDITOR.config.font_names =
\r
147 'Arial/Arial, Helvetica, sans-serif;' +
\r
148 'Comic Sans MS/Comic Sans MS, cursive;' +
\r
149 'Courier New/Courier New, Courier, monospace;' +
\r
150 'Georgia/Georgia, serif;' +
\r
151 'Lucida Sans Unicode/Lucida Sans Unicode, Lucida Grande, sans-serif;' +
\r
152 'Tahoma/Tahoma, Geneva, sans-serif;' +
\r
153 'Times New Roman/Times New Roman, Times, serif;' +
\r
154 'Trebuchet MS/Trebuchet MS, Helvetica, sans-serif;' +
\r
155 'Verdana/Verdana, Geneva, sans-serif';
\r
158 * The text to be displayed in the Font combo is none of the available values
\r
159 * matches the current cursor position or text selection.
\r
162 * // If the default site font is Arial, we may making it more explicit to the end user.
\r
163 * config.font_defaultLabel = 'Arial';
\r
165 CKEDITOR.config.font_defaultLabel = '';
\r
168 * The style definition to be used to apply the font in the text.
\r
171 * // This is actually the default value for it.
\r
172 * config.font_style =
\r
174 * element : 'span',
\r
175 * styles : { 'font-family' : '#(family)' },
\r
176 * overrides : [ { element : 'font', attributes : { 'face' : null } } ]
\r
179 CKEDITOR.config.font_style =
\r
182 styles : { 'font-family' : '#(family)' },
\r
183 overrides : [ { element : 'font', attributes : { 'face' : null } } ]
\r
187 * The list of fonts size to be displayed in the Font Size combo in the
\r
188 * toolbar. Entries are separated by semi-colons (;).
\r
190 * Any kind of "CSS like" size can be used, like "12px", "2.3em", "130%",
\r
191 * "larger" or "x-small".
\r
193 * A display name may be optionally defined by prefixing the entries with the
\r
194 * name and the slash character. For example, "Bigger Font/14px" will be
\r
195 * displayed as "Bigger Font" in the list, but will be outputted as "14px".
\r
197 * @default '8/8px;9/9px;10/10px;11/11px;12/12px;14/14px;16/16px;18/18px;20/20px;22/22px;24/24px;26/26px;28/28px;36/36px;48/48px;72/72px'
\r
199 * config.fontSize_sizes = '16/16px;24/24px;48/48px;';
\r
201 * config.fontSize_sizes = '12px;2.3em;130%;larger;x-small';
\r
203 * config.fontSize_sizes = '12 Pixels/12px;Big/2.3em;30 Percent More/130%;Bigger/larger;Very Small/x-small';
\r
205 CKEDITOR.config.fontSize_sizes =
\r
206 '8/8px;9/9px;10/10px;11/11px;12/12px;14/14px;16/16px;18/18px;20/20px;22/22px;24/24px;26/26px;28/28px;36/36px;48/48px;72/72px';
\r
209 * The text to be displayed in the Font Size combo is none of the available
\r
210 * values matches the current cursor position or text selection.
\r
213 * // If the default site font size is 12px, we may making it more explicit to the end user.
\r
214 * config.fontSize_defaultLabel = '12px';
\r
216 CKEDITOR.config.fontSize_defaultLabel = '';
\r
219 * The style definition to be used to apply the font size in the text.
\r
222 * // This is actually the default value for it.
\r
223 * config.fontSize_style =
\r
225 * element : 'span',
\r
226 * styles : { 'font-size' : '#(size)' },
\r
227 * overrides : [ { element : 'font', attributes : { 'size' : null } } ]
\r
230 CKEDITOR.config.fontSize_style =
\r
233 styles : { 'font-size' : '#(size)' },
\r
234 overrides : [ { element : 'font', attributes : { 'size' : null } } ]
\r