8e96529eae7c8b8a8c2dcd9ec10631ae8a46e0be
2 Copyright (c) 2003-2011, CKSource - Frederico Knabben. All rights reserved.
3 For licensing, see LICENSE.html or http://ckeditor.com/license
6 CKEDITOR
.plugins
.add( 'format',
8 requires
: [ 'richcombo', 'styles' ],
10 init : function( editor
)
12 var config
= editor
.config
,
13 lang
= editor
.lang
.format
;
15 // Gets the list of tags from the settings.
16 var tags
= config
.format_tags
.split( ';' );
18 // Create style objects for all defined styles.
20 for ( var i
= 0 ; i
< tags
.length
; i
++ )
23 styles
[ tag
] = new CKEDITOR
.style( config
[ 'format_' + tag
] );
24 styles
[ tag
]._
.enterMode
= editor
.config
.enterMode
;
27 editor
.ui
.addRichCombo( 'Format',
30 title
: lang
.panelTitle
,
31 className
: 'cke_format',
34 css
: editor
.skin
.editor
.css
.concat( config
.contentsCss
),
36 attributes
: { 'aria-label' : lang
.panelTitle
}
41 this.startGroup( lang
.panelTitle
);
43 for ( var tag
in styles
)
45 var label
= lang
[ 'tag_' + tag
];
47 // Add the tag entry to the panel list.
48 this.add( tag
, styles
[tag
].buildPreview( label
), label
);
52 onClick : function( value
)
55 editor
.fire( 'saveSnapshot' );
57 var style
= styles
[ value
],
58 elementPath
= new CKEDITOR
.dom
.elementPath( editor
.getSelection().getStartElement() );
60 style
[ style
.checkActive( elementPath
) ? 'remove' : 'apply' ]( editor
.document
);
62 // Save the undo snapshot after all changes are affected. (#4899)
63 setTimeout( function()
65 editor
.fire( 'saveSnapshot' );
71 editor
.on( 'selectionChange', function( ev
)
73 var currentTag
= this.getValue();
75 var elementPath
= ev
.data
.path
;
77 for ( var tag
in styles
)
79 if ( styles
[ tag
].checkActive( elementPath
) )
81 if ( tag
!= currentTag
)
82 this.setValue( tag
, editor
.lang
.format
[ 'tag_' + tag
] );
87 // If no styles match, just empty it.
97 * A list of semi colon separated style names (by default tags) representing
98 * the style definition for each entry to be displayed in the Format combo in
99 * the toolbar. Each entry must have its relative definition configuration in a
100 * setting named "format_(tagName)". For example, the "p" entry has its
101 * definition taken from config.format_p.
103 * @default 'p;h1;h2;h3;h4;h5;h6;pre;address;div'
105 * config.format_tags = 'p;h2;h3;pre'
107 CKEDITOR
.config
.format_tags
= 'p;h1;h2;h3;h4;h5;h6;pre;address;div';
110 * The style definition to be used to apply the "Normal" format.
112 * @default { element : 'p' }
114 * config.format_p = { element : 'p', attributes : { 'class' : 'normalPara' } };
116 CKEDITOR
.config
.format_p
= { element
: 'p' };
119 * The style definition to be used to apply the "Normal (DIV)" format.
121 * @default { element : 'div' }
123 * config.format_div = { element : 'div', attributes : { 'class' : 'normalDiv' } };
125 CKEDITOR
.config
.format_div
= { element
: 'div' };
128 * The style definition to be used to apply the "Formatted" format.
130 * @default { element : 'pre' }
132 * config.format_pre = { element : 'pre', attributes : { 'class' : 'code' } };
134 CKEDITOR
.config
.format_pre
= { element
: 'pre' };
137 * The style definition to be used to apply the "Address" format.
139 * @default { element : 'address' }
141 * config.format_address = { element : 'address', attributes : { 'class' : 'styledAddress' } };
143 CKEDITOR
.config
.format_address
= { element
: 'address' };
146 * The style definition to be used to apply the "Heading 1" format.
148 * @default { element : 'h1' }
150 * config.format_h1 = { element : 'h1', attributes : { 'class' : 'contentTitle1' } };
152 CKEDITOR
.config
.format_h1
= { element
: 'h1' };
155 * The style definition to be used to apply the "Heading 1" format.
157 * @default { element : 'h2' }
159 * config.format_h2 = { element : 'h2', attributes : { 'class' : 'contentTitle2' } };
161 CKEDITOR
.config
.format_h2
= { element
: 'h2' };
164 * The style definition to be used to apply the "Heading 1" format.
166 * @default { element : 'h3' }
168 * config.format_h3 = { element : 'h3', attributes : { 'class' : 'contentTitle3' } };
170 CKEDITOR
.config
.format_h3
= { element
: 'h3' };
173 * The style definition to be used to apply the "Heading 1" format.
175 * @default { element : 'h4' }
177 * config.format_h4 = { element : 'h4', attributes : { 'class' : 'contentTitle4' } };
179 CKEDITOR
.config
.format_h4
= { element
: 'h4' };
182 * The style definition to be used to apply the "Heading 1" format.
184 * @default { element : 'h5' }
186 * config.format_h5 = { element : 'h5', attributes : { 'class' : 'contentTitle5' } };
188 CKEDITOR
.config
.format_h5
= { element
: 'h5' };
191 * The style definition to be used to apply the "Heading 1" format.
193 * @default { element : 'h6' }
195 * config.format_h6 = { element : 'h6', attributes : { 'class' : 'contentTitle6' } };
197 CKEDITOR
.config
.format_h6
= { element
: 'h6' };