      1 /*
      2 Copyright (c) 2003-2009, CKSource - Frederico Knabben. All rights reserved.
      3 For licensing, see LICENSE.html or http://ckeditor.com/license
      4 */
      5
      6 (function()
      7 {
      8 	function addCombo( editor, comboName, styleType, lang, entries, defaultLabel, styleDefinition )
      9 	{
     10 		var config = editor.config;
     11
     12 		// Gets the list of fonts from the settings.
     13 		var names = entries.split( ';' ),
     14 			values = [];
     15
     16 		// Create style objects for all fonts.
     17 		var styles = {};
     18 		for ( var i = 0 ; i < names.length ; i++ )
     19 		{
     20 			var vars = {};
     21 			var parts = names[ i ].split( '/' );
     22
     23 			var name = names[ i ] = parts[ 0 ];
     24 			vars[ styleType ] = values[ i ] = parts[ 1 ] || name;
     25
     26 			styles[ name ] = new CKEDITOR.style( styleDefinition, vars );
     27 		}
     28
     29 		editor.ui.addRichCombo( comboName,
     30 			{
     31 				label : lang.label,
     32 				title : lang.panelTitle,
     33 				voiceLabel : lang.voiceLabel,
     34 				className : 'cke_' + ( styleType == 'size' ? 'fontSize' : 'font' ),
     35 				multiSelect : false,
     36
     37 				panel :
     38 				{
     39 					css : [ config.contentsCss, CKEDITOR.getUrl( editor.skinPath + 'editor.css' ) ],
     40 					voiceLabel : lang.panelVoiceLabel
     41 				},
     42
     43 				init : function()
     44 				{
     45 					this.startGroup( lang.panelTitle );
     46
     47 					for ( var i = 0 ; i < names.length ; i++ )
     48 					{
     49 						var name = names[ i ];
     50
     51 						// Add the tag entry to the panel list.
     52 						this.add( name, '<span style="font-' + styleType + ':' + values[ i ] + '">' + name + '</span>', name );
     53 					}
     54 				},
     55
     56 				onClick : function( value )
     57 				{
     58 					editor.focus();
     59 					editor.fire( 'saveSnapshot' );
     60
     61 					var style = styles[ value ];
     62
     63 					if ( this.getValue() == value )
     64 						style.remove( editor.document );
     65 					else
     66 						style.apply( editor.document );
     67
     68 					editor.fire( 'saveSnapshot' );
     69 				},
     70
     71 				onRender : function()
     72 				{
     73 					editor.on( 'selectionChange', function( ev )
     74 						{
     75 							var currentValue = this.getValue();
     76
     77 							var elementPath = ev.data.path,
     78 								elements = elementPath.elements;
     79
     80 							// For each element into the elements path.
     81 							for ( var i = 0, element ; i < elements.length ; i++ )
     82 							{
     83 								element = elements[i];
     84
     85 								// Check if the element is removable by any of
     86 								// the styles.
     87 								for ( var value in styles )
     88 								{
     89 									if ( styles[ value ].checkElementRemovable( element, true ) )
     90 									{
     91 										if ( value != currentValue )
     92 											this.setValue( value );
     93 										return;
     94 									}
     95 								}
     96 							}
     97
     98 							// If no styles match, just empty it.
     99 							this.setValue( '', defaultLabel );
    100 						},
    101 						this);
    102 				}
    103 			});
    104 	}
    105
    106 	CKEDITOR.plugins.add( 'font',
    107 	{
    108 		requires : [ 'richcombo', 'styles' ],
    109
    110 		init : function( editor )
    111 		{
    112 			var config = editor.config;
    113
    114 			addCombo( editor, 'Font', 'family', editor.lang.font, config.font_names, config.font_defaultLabel, config.font_style );
    115 			addCombo( editor, 'FontSize', 'size', editor.lang.fontSize, config.fontSize_sizes, config.fontSize_defaultLabel, config.fontSize_style );
    116 		}
    117 	});
    118 })();
    119
    120 // Font settings.
    121
    122 CKEDITOR.config.font_names =
    123 	'Arial/Arial, Helvetica, sans-serif;' +
    124 	'Comic Sans MS/Comic Sans MS, cursive;' +
    125 	'Courier New/Courier New, Courier, monospace;' +
    126 	'Georgia/Georgia, serif;' +
    127 	'Lucida Sans Unicode/Lucida Sans Unicode, Lucida Grande, sans-serif;' +
    128 	'Tahoma/Tahoma, Geneva, sans-serif;' +
    129 	'Times New Roman/Times New Roman, Times, serif;' +
    130 	'Trebuchet MS/Trebuchet MS, Helvetica, sans-serif;' +
    131 	'Verdana/Verdana, Geneva, sans-serif';
    132
    133 CKEDITOR.config.font_defaultLabel = '';
    134 CKEDITOR.config.font_style =
    135 	{
    136 		element		: 'span',
    137 		styles		: { 'font-family' : '#(family)' },
    138 		overrides	: [ { element : 'font', attributes : { 'face' : null } } ]
    139 	};
    140
    141 // Font Size setting.
    142
    143 CKEDITOR.config.fontSize_sizes =
    144 	'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';
    145
    146 CKEDITOR.config.fontSize_defaultLabel = '';
    147 CKEDITOR.config.fontSize_style =
    148 	{
    149 		element		: 'span',
    150 		styles		: { 'font-size' : '#(size)' },
    151 		overrides	: [ { element : 'font', attributes : { 'face' : null } } ]
    152 	};
    153