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