2 Copyright (c) 2003-2010, 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
24 styles[ tag ]._.enterMode = editor.config.enterMode;
\r
27 editor.ui.addRichCombo( 'Format',
\r
30 title : lang.panelTitle,
\r
31 className : 'cke_format',
\r
34 css : editor.skin.editor.css.concat( config.contentsCss ),
\r
35 multiSelect : false,
\r
36 attributes : { 'aria-label' : lang.panelTitle }
\r
41 this.startGroup( lang.panelTitle );
\r
43 for ( var tag in styles )
\r
45 var label = lang[ 'tag_' + tag ];
\r
47 // Add the tag entry to the panel list.
\r
48 this.add( tag, '<' + tag + '>' + label + '</' + tag + '>', label );
\r
52 onClick : function( value )
\r
55 editor.fire( 'saveSnapshot' );
\r
57 styles[ value ].apply( editor.document );
\r
59 // Save the undo snapshot after all changes are affected. (#4899)
\r
60 setTimeout( function()
\r
62 editor.fire( 'saveSnapshot' );
\r
66 onRender : function()
\r
68 editor.on( 'selectionChange', function( ev )
\r
70 var currentTag = this.getValue();
\r
72 var elementPath = ev.data.path;
\r
74 for ( var tag in styles )
\r
76 if ( styles[ tag ].checkActive( elementPath ) )
\r
78 if ( tag != currentTag )
\r
79 this.setValue( tag, editor.lang.format[ 'tag_' + tag ] );
\r
84 // If no styles match, just empty it.
\r
85 this.setValue( '' );
\r
94 * A list of semi colon separated style names (by default tags) representing
\r
95 * the style definition for each entry to be displayed in the Format combo in
\r
96 * the toolbar. Each entry must have its relative definition configuration in a
\r
97 * setting named "format_(tagName)". For example, the "p" entry has its
\r
98 * definition taken from config.format_p.
\r
100 * @default 'p;h1;h2;h3;h4;h5;h6;pre;address;div'
\r
102 * config.format_tags = 'p;h2;h3;pre'
\r
104 CKEDITOR.config.format_tags = 'p;h1;h2;h3;h4;h5;h6;pre;address;div';
\r
107 * The style definition to be used to apply the "Normal" format.
\r
109 * @default { element : 'p' }
\r
111 * config.format_p = { element : 'p', attributes : { class : 'normalPara' } };
\r
113 CKEDITOR.config.format_p = { element : 'p' };
\r
116 * The style definition to be used to apply the "Normal (DIV)" format.
\r
118 * @default { element : 'div' }
\r
120 * config.format_div = { element : 'div', attributes : { class : 'normalDiv' } };
\r
122 CKEDITOR.config.format_div = { element : 'div' };
\r
125 * The style definition to be used to apply the "Formatted" format.
\r
127 * @default { element : 'pre' }
\r
129 * config.format_pre = { element : 'pre', attributes : { class : 'code' } };
\r
131 CKEDITOR.config.format_pre = { element : 'pre' };
\r
134 * The style definition to be used to apply the "Address" format.
\r
136 * @default { element : 'address' }
\r
138 * config.format_address = { element : 'address', attributes : { class : 'styledAddress' } };
\r
140 CKEDITOR.config.format_address = { element : 'address' };
\r
143 * The style definition to be used to apply the "Heading 1" format.
\r
145 * @default { element : 'h1' }
\r
147 * config.format_h1 = { element : 'h1', attributes : { class : 'contentTitle1' } };
\r
149 CKEDITOR.config.format_h1 = { element : 'h1' };
\r
152 * The style definition to be used to apply the "Heading 1" format.
\r
154 * @default { element : 'h2' }
\r
156 * config.format_h2 = { element : 'h2', attributes : { class : 'contentTitle2' } };
\r
158 CKEDITOR.config.format_h2 = { element : 'h2' };
\r
161 * The style definition to be used to apply the "Heading 1" format.
\r
163 * @default { element : 'h3' }
\r
165 * config.format_h3 = { element : 'h3', attributes : { class : 'contentTitle3' } };
\r
167 CKEDITOR.config.format_h3 = { element : 'h3' };
\r
170 * The style definition to be used to apply the "Heading 1" format.
\r
172 * @default { element : 'h4' }
\r
174 * config.format_h4 = { element : 'h4', attributes : { class : 'contentTitle4' } };
\r
176 CKEDITOR.config.format_h4 = { element : 'h4' };
\r
179 * The style definition to be used to apply the "Heading 1" format.
\r
181 * @default { element : 'h5' }
\r
183 * config.format_h5 = { element : 'h5', attributes : { class : 'contentTitle5' } };
\r
185 CKEDITOR.config.format_h5 = { element : 'h5' };
\r
188 * The style definition to be used to apply the "Heading 1" format.
\r
190 * @default { element : 'h6' }
\r
192 * config.format_h6 = { element : 'h6', attributes : { class : 'contentTitle6' } };
\r
194 CKEDITOR.config.format_h6 = { element : 'h6' };
\r