Ticket #6010: 6010_2.patch

File 6010_2.patch, 2.5 KB (added by Sa'ar Zac Elias, 14 years ago)
  • _source/plugins/colorbutton/plugin.js

     
    2222
    2323                function addButton( name, type, title )
    2424                {
     25                        var colorBoxId = CKEDITOR.tools.getNextId() + '_colorBox';
    2526                        editor.ui.add( name, CKEDITOR.UI_PANELBUTTON,
    2627                                {
    2728                                        label : title,
     
    3940                                        {
    4041                                                block.autoSize = true;
    4142                                                block.element.addClass( 'cke_colorblock' );
    42                                                 block.element.setHtml( renderColors( panel, type ) );
     43                                                block.element.setHtml( renderColors( panel, type, colorBoxId ) );
    4344                                                // The block should not have scrollbars (#5933, #6056)
    4445                                                block.element.getDocument().getBody().setStyle( 'overflow', 'hidden' );
    4546
     
    5253                                                keys[ 38 ]      = 'prev';                                       // ARROW-UP
    5354                                                keys[ CKEDITOR.SHIFT + 9 ]      = 'prev';       // SHIFT + TAB
    5455                                                keys[ 32 ]      = 'click';                                      // SPACE
     56                                        },
     57
     58                                        // The automatic colorbox should represent the real color (#6010)
     59                                        onOpen : function()
     60                                        {
     61                                                var selection = editor.getSelection(),
     62                                                        block = selection && selection.getStartElement(),
     63                                                        path = new CKEDITOR.dom.elementPath( block ),
     64                                                        color;
     65
     66                                                // Find the closest block element.
     67                                                block = path.block || path.blockLimit;
     68
     69                                                // The background color might be transparent. In that case, look up the color in the DOM tree.
     70                                                do
     71                                                {
     72                                                        color = block && block.getComputedStyle( type == 'back' ? 'background-color' : 'color' ) || 'transparent';
     73                                                }
     74                                                while ( type == 'back' && color == 'transparent' && ( block = block.getParent() ) );
     75
     76                                                // The box should never be transparent.
     77                                                if ( !color || color == 'transparent' )
     78                                                        color = '#ffffff';
     79
     80                                                this._.panel._.iframe.getFrameDocument().getById( colorBoxId ).setStyle( 'background-color', color );
    5581                                        }
    5682                                });
    5783                }
    5884
    5985
    60                 function renderColors( panel, type )
     86                function renderColors( panel, type, colorBoxId )
    6187                {
    6288                        var output = [],
    6389                                colors = config.colorButton_colors.split( ',' ),
     
    121147                                        '<table role="presentation" cellspacing=0 cellpadding=0 width="100%">' +
    122148                                                '<tr>' +
    123149                                                        '<td>' +
    124                                                                 '<span class="cke_colorbox" style="background-color:#000"></span>' +
     150                                                                '<span class="cke_colorbox" id="', colorBoxId, '"></span>' +
    125151                                                        '</td>' +
    126152                                                        '<td colspan=7 align=center>',
    127153                                                                lang.auto,
© 2003 – 2022, CKSource sp. z o.o. sp.k. All rights reserved. | Terms of use | Privacy policy