Ticket #5931: 5931_6.patch

File 5931_6.patch, 3.2 KB (added by Garry Yao, 14 years ago)
  • _source/plugins/styles/plugin.js

     
    478478                        if ( applyStyle && styleRange && !styleRange.collapsed )
    479479                        {
    480480                                // Build the style element, based on the style object definition.
    481                                 var styleNode = getElement( this, document );
     481                                var styleNode = getElement( this, document ),
     482                                        styleHasAttrs = styleNode.hasAttributes();
    482483
    483484                                // Get the element that holds the entire range.
    484485                                var parent = styleRange.getCommonAncestor();
    485486
     487                                var removeList = {
     488                                        styles : {},
     489                                        attrs : {},
     490                                        // Styles cannot be removed.
     491                                        blockedStyles : {},
     492                                        // Attrs cannot be removed.
     493                                        blockedAttrs : {}
     494                                };
     495
     496                                var attName, styleName, value;
     497
    486498                                // Loop through the parents, removing the redundant attributes
    487499                                // from the element to be applied.
    488500                                while ( styleNode && parent )
    489501                                {
    490502                                        if ( parent.getName() == elementName )
    491503                                        {
    492                                                 for ( var attName in def.attributes )
     504                                                for ( attName in def.attributes )
    493505                                                {
    494                                                         if ( styleNode.getAttribute( attName ) == parent.getAttribute( attName ) )
    495                                                                 styleNode.removeAttribute( attName );
    496                                                 }
     506                                                        if ( removeList.blockedAttrs[ attName ] || !( value = parent.getAttribute( styleName ) ) )
     507                                                                continue;
    497508
    498                                                 for ( var styleName in def.styles )
    499                                                 {
    500                                                         if ( styleNode.getStyle( styleName ) == parent.getStyle( styleName ) )
    501                                                                 styleNode.removeStyle( styleName );
     509                                                        if ( styleNode.getAttribute( attName ) == value )
     510                                                                removeList.attrs[ attName ] = 1;
     511                                                        else
     512                                                                removeList.blockedAttrs[ attName ] = 1;
    502513                                                }
    503514
    504                                                 if ( !styleNode.hasAttributes() )
     515                                                for ( styleName in def.styles )
    505516                                                {
    506                                                         styleNode = null;
    507                                                         break;
     517                                                        if ( removeList.blockedStyles[ styleName ] || !( value = parent.getStyle( styleName ) ) )
     518                                                                continue;
     519
     520                                                        if ( styleNode.getStyle( styleName ) == value )
     521                                                                removeList.styles[ styleName ] = 1;
     522                                                        else
     523                                                                removeList.blockedStyles[ styleName ] = 1;
    508524                                                }
    509525                                        }
    510526
    511527                                        parent = parent.getParent();
    512528                                }
    513529
     530                                for ( attName in removeList.attrs )
     531                                        styleNode.removeAttribute( attName );
     532
     533                                for ( styleName in removeList.styles )
     534                                        styleNode.removeStyle( styleName );
     535
     536                                if ( styleHasAttrs && !styleNode.hasAttributes() )
     537                                        styleNode = null;
     538
    514539                                if ( styleNode )
    515540                                {
    516541                                        // Move the contents of the range to the style element.
     
    536561                                        if ( !CKEDITOR.env.ie )
    537562                                                styleNode.$.normalize();
    538563                                }
     564                                // Style already inherit from parents, left just to clear up any internal overrides. (#5931)
     565                                else
     566                                {
     567                                        styleNode = new CKEDITOR.dom.element( 'span' );
     568                                        styleRange.extractContents().appendTo( styleNode );
     569                                        styleRange.insertNode( styleNode );
     570                                        removeFromInsideElement( this, styleNode );
     571                                        styleNode.remove( true );
     572                                }
    539573
    540574                                // Style applied, let's release the range, so it gets
    541575                                // re-initialization in the next loop.
© 2003 – 2022, CKSource sp. z o.o. sp.k. All rights reserved. | Terms of use | Privacy policy