Ticket #5931: 5931_5.patch

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

     
    483483                                // Get the element that holds the entire range.
    484484                                var parent = styleRange.getCommonAncestor();
    485485
     486                                var removeList = {
     487                                        styles : {},
     488                                        attrs : {},
     489                                        // Styles cannot be removed.
     490                                        blockedStyles : {},
     491                                        // Attrs cannot be removed.
     492                                        blockedAttrs : {}
     493                                };
     494
     495                                var attName, styleName, value;
     496
    486497                                // Loop through the parents, removing the redundant attributes
    487498                                // from the element to be applied.
    488499                                while ( styleNode && parent )
    489500                                {
    490501                                        if ( parent.getName() == elementName )
    491502                                        {
    492                                                 for ( var attName in def.attributes )
     503                                                for ( attName in def.attributes )
    493504                                                {
    494                                                         if ( styleNode.getAttribute( attName ) == parent.getAttribute( attName ) )
    495                                                                 styleNode.removeAttribute( attName );
    496                                                 }
     505                                                        if ( removeList.blockedAttrs[ attName ] || !( value = parent.getAttribute( styleName ) ) )
     506                                                                continue;
    497507
    498                                                 for ( var styleName in def.styles )
    499                                                 {
    500                                                         if ( styleNode.getStyle( styleName ) == parent.getStyle( styleName ) )
    501                                                                 styleNode.removeStyle( styleName );
     508                                                        if ( styleNode.getAttribute( attName ) == value )
     509                                                                removeList.attrs[ attName ] = 1;
     510                                                        else
     511                                                                removeList.blockedAttrs[ attName ] = 1;
    502512                                                }
    503513
    504                                                 if ( !styleNode.hasAttributes() )
     514                                                for ( styleName in def.styles )
    505515                                                {
    506                                                         styleNode = null;
    507                                                         break;
     516                                                        if ( removeList.blockedStyles[ styleName ] || !( value = parent.getStyle( styleName ) ) )
     517                                                                continue;
     518
     519                                                        if ( styleNode.getStyle( styleName ) == value )
     520                                                                removeList.styles[ styleName ] = 1;
     521                                                        else
     522                                                                removeList.blockedStyles[ styleName ] = 1;
    508523                                                }
    509524                                        }
    510525
    511526                                        parent = parent.getParent();
    512527                                }
    513528
     529                                for ( attName in removeList.attrs )
     530                                        styleNode.removeAttribute( attName );
     531
     532                                for ( styleName in removeList.styles )
     533                                        styleNode.removeStyle( styleName );
     534
     535                                if ( !styleNode.hasAttributes() )
     536                                        styleNode = null;
     537
    514538                                if ( styleNode )
    515539                                {
    516540                                        // Move the contents of the range to the style element.
     
    536560                                        if ( !CKEDITOR.env.ie )
    537561                                                styleNode.$.normalize();
    538562                                }
     563                                // Style already inherit from parents, left just to clear up any internal overrides. (#5931)
     564                                else
     565                                {
     566                                        styleNode = new CKEDITOR.dom.element( 'span' );
     567                                        styleRange.extractContents().appendTo( styleNode );
     568                                        styleRange.insertNode( styleNode );
     569                                        removeFromInsideElement( this, styleNode );
     570                                        styleNode.remove( true );
     571                                }
    539572
    540573                                // Style applied, let's release the range, so it gets
    541574                                // re-initialization in the next loop.
© 2003 – 2022, CKSource sp. z o.o. sp.k. All rights reserved. | Terms of use | Privacy policy