4 * @author Jonnas Fonini <contato@fonini.net>
10 var pluginName
= "format_buttons";
12 CKEDITOR
.plugins
.add(pluginName
, {
15 icons
: 'h1,h2,h3,h4,h5,h6',
18 init: function( editor
) {
21 // All buttons use the same code to register. So, to avoid
22 // duplications, let's use this tool function.
23 var addButtonCommand = function( buttonName
, buttonLabel
, commandName
, styleDefiniton
) {
24 // Disable the command if no definition is configured.
25 if ( !styleDefiniton
)
28 var style
= new CKEDITOR
.style( styleDefiniton
),
29 forms
= contentForms
[ commandName
];
31 // Put the style as the most important form.
32 forms
.unshift( style
);
34 // Listen to contextual style activation.
35 editor
.attachStyleStateChange( style
, function( state
) {
36 !editor
.readOnly
&& editor
.getCommand( commandName
).setState( state
);
39 // Create the command that can be used to apply the style.
40 editor
.addCommand( commandName
, new CKEDITOR
.styleCommand( style
, {
44 // Register the button, if the button plugin is loaded.
45 if ( editor
.ui
.addButton
) {
46 editor
.ui
.addButton( buttonName
, {
49 toolbar
: 'basicstyles,' + ( order
+= 10 )
62 config
= editor
.config
,
63 lang
= editor
.lang
.format_buttons
;
65 addButtonCommand( 'h1', lang
.h1
, 'h1', config
.h1
);
66 addButtonCommand( 'h2', lang
.h2
, 'h2', config
.h2
);
67 addButtonCommand( 'h3', lang
.h3
, 'h3', config
.h3
);
68 addButtonCommand( 'h4', lang
.h4
, 'h4', config
.h4
);
69 addButtonCommand( 'h5', lang
.h5
, 'h5', config
.h5
);
70 addButtonCommand( 'h6', lang
.h6
, 'h6', config
.h6
);
81 CKEDITOR
.config
.h1
= { element
: 'h1' };
82 CKEDITOR
.config
.h2
= { element
: 'h2' };
83 CKEDITOR
.config
.h3
= { element
: 'h3' };
84 CKEDITOR
.config
.h4
= { element
: 'h4' };
85 CKEDITOR
.config
.h5
= { element
: 'h5' };
86 CKEDITOR
.config
.h6
= { element
: 'h6' };