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

Revision 2862, 7.1 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
6(function()
7{
8        function addCombo( editor, comboName, styleType, lang, entries, defaultLabel, styleDefinition )
9        {
10                var config = editor.config;
11
12                // Gets the list of fonts from the settings.
13                var names = entries.split( ';' ),
14                        values = [];
15
16                // Create style objects for all fonts.
17                var styles = {};
18                for ( var i = 0 ; i < names.length ; i++ )
19                {
20                        var parts = names[ i ];
21
22                        if ( parts )
23                        {
24                                parts = parts.split( '/' );
25
26                                var vars = {},
27                                        name = names[ i ] = parts[ 0 ];
28
29                                vars[ styleType ] = values[ i ] = parts[ 1 ] || name;
30
31                                styles[ name ] = new CKEDITOR.style( styleDefinition, vars );
32                                styles[ name ]._.definition.name = name;
33                        }
34                        else
35                                names.splice( i--, 1 );
36                }
37
38                editor.ui.addRichCombo( comboName,
39                        {
40                                label : lang.label,
41                                title : lang.panelTitle,
42                                className : 'cke_' + ( styleType == 'size' ? 'fontSize' : 'font' ),
43                                panel :
44                                {
45                                        css : editor.skin.editor.css.concat( config.contentsCss ),
46                                        multiSelect : false,
47                                        attributes : { 'aria-label' : lang.panelTitle }
48                                },
49
50                                init : function()
51                                {
52                                        this.startGroup( lang.panelTitle );
53
54                                        for ( var i = 0 ; i < names.length ; i++ )
55                                        {
56                                                var name = names[ i ];
57
58                                                // Add the tag entry to the panel list.
59                                                this.add( name, styles[ name ].buildPreview(), name );
60                                        }
61                                },
62
63                                onClick : function( value )
64                                {
65                                        editor.focus();
66                                        editor.fire( 'saveSnapshot' );
67
68                                        var style = styles[ value ];
69
70                                        if ( this.getValue() == value )
71                                                style.remove( editor.document );
72                                        else
73                                                style.apply( editor.document );
74
75                                        editor.fire( 'saveSnapshot' );
76                                },
77
78                                onRender : function()
79                                {
80                                        editor.on( 'selectionChange', function( ev )
81                                                {
82                                                        var currentValue = this.getValue();
83
84                                                        var elementPath = ev.data.path,
85                                                                elements = elementPath.elements;
86
87                                                        // For each element into the elements path.
88                                                        for ( var i = 0, element ; i < elements.length ; i++ )
89                                                        {
90                                                                element = elements[i];
91
92                                                                // Check if the element is removable by any of
93                                                                // the styles.
94                                                                for ( var value in styles )
95                                                                        if ( ! ( value in Object.prototype ) )
96                                                                        {
97                                                                                if ( styles[ value ].checkElementRemovable( element, true ) )
98                                                                                {
99                                                                                        if ( value != currentValue )
100                                                                                                this.setValue( value );
101                                                                                        return;
102                                                                                }
103                                                                        }
104                                                        }
105
106                                                        // If no styles match, just empty it.
107                                                        this.setValue( '', defaultLabel );
108                                                },
109                                                this);
110                                }
111                        });
112        }
113
114        CKEDITOR.plugins.add( 'font',
115        {
116                requires : [ 'richcombo', 'styles' ],
117
118                init : function( editor )
119                {
120                        var config = editor.config;
121
122                        addCombo( editor, 'Font', 'family', editor.lang.font, config.font_names, config.font_defaultLabel, config.font_style );
123                        addCombo( editor, 'FontSize', 'size', editor.lang.fontSize, config.fontSize_sizes, config.fontSize_defaultLabel, config.fontSize_style );
124                }
125        });
126})();
127
128/**
129 * The list of fonts names to be displayed in the Font combo in the toolbar.
130 * Entries are separated by semi-colons (;), while it's possible to have more
131 * than one font for each entry, in the HTML way (separated by comma).
132 *
133 * A display name may be optionally defined by prefixing the entries with the
134 * name and the slash character. For example, "Arial/Arial, Helvetica, sans-serif"
135 * will be displayed as "Arial" in the list, but will be outputted as
136 * "Arial, Helvetica, sans-serif".
137 * @type String
138 * @example
139 * config.font_names =
140 *     'Arial/Arial, Helvetica, sans-serif;' +
141 *     'Times New Roman/Times New Roman, Times, serif;' +
142 *     'Verdana';
143 * @example
144 * config.font_names = 'Arial;Times New Roman;Verdana';
145 */
146CKEDITOR.config.font_names =
147        'Arial/Arial, Helvetica, sans-serif;' +
148        'Comic Sans MS/Comic Sans MS, cursive;' +
149        'Courier New/Courier New, Courier, monospace;' +
150        'Georgia/Georgia, serif;' +
151        'Lucida Sans Unicode/Lucida Sans Unicode, Lucida Grande, sans-serif;' +
152        'Tahoma/Tahoma, Geneva, sans-serif;' +
153        'Times New Roman/Times New Roman, Times, serif;' +
154        'Trebuchet MS/Trebuchet MS, Helvetica, sans-serif;' +
155        'Verdana/Verdana, Geneva, sans-serif';
156
157/**
158 * The text to be displayed in the Font combo is none of the available values
159 * matches the current cursor position or text selection.
160 * @type String
161 * @example
162 * // If the default site font is Arial, we may making it more explicit to the end user.
163 * config.font_defaultLabel = 'Arial';
164 */
165CKEDITOR.config.font_defaultLabel = '';
166
167/**
168 * The style definition to be used to apply the font in the text.
169 * @type Object
170 * @example
171 * // This is actually the default value for it.
172 * config.font_style =
173 *     {
174 *         element              : 'span',
175 *         styles               : { 'font-family' : '#(family)' },
176 *         overrides    : [ { element : 'font', attributes : { 'face' : null } } ]
177 *     };
178 */
179CKEDITOR.config.font_style =
180        {
181                element         : 'span',
182                styles          : { 'font-family' : '#(family)' },
183                overrides       : [ { element : 'font', attributes : { 'face' : null } } ]
184        };
185
186/**
187 * The list of fonts size to be displayed in the Font Size combo in the
188 * toolbar. Entries are separated by semi-colons (;).
189 *
190 * Any kind of "CSS like" size can be used, like "12px", "2.3em", "130%",
191 * "larger" or "x-small".
192 *
193 * A display name may be optionally defined by prefixing the entries with the
194 * name and the slash character. For example, "Bigger Font/14px" will be
195 * displayed as "Bigger Font" in the list, but will be outputted as "14px".
196 * @type String
197 * @default '8/8px;9/9px;10/10px;11/11px;12/12px;14/14px;16/16px;18/18px;20/20px;22/22px;24/24px;26/26px;28/28px;36/36px;48/48px;72/72px'
198 * @example
199 * config.fontSize_sizes = '16/16px;24/24px;48/48px;';
200 * @example
201 * config.fontSize_sizes = '12px;2.3em;130%;larger;x-small';
202 * @example
203 * config.fontSize_sizes = '12 Pixels/12px;Big/2.3em;30 Percent More/130%;Bigger/larger;Very Small/x-small';
204 */
205CKEDITOR.config.fontSize_sizes =
206        '8/8px;9/9px;10/10px;11/11px;12/12px;14/14px;16/16px;18/18px;20/20px;22/22px;24/24px;26/26px;28/28px;36/36px;48/48px;72/72px';
207
208/**
209 * The text to be displayed in the Font Size combo is none of the available
210 * values matches the current cursor position or text selection.
211 * @type String
212 * @example
213 * // If the default site font size is 12px, we may making it more explicit to the end user.
214 * config.fontSize_defaultLabel = '12px';
215 */
216CKEDITOR.config.fontSize_defaultLabel = '';
217
218/**
219 * The style definition to be used to apply the font size in the text.
220 * @type Object
221 * @example
222 * // This is actually the default value for it.
223 * config.fontSize_style =
224 *     {
225 *         element              : 'span',
226 *         styles               : { 'font-size' : '#(size)' },
227 *         overrides    : [ { element : 'font', attributes : { 'size' : null } } ]
228 *     };
229 */
230CKEDITOR.config.fontSize_style =
231        {
232                element         : 'span',
233                styles          : { 'font-size' : '#(size)' },
234                overrides       : [ { element : 'font', attributes : { 'size' : null } } ]
235        };
Note: See TracBrowser for help on using the repository browser.