source: sandbox/2.3-MailArchiver/filemanager/tp/ckeditor/_source/plugins/toolbar/plugin.js @ 6779

Revision 6779, 11.7 KB checked in by rafaelraymundo, 12 years ago (diff)

Ticket #2946 - Liberado Expresso(branch 2.3) integrado ao MailArchiver?.

Line 
1/*
2Copyright (c) 2003-2009, CKSource - Frederico Knabben. All rights reserved.
3For licensing, see LICENSE.html or http://ckeditor.com/license
4*/
5
6/**
7 * @fileOverview The "toolbar" plugin. Renders the default toolbar interface in
8 * the editor.
9 */
10
11(function()
12{
13        var toolbox = function()
14        {
15                this.toolbars = [];
16                this.focusCommandExecuted = false;
17        };
18
19        toolbox.prototype.focus = function()
20        {
21                for ( var t = 0, toolbar ; toolbar = this.toolbars[ t++ ] ; )
22                {
23                        for ( var i = 0, item ; item = toolbar.items[ i++ ] ; )
24                        {
25                                if ( item.focus )
26                                {
27                                        item.focus();
28                                        return;
29                                }
30                        }
31                }
32        };
33
34        var commands =
35        {
36                toolbarFocus :
37                {
38                        modes : { wysiwyg : 1, source : 1 },
39
40                        exec : function( editor )
41                        {
42                                if ( editor.toolbox )
43                                {
44                                        editor.toolbox.focusCommandExecuted = true;
45
46                                        // Make the first button focus accessible. (#3417)
47                                        if ( CKEDITOR.env.ie )
48                                                setTimeout( function(){ editor.toolbox.focus(); }, 100 );
49                                        else
50                                                editor.toolbox.focus();
51                                }
52                        }
53                }
54        };
55
56        CKEDITOR.plugins.add( 'toolbar',
57        {
58                init : function( editor )
59                {
60                        var itemKeystroke = function( item, keystroke )
61                        {
62                                switch ( keystroke )
63                                {
64                                        case 39 :                                       // RIGHT-ARROW
65                                        case 9 :                                        // TAB
66                                                // Look for the next item in the toolbar.
67                                                while ( ( item = item.next || ( item.toolbar.next && item.toolbar.next.items[ 0 ] ) ) && !item.focus )
68                                                { /*jsl:pass*/ }
69
70                                                // If available, just focus it, otherwise focus the
71                                                // first one.
72                                                if ( item )
73                                                        item.focus();
74                                                else
75                                                        editor.toolbox.focus();
76
77                                                return false;
78
79                                        case 37 :                                       // LEFT-ARROW
80                                        case CKEDITOR.SHIFT + 9 :       // SHIFT + TAB
81                                                // Look for the previous item in the toolbar.
82                                                while ( ( item = item.previous || ( item.toolbar.previous && item.toolbar.previous.items[ item.toolbar.previous.items.length - 1 ] ) ) && !item.focus )
83                                                { /*jsl:pass*/ }
84
85                                                // If available, just focus it, otherwise focus the
86                                                // last one.
87                                                if ( item )
88                                                        item.focus();
89                                                else
90                                                {
91                                                        var lastToolbarItems = editor.toolbox.toolbars[ editor.toolbox.toolbars.length - 1 ].items;
92                                                        lastToolbarItems[ lastToolbarItems.length - 1 ].focus();
93                                                }
94
95                                                return false;
96
97                                        case 27 :                                       // ESC
98                                                editor.focus();
99                                                return false;
100
101                                        case 13 :                                       // ENTER
102                                        case 32 :                                       // SPACE
103                                                item.execute();
104                                                return false;
105                                }
106                                return true;
107                        };
108
109                        editor.on( 'themeSpace', function( event )
110                                {
111                                        if ( event.data.space == editor.config.toolbarLocation )
112                                        {
113                                                editor.toolbox = new toolbox();
114
115                                                var output = [ '<div class="cke_toolbox"' ],
116                                                        expanded =  editor.config.toolbarStartupExpanded,
117                                                        groupStarted;
118
119                                                output.push( expanded ? '>' : ' style="display:none">' );
120
121                                                var toolbars = editor.toolbox.toolbars,
122                                                        toolbar =
123                                                                        ( editor.config.toolbar instanceof Array ) ?
124                                                                                editor.config.toolbar
125                                                                        :
126                                                                                editor.config[ 'toolbar_' + editor.config.toolbar ];
127
128                                                for ( var r = 0 ; r < toolbar.length ; r++ )
129                                                {
130                                                        var row = toolbar[ r ];
131
132                                                        // It's better to check if the row object is really
133                                                        // available because it's a common mistake to leave
134                                                        // an extra comma in the toolbar definition
135                                                        // settings, which leads on the editor not loading
136                                                        // at all in IE. (#3983)
137                                                        if ( !row )
138                                                                continue;
139
140                                                        var toolbarId = 'cke_' + CKEDITOR.tools.getNextNumber(),
141                                                                toolbarObj = { id : toolbarId, items : [] };
142
143                                                        if ( groupStarted )
144                                                        {
145                                                                output.push( '</div>' );
146                                                                groupStarted = 0;
147                                                        }
148
149                                                        if ( row === '/' )
150                                                        {
151                                                                output.push( '<div class="cke_break"></div>' );
152                                                                continue;
153                                                        }
154
155                                                        output.push( '<span id="', toolbarId, '" class="cke_toolbar"><span class="cke_toolbar_start"></span>' );
156
157                                                        // Add the toolbar to the "editor.toolbox.toolbars"
158                                                        // array.
159                                                        var index = toolbars.push( toolbarObj ) - 1;
160
161                                                        // Create the next/previous reference.
162                                                        if ( index > 0 )
163                                                        {
164                                                                toolbarObj.previous = toolbars[ index - 1 ];
165                                                                toolbarObj.previous.next = toolbarObj;
166                                                        }
167
168                                                        // Create all items defined for this toolbar.
169                                                        for ( var i = 0 ; i < row.length ; i++ )
170                                                        {
171                                                                var item,
172                                                                        itemName = row[ i ];
173
174                                                                if ( itemName == '-' )
175                                                                        item = CKEDITOR.ui.separator;
176                                                                else
177                                                                        item = editor.ui.create( itemName );
178
179                                                                if ( item )
180                                                                {
181                                                                        if ( item.canGroup )
182                                                                        {
183                                                                                if ( !groupStarted )
184                                                                                {
185                                                                                        output.push( '<span class="cke_toolgroup">' );
186                                                                                        groupStarted = 1;
187                                                                                }
188                                                                        }
189                                                                        else if ( groupStarted )
190                                                                        {
191                                                                                output.push( '</span>' );
192                                                                                groupStarted = 0;
193                                                                        }
194
195                                                                        var itemObj = item.render( editor, output );
196                                                                        index = toolbarObj.items.push( itemObj ) - 1;
197
198                                                                        if ( index > 0 )
199                                                                        {
200                                                                                itemObj.previous = toolbarObj.items[ index - 1 ];
201                                                                                itemObj.previous.next = itemObj;
202                                                                        }
203
204                                                                        itemObj.toolbar = toolbarObj;
205                                                                        itemObj.onkey = itemKeystroke;
206
207                                                                        /*
208                                                                         * Fix for #3052:
209                                                                         * Prevent JAWS from focusing the toolbar after document load.
210                                                                         */
211                                                                        itemObj.onfocus = function()
212                                                                        {
213                                                                                if ( !editor.toolbox.focusCommandExecuted )
214                                                                                        editor.focus();
215                                                                        };
216                                                                }
217                                                        }
218
219                                                        if ( groupStarted )
220                                                        {
221                                                                output.push( '</span>' );
222                                                                groupStarted = 0;
223                                                        }
224
225                                                        output.push( '<span class="cke_toolbar_end"></span></span>' );
226                                                }
227
228                                                output.push( '</div>' );
229
230                                                if ( editor.config.toolbarCanCollapse )
231                                                {
232                                                        var collapserFn = CKEDITOR.tools.addFunction(
233                                                                function()
234                                                                {
235                                                                        editor.execCommand( 'toolbarCollapse' );
236                                                                } );
237
238                                                        var collapserId = 'cke_' + CKEDITOR.tools.getNextNumber();
239
240                                                        editor.addCommand( 'toolbarCollapse',
241                                                                {
242                                                                        exec : function( editor )
243                                                                        {
244                                                                                var collapser = CKEDITOR.document.getById( collapserId );
245                                                                                var toolbox = collapser.getPrevious();
246                                                                                var contents = editor.getThemeSpace( 'contents' );
247                                                                                var toolboxContainer = toolbox.getParent();
248                                                                                var contentHeight = parseInt( contents.$.style.height, 10 );
249                                                                                var previousHeight = toolboxContainer.$.offsetHeight;
250
251                                                                                if ( toolbox.isVisible() )
252                                                                                {
253                                                                                        toolbox.hide();
254                                                                                        collapser.addClass( 'cke_toolbox_collapser_min' );
255                                                                                }
256                                                                                else
257                                                                                {
258                                                                                        toolbox.show();
259                                                                                        collapser.removeClass( 'cke_toolbox_collapser_min' );
260                                                                                }
261
262                                                                                var dy = toolboxContainer.$.offsetHeight - previousHeight;
263                                                                                contents.setStyle( 'height', ( contentHeight - dy ) + 'px' );
264                                                                        },
265
266                                                                        modes : { wysiwyg : 1, source : 1 }
267                                                                } );
268
269                                                        output.push( '<a id="' + collapserId + '" class="cke_toolbox_collapser' );
270
271                                                        if ( !expanded )
272                                                                output.push( ' cke_toolbox_collapser_min' );
273
274                                                        output.push( '" onclick="CKEDITOR.tools.callFunction(' + collapserFn + ')"></a>' );
275                                                }
276
277                                                event.data.html += output.join( '' );
278                                        }
279                                });
280
281                        editor.addCommand( 'toolbarFocus', commands.toolbarFocus );
282                }
283        });
284})();
285
286/**
287 * The UI element that renders a toolbar separator.
288 * @type Object
289 * @example
290 */
291CKEDITOR.ui.separator =
292{
293        render : function( editor, output )
294        {
295                output.push( '<span class="cke_separator"></span>' );
296                return {};
297        }
298};
299
300/**
301 * The "theme space" to which rendering the toolbar. For the default theme,
302 * the recommended options are "top" and "bottom".
303 * @type String
304 * @default 'top'
305 * @see CKEDITOR.config.theme
306 * @example
307 * config.toolbarLocation = 'bottom';
308 */
309CKEDITOR.config.toolbarLocation = 'top';
310
311/**
312 * The toolbar definition. It is an array of toolbars (strips),
313 * each one being also an array, containing a list of UI items.
314 * Note that this setting is composed by "toolbar_" added by the toolbar name,
315 * which in this case is called "Basic". This second part of the setting name
316 * can be anything. You must use this name in the
317 * {@link CKEDITOR.config.toolbar} setting, so you instruct the editor which
318 * toolbar_(name) setting to you.
319 * @type Array
320 * @example
321 * // Defines a toolbar with only one strip containing the "Source" button, a
322 * // separator and the "Bold" and "Italic" buttons.
323 * <b>config.toolbar_Basic =
324 * [
325 *     [ 'Source', '-', 'Bold', 'Italic' ]
326 * ]</b>;
327 * config.toolbar = 'Basic';
328 */
329CKEDITOR.config.toolbar_Basic =
330[
331        ['Bold', 'Italic', '-', 'NumberedList', 'BulletedList', '-', 'Link', 'Unlink','-','About']
332];
333
334/**
335 * This is the default toolbar definition used by the editor. It contains all
336 * editor features.
337 * @type Array
338 * @default (see example)
339 * @example
340 * // This is actually the default value.
341 * config.toolbar_Full =
342 * [
343 *     ['Source','-','Save','NewPage','Preview','-','Templates'],
344 *     ['Cut','Copy','Paste','PasteText','PasteFromWord','-','Print', 'SpellChecker', 'Scayt'],
345 *     ['Undo','Redo','-','Find','Replace','-','SelectAll','RemoveFormat'],
346 *     ['Form', 'Checkbox', 'Radio', 'TextField', 'Textarea', 'Select', 'Button', 'ImageButton', 'HiddenField'],
347 *     '/',
348 *     ['Bold','Italic','Underline','Strike','-','Subscript','Superscript'],
349 *     ['NumberedList','BulletedList','-','Outdent','Indent','Blockquote'],
350 *     ['JustifyLeft','JustifyCenter','JustifyRight','JustifyBlock'],
351 *     ['Link','Unlink','Anchor'],
352 *     ['Image','Flash','Table','HorizontalRule','Smiley','SpecialChar','PageBreak'],
353 *     '/',
354 *     ['Styles','Format','Font','FontSize'],
355 *     ['TextColor','BGColor'],
356 *     ['Maximize', 'ShowBlocks','-','About']
357 * ];
358 */
359CKEDITOR.config.toolbar_Full =
360[
361        ['Source','-','Save','NewPage','Preview','-','Templates'],
362        ['Cut','Copy','Paste','PasteText','PasteFromWord','-','Print', 'SpellChecker', 'Scayt'],
363        ['Undo','Redo','-','Find','Replace','-','SelectAll','RemoveFormat'],
364        ['Form', 'Checkbox', 'Radio', 'TextField', 'Textarea', 'Select', 'Button', 'ImageButton', 'HiddenField'],
365        '/',
366        ['Bold','Italic','Underline','Strike','-','Subscript','Superscript'],
367        ['NumberedList','BulletedList','-','Outdent','Indent','Blockquote'],
368        ['JustifyLeft','JustifyCenter','JustifyRight','JustifyBlock'],
369        ['Link','Unlink','Anchor'],
370        ['Image','Flash','Table','HorizontalRule','Smiley','SpecialChar','PageBreak'],
371        '/',
372        ['Styles','Format','Font','FontSize'],
373        ['TextColor','BGColor'],
374        ['Maximize', 'ShowBlocks','-','About']
375];
376
377/**
378 * The toolbox (alias toolbar) definition. It is a toolbar name or an array of
379 * toolbars (strips), each one being also an array, containing a list of UI items.
380 * @type Array|String
381 * @default 'Full'
382 * @example
383 * // Defines a toolbar with only one strip containing the "Source" button, a
384 * // separator and the "Bold" and "Italic" buttons.
385 * config.toolbar =
386 * [
387 *     [ 'Source', '-', 'Bold', 'Italic' ]
388 * ];
389 * @example
390 * // Load toolbar_Name where Name = Basic.
391 * config.toolbar = 'Basic';
392 */
393CKEDITOR.config.toolbar = 'Full';
394
395/**
396 * Whether the toolbar can be collapsed by the user. If disabled, the collapser
397 * button will not be displayed.
398 * @type Boolean
399 * @default true
400 * @example
401 * config.toolbarCanCollapse = false;
402 */
403CKEDITOR.config.toolbarCanCollapse = true;
404
405/**
406 * Whether the toolbar must start expanded when the editor is loaded.
407 * @type Boolean
408 * @default true
409 * @example
410 * config.toolbarStartupExpanded = false;
411 */
412CKEDITOR.config.toolbarStartupExpanded = true;
Note: See TracBrowser for help on using the repository browser.