Ticket #7280: 7280_2.patch

File 7280_2.patch, 13.8 KB (added by Alfonso Martínez de Lizarrondo, 13 years ago)

good patch

  • _source/plugins/panelbutton/plugin.js

     
    4646
    4747                $ : function( definition )
    4848                {
     49                        // Store/Restore a copy of the panel definition to allow switch toolbars
     50                        if ( definition.panel )
     51                                definition.storedPanel = definition.panel;
     52                        else
     53                                definition.panel = definition.storedPanel ;
     54
    4955                        // We don't want the panel definition in this object.
    5056                        var panelDefinition = definition.panel;
    5157                        delete definition.panel;
  • _source/plugins/toolbar/plugin.js

     
    153153                        };
    154154
    155155                        editor.on( 'themeSpace', function( event )
     156                        {
     157                                if ( event.data.space == editor.config.toolbarLocation )
    156158                                {
    157                                         if ( event.data.space == editor.config.toolbarLocation )
    158                                         {
    159                                                 editor.toolbox = new toolbox();
     159                                        event.data.html += generateToolbarHtml( editor );
     160                                }
     161                        });
    160162
    161                                                 var labelId = CKEDITOR.tools.getNextId();
     163                        var generateToolbarHtml = function ( editor )
     164                        {
     165                                editor.toolbox = new toolbox();
    162166
    163                                                 var output = [ '<div class="cke_toolbox" role="toolbar" aria-labelledby="', labelId, '" onmousedown="return false;"' ],
    164                                                         expanded =  editor.config.toolbarStartupExpanded !== false,
    165                                                         groupStarted;
     167                                var labelId = CKEDITOR.tools.getNextId();
    166168
    167                                                 output.push( expanded ? '>' : ' style="display:none">' );
     169                                var output = [ '<div class="cke_toolbox" role="toolbar" aria-labelledby="', labelId, '" onmousedown="return false;"' ],
     170                                        expanded =  editor.config.toolbarStartupExpanded !== false,
     171                                        groupStarted;
    168172
    169                                                 // Sends the ARIA label.
    170                                                 output.push( '<span id="', labelId, '" class="cke_voice_label">', editor.lang.toolbar, '</span>' );
     173                                output.push( expanded ? '>' : ' style="display:none">' );
    171174
    172                                                 var toolbars = editor.toolbox.toolbars,
    173                                                         toolbar =
    174                                                                         ( editor.config.toolbar instanceof Array ) ?
    175                                                                                 editor.config.toolbar
    176                                                                         :
    177                                                                                 editor.config[ 'toolbar_' + editor.config.toolbar ];
     175                                // Sends the ARIA label.
     176                                output.push( '<span id="', labelId, '" class="cke_voice_label">', editor.lang.toolbar, '</span>' );
    178177
    179                                                 for ( var r = 0 ; r < toolbar.length ; r++ )
    180                                                 {
    181                                                         var row = toolbar[ r ];
     178                                var toolbars = editor.toolbox.toolbars,
     179                                        toolbar =
     180                                                        ( editor.config.toolbar instanceof Array ) ?
     181                                                                editor.config.toolbar
     182                                                        :
     183                                                                editor.config[ 'toolbar_' + editor.config.toolbar ];
    182184
    183                                                         // It's better to check if the row object is really
    184                                                         // available because it's a common mistake to leave
    185                                                         // an extra comma in the toolbar definition
    186                                                         // settings, which leads on the editor not loading
    187                                                         // at all in IE. (#3983)
    188                                                         if ( !row )
    189                                                                 continue;
     185                                for ( var r = 0 ; r < toolbar.length ; r++ )
     186                                {
     187                                        var row = toolbar[ r ];
    190188
    191                                                         var toolbarId = CKEDITOR.tools.getNextId(),
    192                                                                 toolbarObj = { id : toolbarId, items : [] };
     189                                        // It's better to check if the row object is really
     190                                        // available because it's a common mistake to leave
     191                                        // an extra comma in the toolbar definition
     192                                        // settings, which leads on the editor not loading
     193                                        // at all in IE. (#3983)
     194                                        if ( !row )
     195                                                continue;
    193196
    194                                                         if ( groupStarted )
    195                                                         {
    196                                                                 output.push( '</div>' );
    197                                                                 groupStarted = 0;
    198                                                         }
     197                                        var toolbarId = CKEDITOR.tools.getNextId(),
     198                                                toolbarObj = { id : toolbarId, items : [] };
    199199
    200                                                         if ( row === '/' )
    201                                                         {
    202                                                                 output.push( '<div class="cke_break"></div>' );
    203                                                                 continue;
    204                                                         }
     200                                        if ( groupStarted )
     201                                        {
     202                                                output.push( '</div>' );
     203                                                groupStarted = 0;
     204                                        }
    205205
    206                                                         output.push( '<span id="', toolbarId, '" class="cke_toolbar" role="presentation"><span class="cke_toolbar_start"></span>' );
     206                                        if ( row === '/' )
     207                                        {
     208                                                output.push( '<div class="cke_break"></div>' );
     209                                                continue;
     210                                        }
    207211
    208                                                         // Add the toolbar to the "editor.toolbox.toolbars"
    209                                                         // array.
    210                                                         var index = toolbars.push( toolbarObj ) - 1;
     212                                        output.push( '<span id="', toolbarId, '" class="cke_toolbar" role="presentation"><span class="cke_toolbar_start"></span>' );
    211213
    212                                                         // Create the next/previous reference.
    213                                                         if ( index > 0 )
    214                                                         {
    215                                                                 toolbarObj.previous = toolbars[ index - 1 ];
    216                                                                 toolbarObj.previous.next = toolbarObj;
    217                                                         }
     214                                        // Add the toolbar to the "editor.toolbox.toolbars"
     215                                        // array.
     216                                        var index = toolbars.push( toolbarObj ) - 1;
    218217
    219                                                         // Create all items defined for this toolbar.
    220                                                         for ( var i = 0 ; i < row.length ; i++ )
    221                                                         {
    222                                                                 var item,
    223                                                                         itemName = row[ i ];
     218                                        // Create the next/previous reference.
     219                                        if ( index > 0 )
     220                                        {
     221                                                toolbarObj.previous = toolbars[ index - 1 ];
     222                                                toolbarObj.previous.next = toolbarObj;
     223                                        }
    224224
    225                                                                 if ( itemName == '-' )
    226                                                                         item = CKEDITOR.ui.separator;
    227                                                                 else
    228                                                                         item = editor.ui.create( itemName );
     225                                        // Create all items defined for this toolbar.
     226                                        for ( var i = 0 ; i < row.length ; i++ )
     227                                        {
     228                                                var item,
     229                                                        itemName = row[ i ];
    229230
    230                                                                 if ( item )
     231                                                if ( itemName == '-' )
     232                                                        item = CKEDITOR.ui.separator;
     233                                                else
     234                                                        item = editor.ui.create( itemName );
     235
     236                                                if ( item )
     237                                                {
     238                                                        if ( item.canGroup )
     239                                                        {
     240                                                                if ( !groupStarted )
    231241                                                                {
    232                                                                         if ( item.canGroup )
    233                                                                         {
    234                                                                                 if ( !groupStarted )
    235                                                                                 {
    236                                                                                         output.push( '<span class="cke_toolgroup" role="presentation">' );
    237                                                                                         groupStarted = 1;
    238                                                                                 }
    239                                                                         }
    240                                                                         else if ( groupStarted )
    241                                                                         {
    242                                                                                 output.push( '</span>' );
    243                                                                                 groupStarted = 0;
    244                                                                         }
    245 
    246                                                                         var itemObj = item.render( editor, output );
    247                                                                         index = toolbarObj.items.push( itemObj ) - 1;
    248 
    249                                                                         if ( index > 0 )
    250                                                                         {
    251                                                                                 itemObj.previous = toolbarObj.items[ index - 1 ];
    252                                                                                 itemObj.previous.next = itemObj;
    253                                                                         }
    254 
    255                                                                         itemObj.toolbar = toolbarObj;
    256                                                                         itemObj.onkey = itemKeystroke;
    257 
    258                                                                         /*
    259                                                                          * Fix for #3052:
    260                                                                          * Prevent JAWS from focusing the toolbar after document load.
    261                                                                          */
    262                                                                         itemObj.onfocus = function()
    263                                                                         {
    264                                                                                 if ( !editor.toolbox.focusCommandExecuted )
    265                                                                                         editor.focus();
    266                                                                         };
     242                                                                        output.push( '<span class="cke_toolgroup" role="presentation">' );
     243                                                                        groupStarted = 1;
    267244                                                                }
    268245                                                        }
    269 
    270                                                         if ( groupStarted )
     246                                                        else if ( groupStarted )
    271247                                                        {
    272248                                                                output.push( '</span>' );
    273249                                                                groupStarted = 0;
    274250                                                        }
    275251
    276                                                         output.push( '<span class="cke_toolbar_end"></span></span>' );
     252                                                        var itemObj = item.render( editor, output );
     253                                                        index = toolbarObj.items.push( itemObj ) - 1;
     254
     255                                                        if ( index > 0 )
     256                                                        {
     257                                                                itemObj.previous = toolbarObj.items[ index - 1 ];
     258                                                                itemObj.previous.next = itemObj;
     259                                                        }
     260
     261                                                        itemObj.toolbar = toolbarObj;
     262                                                        itemObj.onkey = itemKeystroke;
     263
     264                                                        /*
     265                                                         * Fix for #3052:
     266                                                         * Prevent JAWS from focusing the toolbar after document load.
     267                                                         */
     268                                                        itemObj.onfocus = function()
     269                                                        {
     270                                                                if ( !editor.toolbox.focusCommandExecuted )
     271                                                                        editor.focus();
     272                                                        };
    277273                                                }
     274                                        }
    278275
    279                                                 output.push( '</div>' );
     276                                        if ( groupStarted )
     277                                        {
     278                                                output.push( '</span>' );
     279                                                groupStarted = 0;
     280                                        }
    280281
    281                                                 if ( editor.config.toolbarCanCollapse )
     282                                        output.push( '<span class="cke_toolbar_end"></span></span>' );
     283                                }
     284
     285                                output.push( '</div>' );
     286
     287                                if ( editor.config.toolbarCanCollapse )
     288                                {
     289                                        var collapserFn = CKEDITOR.tools.addFunction(
     290                                                function()
    282291                                                {
    283                                                         var collapserFn = CKEDITOR.tools.addFunction(
    284                                                                 function()
    285                                                                 {
    286                                                                         editor.execCommand( 'toolbarCollapse' );
    287                                                                 });
     292                                                        editor.execCommand( 'toolbarCollapse' );
     293                                                });
    288294
    289                                                         editor.on( 'destroy', function () {
    290                                                                         CKEDITOR.tools.removeFunction( collapserFn );
    291                                                                 });
     295                                        editor.on( 'destroy', function () {
     296                                                        CKEDITOR.tools.removeFunction( collapserFn );
     297                                                });
    292298
    293                                                         var collapserId = CKEDITOR.tools.getNextId();
     299                                        var collapserId = CKEDITOR.tools.getNextId();
    294300
    295                                                         editor.addCommand( 'toolbarCollapse',
     301                                        editor.addCommand( 'toolbarCollapse',
     302                                                {
     303                                                        exec : function( editor )
     304                                                        {
     305                                                                var collapser = CKEDITOR.document.getById( collapserId ),
     306                                                                        toolbox = collapser.getPrevious(),
     307                                                                        contents = editor.getThemeSpace( 'contents' ),
     308                                                                        toolboxContainer = toolbox.getParent(),
     309                                                                        contentHeight = parseInt( contents.$.style.height, 10 ),
     310                                                                        previousHeight = toolboxContainer.$.offsetHeight,
     311                                                                        collapsed = !toolbox.isVisible();
     312
     313                                                                if ( !collapsed )
    296314                                                                {
    297                                                                         exec : function( editor )
    298                                                                         {
    299                                                                                 var collapser = CKEDITOR.document.getById( collapserId ),
    300                                                                                         toolbox = collapser.getPrevious(),
    301                                                                                         contents = editor.getThemeSpace( 'contents' ),
    302                                                                                         toolboxContainer = toolbox.getParent(),
    303                                                                                         contentHeight = parseInt( contents.$.style.height, 10 ),
    304                                                                                         previousHeight = toolboxContainer.$.offsetHeight,
    305                                                                                         collapsed = !toolbox.isVisible();
     315                                                                        toolbox.hide();
     316                                                                        collapser.addClass( 'cke_toolbox_collapser_min' );
     317                                                                        collapser.setAttribute( 'title', editor.lang.toolbarExpand );
     318                                                                }
     319                                                                else
     320                                                                {
     321                                                                        toolbox.show();
     322                                                                        collapser.removeClass( 'cke_toolbox_collapser_min' );
     323                                                                        collapser.setAttribute( 'title', editor.lang.toolbarCollapse );
     324                                                                }
    306325
    307                                                                                 if ( !collapsed )
    308                                                                                 {
    309                                                                                         toolbox.hide();
    310                                                                                         collapser.addClass( 'cke_toolbox_collapser_min' );
    311                                                                                         collapser.setAttribute( 'title', editor.lang.toolbarExpand );
    312                                                                                 }
    313                                                                                 else
    314                                                                                 {
    315                                                                                         toolbox.show();
    316                                                                                         collapser.removeClass( 'cke_toolbox_collapser_min' );
    317                                                                                         collapser.setAttribute( 'title', editor.lang.toolbarCollapse );
    318                                                                                 }
     326                                                                // Update collapser symbol.
     327                                                                collapser.getFirst().setText( collapsed ?
     328                                                                        '\u25B2' :              // BLACK UP-POINTING TRIANGLE
     329                                                                        '\u25C0' );             // BLACK LEFT-POINTING TRIANGLE
    319330
    320                                                                                 // Update collapser symbol.
    321                                                                                 collapser.getFirst().setText( collapsed ?
    322                                                                                         '\u25B2' :              // BLACK UP-POINTING TRIANGLE
    323                                                                                         '\u25C0' );             // BLACK LEFT-POINTING TRIANGLE
     331                                                                var dy = toolboxContainer.$.offsetHeight - previousHeight;
     332                                                                contents.setStyle( 'height', ( contentHeight - dy ) + 'px' );
    324333
    325                                                                                 var dy = toolboxContainer.$.offsetHeight - previousHeight;
    326                                                                                 contents.setStyle( 'height', ( contentHeight - dy ) + 'px' );
     334                                                                editor.fire( 'resize' );
     335                                                        },
    327336
    328                                                                                 editor.fire( 'resize' );
    329                                                                         },
     337                                                        modes : { wysiwyg : 1, source : 1 }
     338                                                } );
    330339
    331                                                                         modes : { wysiwyg : 1, source : 1 }
    332                                                                 } );
     340                                        output.push( '<a title="' + ( expanded ? editor.lang.toolbarCollapse : editor.lang.toolbarExpand )
     341                                                                                          + '" id="' + collapserId + '" tabIndex="-1" class="cke_toolbox_collapser' );
    333342
    334                                                         output.push( '<a title="' + ( expanded ? editor.lang.toolbarCollapse : editor.lang.toolbarExpand )
    335                                                                                                           + '" id="' + collapserId + '" tabIndex="-1" class="cke_toolbox_collapser' );
     343                                        if ( !expanded )
     344                                                output.push( ' cke_toolbox_collapser_min' );
    336345
    337                                                         if ( !expanded )
    338                                                                 output.push( ' cke_toolbox_collapser_min' );
     346                                        output.push( '" onclick="CKEDITOR.tools.callFunction(' + collapserFn + ')">',
     347                                                                '<span>&#9650;</span>',         // BLACK UP-POINTING TRIANGLE
     348                                                                '</a>' );
     349                                }
    339350
    340                                                         output.push( '" onclick="CKEDITOR.tools.callFunction(' + collapserFn + ')">',
    341                                                                                 '<span>&#9650;</span>',         // BLACK UP-POINTING TRIANGLE
    342                                                                                 '</a>' );
    343                                                 }
     351                                return output.join( '' );
     352                        };
    344353
    345                                                 event.data.html += output.join( '' );
    346                                         }
    347                                 });
     354                        var destroyToolbar = function()
     355                        {
     356                                var index = 0,
     357                                        i,
     358                                        items,
     359                                        instancem
     360                                        toolbars = this.toolbox.toolbars;
    348361
    349                         editor.on( 'destroy', function()
    350                         {
    351                                 var toolbars, index = 0, i,
    352                                                 items, instance;
    353                                 toolbars = this.toolbox.toolbars;
    354362                                for ( ; index < toolbars.length; index++ )
    355363                                {
    356364                                        items = toolbars[ index ].items;
     
    363371                                                if ( instance.index ) CKEDITOR.ui.button._.instances[ instance.index ] = null;
    364372                                        }
    365373                                }
    366                         });
     374                        };
    367375
     376                        editor.on( 'destroy', destroyToolbar );
     377
     378                        // Method to switch the currently used toolbar
     379                        editor.setToolbar = function( toolbar )
     380                        {
     381                                // Remove existing toolbar
     382                                destroyToolbar.call( this );
     383
     384                                // Set new one
     385                                this.config.toolbar = toolbar;
     386
     387                                // Create it
     388                                var toolbarLocation = this.config.toolbarLocation,
     389                                        space = document.getElementById('cke_' + toolbarLocation + '_' + this.name);
     390
     391                                space.innerHTML = generateToolbarHtml( this );
     392
     393                                // IE...
     394                                if ( CKEDITOR.env.ie )
     395                                {
     396                                        var table = space.parentNode.parentNode.parentNode;
     397                                        table.style.display = 'none';
     398                                        // Force refresh
     399                                        var h = table.scrollHeight;
     400                                        table.style.display = '';
     401                                }
     402                        };
     403
    368404                        editor.addCommand( 'toolbarFocus', commands.toolbarFocus );
    369405                }
    370406        });
© 2003 – 2022, CKSource sp. z o.o. sp.k. All rights reserved. | Terms of use | Privacy policy