2 Copyright (c) 2003-2009, CKSource - Frederico Knabben. All rights reserved.
\r
3 For licensing, see LICENSE.html or http://ckeditor.com/license
\r
6 CKEDITOR.plugins.add( 'format',
\r
8 requires : [ 'richcombo', 'styles' ],
\r
10 init : function( editor )
\r
12 var config = editor.config,
\r
13 lang = editor.lang.format;
\r
15 // Gets the list of tags from the settings.
\r
16 var tags = config.format_tags.split( ';' );
\r
18 // Create style objects for all defined styles.
\r
20 for ( var i = 0 ; i < tags.length ; i++ )
\r
22 var tag = tags[ i ];
\r
23 styles[ tag ] = new CKEDITOR.style( config[ 'format_' + tag ] );
\r
26 editor.ui.addRichCombo( 'Format',
\r
29 title : lang.panelTitle,
\r
30 voiceLabel : lang.voiceLabel,
\r
31 className : 'cke_format',
\r
32 multiSelect : false,
\r
36 css : [ config.contentsCss, CKEDITOR.getUrl( editor.skinPath + 'editor.css' ) ],
\r
37 voiceLabel : lang.panelVoiceLabel
\r
42 this.startGroup( lang.panelTitle );
\r
44 for ( var tag in styles )
\r
46 var label = lang[ 'tag_' + tag ];
\r
48 // Add the tag entry to the panel list.
\r
49 this.add( tag, '<' + tag + '>' + label + '</' + tag + '>', label );
\r
53 onClick : function( value )
\r
56 editor.fire( 'saveSnapshot' );
\r
58 styles[ value ].apply( editor.document );
\r
60 editor.fire( 'saveSnapshot' );
\r
63 onRender : function()
\r
65 editor.on( 'selectionChange', function( ev )
\r
67 var currentTag = this.getValue();
\r
69 var elementPath = ev.data.path;
\r
71 for ( var tag in styles )
\r
73 if ( styles[ tag ].checkActive( elementPath ) )
\r
75 if ( tag != currentTag )
\r
76 this.setValue( tag, editor.lang.format[ 'tag_' + tag ] );
\r
81 // If no styles match, just empty it.
\r
82 this.setValue( '' );
\r
91 * A list of semi colon separated style names (by default tags) representing
\r
92 * the style definition for each entry to be displayed in the Format combo in
\r
93 * the toolbar. Each entry must have its relative definition configuration in a
\r
94 * setting named "format_(tagName)". For example, the "p" entry has its
\r
95 * definition taken from config.format_p.
\r
97 * @default 'p;h1;h2;h3;h4;h5;h6;pre;address;div'
\r
99 * config.format_tags = 'p;h2;h3;pre'
\r
101 CKEDITOR.config.format_tags = 'p;h1;h2;h3;h4;h5;h6;pre;address;div';
\r
104 * The style definition to be used to apply the "Normal" format.
\r
106 * @default { element : 'p' }
\r
108 * config.format_p = { element : 'p', attributes : { class : 'normalPara' } };
\r
110 CKEDITOR.config.format_p = { element : 'p' };
\r
113 * The style definition to be used to apply the "Normal (DIV)" format.
\r
115 * @default { element : 'div' }
\r
117 * config.format_div = { element : 'div', attributes : { class : 'normalDiv' } };
\r
119 CKEDITOR.config.format_div = { element : 'div' };
\r
122 * The style definition to be used to apply the "Formatted" format.
\r
124 * @default { element : 'pre' }
\r
126 * config.format_pre = { element : 'pre', attributes : { class : 'code' } };
\r
128 CKEDITOR.config.format_pre = { element : 'pre' };
\r
131 * The style definition to be used to apply the "Address" format.
\r
133 * @default { element : 'address' }
\r
135 * config.format_address = { element : 'address', attributes : { class : 'styledAddress' } };
\r
137 CKEDITOR.config.format_address = { element : 'address' };
\r
140 * The style definition to be used to apply the "Heading 1" format.
\r
142 * @default { element : 'h1' }
\r
144 * config.format_h1 = { element : 'h1', attributes : { class : 'contentTitle1' } };
\r
146 CKEDITOR.config.format_h1 = { element : 'h1' };
\r
149 * The style definition to be used to apply the "Heading 1" format.
\r
151 * @default { element : 'h2' }
\r
153 * config.format_h2 = { element : 'h2', attributes : { class : 'contentTitle2' } };
\r
155 CKEDITOR.config.format_h2 = { element : 'h2' };
\r
158 * The style definition to be used to apply the "Heading 1" format.
\r
160 * @default { element : 'h3' }
\r
162 * config.format_h3 = { element : 'h3', attributes : { class : 'contentTitle3' } };
\r
164 CKEDITOR.config.format_h3 = { element : 'h3' };
\r
167 * The style definition to be used to apply the "Heading 1" format.
\r
169 * @default { element : 'h4' }
\r
171 * config.format_h4 = { element : 'h4', attributes : { class : 'contentTitle4' } };
\r
173 CKEDITOR.config.format_h4 = { element : 'h4' };
\r
176 * The style definition to be used to apply the "Heading 1" format.
\r
178 * @default { element : 'h5' }
\r
180 * config.format_h5 = { element : 'h5', attributes : { class : 'contentTitle5' } };
\r
182 CKEDITOR.config.format_h5 = { element : 'h5' };
\r
185 * The style definition to be used to apply the "Heading 1" format.
\r
187 * @default { element : 'h6' }
\r
189 * config.format_h6 = { element : 'h6', attributes : { class : 'contentTitle6' } };
\r
191 CKEDITOR.config.format_h6 = { element : 'h6' };
\r