1 | /*
|
---|
2 | Copyright (c) 2003-2009, CKSource - Frederico Knabben. All rights reserved.
|
---|
3 | For licensing, see LICENSE.html or http://ckeditor.com/license
|
---|
4 | */
|
---|
5 |
|
---|
6 | CKEDITOR.plugins.add( 'format',
|
---|
7 | {
|
---|
8 | requires : [ 'richcombo', 'styles' ],
|
---|
9 |
|
---|
10 | init : function( editor )
|
---|
11 | {
|
---|
12 | var config = editor.config,
|
---|
13 | lang = editor.lang.format;
|
---|
14 |
|
---|
15 | // Gets the list of tags from the settings.
|
---|
16 | var tags = config.format_tags.split( ';' );
|
---|
17 |
|
---|
18 | // Create style objects for all defined styles.
|
---|
19 | var styles = {};
|
---|
20 | for ( var i = 0 ; i < tags.length ; i++ )
|
---|
21 | {
|
---|
22 | var tag = tags[ i ];
|
---|
23 | styles[ tag ] = new CKEDITOR.style( config[ 'format_' + tag ] );
|
---|
24 | }
|
---|
25 |
|
---|
26 | editor.ui.addRichCombo( 'Format',
|
---|
27 | {
|
---|
28 | label : lang.label,
|
---|
29 | title : lang.panelTitle,
|
---|
30 | voiceLabel : lang.voiceLabel,
|
---|
31 | className : 'cke_format',
|
---|
32 | multiSelect : false,
|
---|
33 |
|
---|
34 | panel :
|
---|
35 | {
|
---|
36 | css : [ CKEDITOR.getUrl( editor.skinPath + 'editor.css' ) ].concat( config.contentsCss ),
|
---|
37 | voiceLabel : lang.panelVoiceLabel
|
---|
38 | },
|
---|
39 |
|
---|
40 | init : function()
|
---|
41 | {
|
---|
42 | this.startGroup( lang.panelTitle );
|
---|
43 |
|
---|
44 | for ( var tag in styles )
|
---|
45 | {
|
---|
46 | var label = lang[ 'tag_' + tag ];
|
---|
47 |
|
---|
48 | // Add the tag entry to the panel list.
|
---|
49 | this.add( tag, '<' + tag + '>' + label + '</' + tag + '>', label );
|
---|
50 | }
|
---|
51 | },
|
---|
52 |
|
---|
53 | onClick : function( value )
|
---|
54 | {
|
---|
55 | editor.focus();
|
---|
56 | editor.fire( 'saveSnapshot' );
|
---|
57 |
|
---|
58 | styles[ value ].apply( editor.document );
|
---|
59 |
|
---|
60 | editor.fire( 'saveSnapshot' );
|
---|
61 | },
|
---|
62 |
|
---|
63 | onRender : function()
|
---|
64 | {
|
---|
65 | editor.on( 'selectionChange', function( ev )
|
---|
66 | {
|
---|
67 | var currentTag = this.getValue();
|
---|
68 |
|
---|
69 | var elementPath = ev.data.path;
|
---|
70 |
|
---|
71 | for ( var tag in styles )
|
---|
72 | {
|
---|
73 | if ( styles[ tag ].checkActive( elementPath ) )
|
---|
74 | {
|
---|
75 | if ( tag != currentTag )
|
---|
76 | this.setValue( tag, editor.lang.format[ 'tag_' + tag ] );
|
---|
77 | return;
|
---|
78 | }
|
---|
79 | }
|
---|
80 |
|
---|
81 | // If no styles match, just empty it.
|
---|
82 | this.setValue( '' );
|
---|
83 | },
|
---|
84 | this);
|
---|
85 | }
|
---|
86 | });
|
---|
87 | }
|
---|
88 | });
|
---|
89 |
|
---|
90 | /**
|
---|
91 | * A list of semi colon separated style names (by default tags) representing
|
---|
92 | * the style definition for each entry to be displayed in the Format combo in
|
---|
93 | * the toolbar. Each entry must have its relative definition configuration in a
|
---|
94 | * setting named "format_(tagName)". For example, the "p" entry has its
|
---|
95 | * definition taken from config.format_p.
|
---|
96 | * @type String
|
---|
97 | * @default 'p;h1;h2;h3;h4;h5;h6;pre;address;div'
|
---|
98 | * @example
|
---|
99 | * config.format_tags = 'p;h2;h3;pre'
|
---|
100 | */
|
---|
101 | CKEDITOR.config.format_tags = 'p;h1;h2;h3;h4;h5;h6;pre;address;div';
|
---|
102 |
|
---|
103 | /**
|
---|
104 | * The style definition to be used to apply the "Normal" format.
|
---|
105 | * @type Object
|
---|
106 | * @default { element : 'p' }
|
---|
107 | * @example
|
---|
108 | * config.format_p = { element : 'p', attributes : { class : 'normalPara' } };
|
---|
109 | */
|
---|
110 | CKEDITOR.config.format_p = { element : 'p' };
|
---|
111 |
|
---|
112 | /**
|
---|
113 | * The style definition to be used to apply the "Normal (DIV)" format.
|
---|
114 | * @type Object
|
---|
115 | * @default { element : 'div' }
|
---|
116 | * @example
|
---|
117 | * config.format_div = { element : 'div', attributes : { class : 'normalDiv' } };
|
---|
118 | */
|
---|
119 | CKEDITOR.config.format_div = { element : 'div' };
|
---|
120 |
|
---|
121 | /**
|
---|
122 | * The style definition to be used to apply the "Formatted" format.
|
---|
123 | * @type Object
|
---|
124 | * @default { element : 'pre' }
|
---|
125 | * @example
|
---|
126 | * config.format_pre = { element : 'pre', attributes : { class : 'code' } };
|
---|
127 | */
|
---|
128 | CKEDITOR.config.format_pre = { element : 'pre' };
|
---|
129 |
|
---|
130 | /**
|
---|
131 | * The style definition to be used to apply the "Address" format.
|
---|
132 | * @type Object
|
---|
133 | * @default { element : 'address' }
|
---|
134 | * @example
|
---|
135 | * config.format_address = { element : 'address', attributes : { class : 'styledAddress' } };
|
---|
136 | */
|
---|
137 | CKEDITOR.config.format_address = { element : 'address' };
|
---|
138 |
|
---|
139 | /**
|
---|
140 | * The style definition to be used to apply the "Heading 1" format.
|
---|
141 | * @type Object
|
---|
142 | * @default { element : 'h1' }
|
---|
143 | * @example
|
---|
144 | * config.format_h1 = { element : 'h1', attributes : { class : 'contentTitle1' } };
|
---|
145 | */
|
---|
146 | CKEDITOR.config.format_h1 = { element : 'h1' };
|
---|
147 |
|
---|
148 | /**
|
---|
149 | * The style definition to be used to apply the "Heading 1" format.
|
---|
150 | * @type Object
|
---|
151 | * @default { element : 'h2' }
|
---|
152 | * @example
|
---|
153 | * config.format_h2 = { element : 'h2', attributes : { class : 'contentTitle2' } };
|
---|
154 | */
|
---|
155 | CKEDITOR.config.format_h2 = { element : 'h2' };
|
---|
156 |
|
---|
157 | /**
|
---|
158 | * The style definition to be used to apply the "Heading 1" format.
|
---|
159 | * @type Object
|
---|
160 | * @default { element : 'h3' }
|
---|
161 | * @example
|
---|
162 | * config.format_h3 = { element : 'h3', attributes : { class : 'contentTitle3' } };
|
---|
163 | */
|
---|
164 | CKEDITOR.config.format_h3 = { element : 'h3' };
|
---|
165 |
|
---|
166 | /**
|
---|
167 | * The style definition to be used to apply the "Heading 1" format.
|
---|
168 | * @type Object
|
---|
169 | * @default { element : 'h4' }
|
---|
170 | * @example
|
---|
171 | * config.format_h4 = { element : 'h4', attributes : { class : 'contentTitle4' } };
|
---|
172 | */
|
---|
173 | CKEDITOR.config.format_h4 = { element : 'h4' };
|
---|
174 |
|
---|
175 | /**
|
---|
176 | * The style definition to be used to apply the "Heading 1" format.
|
---|
177 | * @type Object
|
---|
178 | * @default { element : 'h5' }
|
---|
179 | * @example
|
---|
180 | * config.format_h5 = { element : 'h5', attributes : { class : 'contentTitle5' } };
|
---|
181 | */
|
---|
182 | CKEDITOR.config.format_h5 = { element : 'h5' };
|
---|
183 |
|
---|
184 | /**
|
---|
185 | * The style definition to be used to apply the "Heading 1" format.
|
---|
186 | * @type Object
|
---|
187 | * @default { element : 'h6' }
|
---|
188 | * @example
|
---|
189 | * config.format_h6 = { element : 'h6', attributes : { class : 'contentTitle6' } };
|
---|
190 | */
|
---|
191 | CKEDITOR.config.format_h6 = { element : 'h6' };
|
---|