JasonWoof Got questions, comments, patches, etc.? Contact Jason Woofenden
vanilla ckeditor-3.0
[ckeditor.git] / _source / plugins / font / plugin.js
diff --git a/_source/plugins/font/plugin.js b/_source/plugins/font/plugin.js
new file mode 100644 (file)
index 0000000..88aa38f
--- /dev/null
@@ -0,0 +1,227 @@
+/*\r
+Copyright (c) 2003-2009, CKSource - Frederico Knabben. All rights reserved.\r
+For licensing, see LICENSE.html or http://ckeditor.com/license\r
+*/\r
+\r
+(function()\r
+{\r
+       function addCombo( editor, comboName, styleType, lang, entries, defaultLabel, styleDefinition )\r
+       {\r
+               var config = editor.config;\r
+\r
+               // Gets the list of fonts from the settings.\r
+               var names = entries.split( ';' ),\r
+                       values = [];\r
+\r
+               // Create style objects for all fonts.\r
+               var styles = {};\r
+               for ( var i = 0 ; i < names.length ; i++ )\r
+               {\r
+                       var vars = {};\r
+                       var parts = names[ i ].split( '/' );\r
+\r
+                       var name = names[ i ] = parts[ 0 ];\r
+                       vars[ styleType ] = values[ i ] = parts[ 1 ] || name;\r
+\r
+                       styles[ name ] = new CKEDITOR.style( styleDefinition, vars );\r
+               }\r
+\r
+               editor.ui.addRichCombo( comboName,\r
+                       {\r
+                               label : lang.label,\r
+                               title : lang.panelTitle,\r
+                               voiceLabel : lang.voiceLabel,\r
+                               className : 'cke_' + ( styleType == 'size' ? 'fontSize' : 'font' ),\r
+                               multiSelect : false,\r
+\r
+                               panel :\r
+                               {\r
+                                       css : [ config.contentsCss, CKEDITOR.getUrl( editor.skinPath + 'editor.css' ) ],\r
+                                       voiceLabel : lang.panelVoiceLabel\r
+                               },\r
+\r
+                               init : function()\r
+                               {\r
+                                       this.startGroup( lang.panelTitle );\r
+\r
+                                       for ( var i = 0 ; i < names.length ; i++ )\r
+                                       {\r
+                                               var name = names[ i ];\r
+\r
+                                               // Add the tag entry to the panel list.\r
+                                               this.add( name, '<span style="font-' + styleType + ':' + values[ i ] + '">' + name + '</span>', name );\r
+                                       }\r
+                               },\r
+\r
+                               onClick : function( value )\r
+                               {\r
+                                       editor.focus();\r
+                                       editor.fire( 'saveSnapshot' );\r
+\r
+                                       var style = styles[ value ];\r
+\r
+                                       if ( this.getValue() == value )\r
+                                               style.remove( editor.document );\r
+                                       else\r
+                                               style.apply( editor.document );\r
+\r
+                                       editor.fire( 'saveSnapshot' );\r
+                               },\r
+\r
+                               onRender : function()\r
+                               {\r
+                                       editor.on( 'selectionChange', function( ev )\r
+                                               {\r
+                                                       var currentValue = this.getValue();\r
+\r
+                                                       var elementPath = ev.data.path,\r
+                                                               elements = elementPath.elements;\r
+\r
+                                                       // For each element into the elements path.\r
+                                                       for ( var i = 0, element ; i < elements.length ; i++ )\r
+                                                       {\r
+                                                               element = elements[i];\r
+\r
+                                                               // Check if the element is removable by any of\r
+                                                               // the styles.\r
+                                                               for ( var value in styles )\r
+                                                               {\r
+                                                                       if ( styles[ value ].checkElementRemovable( element, true ) )\r
+                                                                       {\r
+                                                                               if ( value != currentValue )\r
+                                                                                       this.setValue( value );\r
+                                                                               return;\r
+                                                                       }\r
+                                                               }\r
+                                                       }\r
+\r
+                                                       // If no styles match, just empty it.\r
+                                                       this.setValue( '', defaultLabel );\r
+                                               },\r
+                                               this);\r
+                               }\r
+                       });\r
+       }\r
+\r
+       CKEDITOR.plugins.add( 'font',\r
+       {\r
+               requires : [ 'richcombo', 'styles' ],\r
+\r
+               init : function( editor )\r
+               {\r
+                       var config = editor.config;\r
+\r
+                       addCombo( editor, 'Font', 'family', editor.lang.font, config.font_names, config.font_defaultLabel, config.font_style );\r
+                       addCombo( editor, 'FontSize', 'size', editor.lang.fontSize, config.fontSize_sizes, config.fontSize_defaultLabel, config.fontSize_style );\r
+               }\r
+       });\r
+})();\r
+\r
+/**\r
+ * The list of fonts names to be displayed in the Font combo in the toolbar.\r
+ * Entries are separated by semi-colons (;), while it's possible to have more\r
+ * than one font for each entry, in the HTML way (separated by comma).\r
+ *\r
+ * A display name may be optionally defined by prefixing the entries with the\r
+ * name and the slash character. For example, "Arial/Arial, Helvetica, sans-serif"\r
+ * will be displayed as "Arial" in the list, but will be outputted as\r
+ * "Arial, Helvetica, sans-serif".\r
+ * @type String\r
+ * @example\r
+ * config.font_names =\r
+ *     'Arial/Arial, Helvetica, sans-serif;' +\r
+ *     'Times New Roman/Times New Roman, Times, serif;' +\r
+ *     'Verdana';\r
+ * @example\r
+ * config.font_names = 'Arial;Times New Roman;Verdana';\r
+ */\r
+CKEDITOR.config.font_names =\r
+       'Arial/Arial, Helvetica, sans-serif;' +\r
+       'Comic Sans MS/Comic Sans MS, cursive;' +\r
+       'Courier New/Courier New, Courier, monospace;' +\r
+       'Georgia/Georgia, serif;' +\r
+       'Lucida Sans Unicode/Lucida Sans Unicode, Lucida Grande, sans-serif;' +\r
+       'Tahoma/Tahoma, Geneva, sans-serif;' +\r
+       'Times New Roman/Times New Roman, Times, serif;' +\r
+       'Trebuchet MS/Trebuchet MS, Helvetica, sans-serif;' +\r
+       'Verdana/Verdana, Geneva, sans-serif';\r
+\r
+/**\r
+ * The text to be displayed in the Font combo is none of the available values\r
+ * matches the current cursor position or text selection.\r
+ * @type String\r
+ * @example\r
+ * // If the default site font is Arial, we may making it more explicit to the end user.\r
+ * config.font_defaultLabel = 'Arial';\r
+ */\r
+CKEDITOR.config.font_defaultLabel = '';\r
+\r
+/**\r
+ * The style definition to be used to apply the font in the text.\r
+ * @type Object\r
+ * @example\r
+ * // This is actually the default value for it.\r
+ * config.font_style =\r
+ *     {\r
+ *         element             : 'span',\r
+ *         styles              : { 'font-family' : '#(family)' },\r
+ *         overrides   : [ { element : 'font', attributes : { 'face' : null } } ]\r
+ *     };\r
+ */\r
+CKEDITOR.config.font_style =\r
+       {\r
+               element         : 'span',\r
+               styles          : { 'font-family' : '#(family)' },\r
+               overrides       : [ { element : 'font', attributes : { 'face' : null } } ]\r
+       };\r
+\r
+/**\r
+ * The list of fonts size to be displayed in the Font Size combo in the\r
+ * toolbar. Entries are separated by semi-colons (;).\r
+ *\r
+ * Any kind of "CSS like" size can be used, like "12px", "2.3em", "130%",\r
+ * "larger" or "x-small".\r
+ *\r
+ * A display name may be optionally defined by prefixing the entries with the\r
+ * name and the slash character. For example, "Bigger Font/14px" will be\r
+ * displayed as "Bigger Font" in the list, but will be outputted as "14px".\r
+ * @type String\r
+ * @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
+ * @example\r
+ * config.fontSize_sizes = '16/16px;24/24px;48/48px;';\r
+ * @example\r
+ * config.fontSize_sizes = '12px;2.3em;130%;larger;x-small';\r
+ * @example\r
+ * config.fontSize_sizes = '12 Pixels/12px;Big/2.3em;30 Percent More/130%;Bigger/larger;Very Small/x-small';\r
+ */\r
+CKEDITOR.config.fontSize_sizes =\r
+       '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
+\r
+/**\r
+ * The text to be displayed in the Font Size combo is none of the available\r
+ * values matches the current cursor position or text selection.\r
+ * @type String\r
+ * @example\r
+ * // If the default site font size is 12px, we may making it more explicit to the end user.\r
+ * config.fontSize_defaultLabel = '12px';\r
+ */\r
+CKEDITOR.config.fontSize_defaultLabel = '';\r
+\r
+/**\r
+ * The style definition to be used to apply the font size in the text.\r
+ * @type Object\r
+ * @example\r
+ * // This is actually the default value for it.\r
+ * config.fontSize_style =\r
+ *     {\r
+ *         element             : 'span',\r
+ *         styles              : { 'font-size' : '#(size)' },\r
+ *         overrides   : [ { element : 'font', attributes : { 'size' : null } } ]\r
+ *     };\r
+ */\r
+CKEDITOR.config.fontSize_style =\r
+       {\r
+               element         : 'span',\r
+               styles          : { 'font-size' : '#(size)' },\r
+               overrides       : [ { element : 'font', attributes : { 'size' : null } } ]\r
+       };\r