Ticket #7498: 7498_3.patch

File 7498_3.patch, 6.6 KB (added by Garry Yao, 13 years ago)
  • _source/plugins/colorbutton/plugin.js

     
    120120
    121121                                        editor.fire( 'saveSnapshot' );
    122122
    123                                         // Clean up any conflicting style within the range.
    124                                         new CKEDITOR.style( config['colorButton_' + type + 'Style'], { color : 'inherit' } ).remove( editor.document );
    125123
    126124                                        if ( color )
    127125                                        {
     
    141139                                                                return element.getName() != 'a' || isUnstylable( element );
    142140                                                        };
    143141
    144                                                 new CKEDITOR.style( colorStyle, { color : color } ).apply( editor.document );
    145                                         }
     142                                                var style = new CKEDITOR.style( colorStyle, { color : color } );
     143
     144                                                var selection = editor.getSelection(),
     145                                                        range = selection.getRanges()[ 0 ],
     146                                                        elementPath = new CKEDITOR.dom.elementPath( range.startContainer ),
     147                                                        elements = elementPath.elements,
     148                                                        isRemove;
     149
     150                                                // Check if the current selected element is removable by this color style.
     151                                                for ( var i = 0 ; i < elements.length ; i++ )
     152                                                {
     153                                                        if ( style.checkElementRemovable( elements[ i ] ) )
     154                                                        {
     155                                                                isRemove = 1;
     156                                                                break;
     157                                                        }
     158                                                }
    146159
     160                                                if ( isRemove )
     161                                                        style.remove( editor.document );
     162                                                else
     163                                                {
     164                                                        // Clean up any conflicting style within the range.
     165                                                        new CKEDITOR.style( CKEDITOR.tools.extend( {}, config['colorButton_' + type + 'Style'],
     166                                                                        { splitOnRemove : 1 } ), { color : 'inherit' } ).remove( editor.document );
     167                                                        style.apply( editor.document );
     168                                                }
     169                                        }
     170
    147171                                        editor.fire( 'saveSnapshot' );
    148172                                });
    149173
  • _source/plugins/styles/plugin.js

     
    654654                range.enlarge( CKEDITOR.ENLARGE_ELEMENT, 1 );
    655655
    656656                var bookmark = range.createBookmark(),
    657                         startNode = bookmark.startNode;
     657                        startNode = bookmark.startNode,
     658                        endNode = bookmark.endNode,
     659                        me = this;
    658660
     661                /*
     662                 * Find out the style ancestor that needs to be broken down at startNode
     663                 * and endNode.
     664                 */
     665                function breakNodes()
     666                {
     667                        var startPath = new CKEDITOR.dom.elementPath( startNode.getParent() ),
     668                                endPath = endNode && new CKEDITOR.dom.elementPath( endNode.getParent() ),
     669                                breakStart = null,
     670                                breakEnd = null;
     671                        for ( var i = 0 ; i < startPath.elements.length ; i++ )
     672                        {
     673                                var element = startPath.elements[ i ];
     674
     675                                if ( element == startPath.block || element == startPath.blockLimit )
     676                                        break;
     677
     678                                if ( me.checkElementRemovable( element ) )
     679                                        breakStart = element;
     680                        }
     681                        for ( i = 0 ; endPath && i < endPath.elements.length ; i++ )
     682                        {
     683                                element = endPath.elements[ i ];
     684
     685                                if ( element == endPath.block || element == endPath.blockLimit )
     686                                        break;
     687
     688                                if ( me.checkElementRemovable( element ) )
     689                                        breakEnd = element;
     690                        }
     691
     692                        if ( breakEnd )
     693                                endNode.breakParent( breakEnd );
     694                        if ( breakStart )
     695                                startNode.breakParent( breakStart );
     696                }
     697
    659698                if ( range.collapsed )
    660699                {
    661700
     
    688727                                                boundaryElement = element;
    689728                                                boundaryElement.match = isStart ? 'start' : 'end';
    690729                                        }
     730                                        // If presents collapsed range will split the current style element but not remove the whole element.
     731                                        else if ( this._.definition.splitOnRemove )
     732                                                breakNodes();
    691733                                        else
    692734                                        {
    693735                                                /*
     
    734776                         * Now our range isn't collapsed. Lets walk from the start node to the end
    735777                         * node via DFS and remove the styles one-by-one.
    736778                         */
    737                         var endNode = bookmark.endNode,
    738                                 me = this;
    739 
    740                         /*
    741                          * Find out the style ancestor that needs to be broken down at startNode
    742                          * and endNode.
    743                          */
    744                         function breakNodes()
    745                         {
    746                                 var startPath = new CKEDITOR.dom.elementPath( startNode.getParent() ),
    747                                         endPath = new CKEDITOR.dom.elementPath( endNode.getParent() ),
    748                                         breakStart = null,
    749                                         breakEnd = null;
    750                                 for ( var i = 0 ; i < startPath.elements.length ; i++ )
    751                                 {
    752                                         var element = startPath.elements[ i ];
    753 
    754                                         if ( element == startPath.block || element == startPath.blockLimit )
    755                                                 break;
    756 
    757                                         if ( me.checkElementRemovable( element ) )
    758                                                 breakStart = element;
    759                                 }
    760                                 for ( i = 0 ; i < endPath.elements.length ; i++ )
    761                                 {
    762                                         element = endPath.elements[ i ];
    763 
    764                                         if ( element == endPath.block || element == endPath.blockLimit )
    765                                                 break;
    766 
    767                                         if ( me.checkElementRemovable( element ) )
    768                                                 breakEnd = element;
    769                                 }
    770 
    771                                 if ( breakEnd )
    772                                         endNode.breakParent( breakEnd );
    773                                 if ( breakStart )
    774                                         startNode.breakParent( breakStart );
    775                         }
    776779                        breakNodes();
    777780
    778781                        // Now, do the DFS walk.
     
    14591462                        return prop + names.join( ',' );
    14601463                });
    14611464
     1465                // Convert CSS color schema.
     1466                styleText = rgbToHex( styleText );
     1467
    14621468                // Shrinking white-spaces around colon and semi-colon (#4147).
    14631469                // Compensate tail semi-colon.
    14641470                return styleText.replace( /\s*([;:])\s*/, '$1' )
     
    14841490                return retval;
    14851491        }
    14861492
     1493        function rgbToHex( cssStyle )
     1494        {
     1495                return cssStyle.replace( /(?:rgb\(\s*(\d+)\s*,\s*(\d+)\s*,\s*(\d+)\s*\))/gi, function( match, red, green, blue )
     1496                        {
     1497                                red = parseInt( red, 10 ).toString( 16 );
     1498                                green = parseInt( green, 10 ).toString( 16 );
     1499                                blue = parseInt( blue, 10 ).toString( 16 );
     1500                                var color = [red, green, blue] ;
     1501
     1502                                // Add padding zeros if the hex value is less than 0x10.
     1503                                for ( var i = 0 ; i < color.length ; i++ )
     1504                                        color[i] = String( '0' + color[i] ).slice( -2 ) ;
     1505
     1506                                return '#' + color.join( '' ) ;
     1507                         });
     1508        }
     1509
     1510
    14871511        /**
    14881512         * Compare two bunch of styles, with the speciality that value 'inherit'
    14891513         * is treated as a wildcard which will match any value.
  • _source/plugins/font/plugin.js

     
    7070                                        if ( this.getValue() == value )
    7171                                                style.remove( editor.document );
    7272                                        else
     73                                        {
     74                                                // Clean up any conflicting style within the range.
     75                                                new CKEDITOR.style( CKEDITOR.tools.extend( {}, config[ 'fontSize_style' ],
     76                                                        { splitOnRemove : 1 } ) , { 'size' : 'inherit' } ).remove( editor.document );
    7377                                                style.apply( editor.document );
     78                                        }
    7479
    7580                                        editor.fire( 'saveSnapshot' );
    7681                                },
© 2003 – 2022, CKSource sp. z o.o. sp.k. All rights reserved. | Terms of use | Privacy policy