source: sandbox/3.0/phpgwapi/js/ckeditor/_source/plugins/format/plugin.js @ 2862

Revision 2862, 5.4 KB checked in by rodsouza, 14 years ago (diff)

Ticket #663 - Atualizando e centralizando o CKEditor (v. 3.2.1)

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