Ticket #5931: 5931_2.patch

File 5931_2.patch, 2.0 KB (added by Tobiasz Cudnik, 14 years ago)
  • _source/plugins/styles/plugin.js

     
    481481                                // Get the element that holds the entire range.
    482482                                var parent = styleRange.getCommonAncestor();
    483483
     484                                var removeList = {
     485                                        styles : {},
     486                                        attrs : {}
     487                                };
     488
     489                                var attName, styleName;
     490
    484491                                // Loop through the parents, removing the redundant attributes
    485492                                // from the element to be applied.
    486493                                while ( styleNode && parent )
    487494                                {
    488495                                        if ( parent.getName() == elementName )
    489496                                        {
    490                                                 for ( var attName in def.attributes )
     497                                                for ( attName in def.attributes )
    491498                                                {
    492499                                                        if ( styleNode.getAttribute( attName ) == parent.getAttribute( attName ) )
    493                                                                 styleNode.removeAttribute( attName );
     500                                                                removeList.attrs[ attName ] = 1;
     501                                                        else
     502                                                                delete removeList.attrs[ attName ];
    494503                                                }
    495504
    496                                                 for ( var styleName in def.styles )
     505                                                for ( styleName in def.styles )
    497506                                                {
    498507                                                        if ( styleNode.getStyle( styleName ) == parent.getStyle( styleName ) )
    499                                                                 styleNode.removeStyle( styleName );
     508                                                                removeList.attrs[ attName ] = 1;
     509                                                        else
     510                                                                delete removeList.attrs[ attName ];
    500511                                                }
     512                                        }
    501513
    502                                                 if ( !styleNode.hasAttributes() )
    503                                                 {
    504                                                         styleNode = null;
    505                                                         break;
    506                                                 }
    507                                         }
     514                                        parent = parent.getParent();
     515                                }
     516
     517                                for ( attName in removeList.attrs )
     518                                {
     519                                        // Skip prototype extensions.
     520                                        if ( !removeList.attrs.hasOwnProperty( attName ) )
     521                                                continue;
     522                                        styleNode.removeAttribute( attName );
     523                                }
    508524
    509                                         parent = parent.getParent();
     525                                for ( styleName in removeList.styles )
     526                                {
     527                                        // Skip prototype extensions.
     528                                        if ( !removeList.styles.hasOwnProperty( styleName ) )
     529                                                continue;
     530                                        styleNode.removeStyle( styleName );
    510531                                }
    511532
     533                                if ( !styleNode.hasAttributes() )
     534                                        styleNode = null;
     535
    512536                                if ( styleNode )
    513537                                {
    514538                                        // Move the contents of the range to the style element.
© 2003 – 2022, CKSource sp. z o.o. sp.k. All rights reserved. | Terms of use | Privacy policy