Ticket #5931: 5931_3.patch

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

     
    479479                        {
    480480                                // Build the style element, based on the style object definition.
    481481                                var styleNode = getElement( this, document );
    482 
    483482                                // Get the element that holds the entire range.
    484483                                var parent = styleRange.getCommonAncestor();
    485484
     485                                var styleRange2 = styleRange.clone();
     486                                styleRange2.shrink();
     487                                var innerStyle = styleRange2.getCommonAncestor();
     488                               
     489                                if ( innerStyle.$ != parent.$ )
     490                                {
     491                                        for ( attName in def.attributes )
     492                                        {
     493                                                if ( innerStyle.hasAttribute( attName ) )
     494                                                        innerStyle.removeAttribute( attName );
     495                                        }
     496
     497                                        for ( styleName in def.styles )
     498                                        {
     499                                                if ( innerStyle.getStyle( styleName ) )
     500                                                        innerStyle.removeStyle( styleName );
     501                                        }
     502
     503                                        if ( !innerStyle.getAttribute( 'style' ) )
     504                                                innerStyle.removeAttribute( 'style' );
     505                                       
     506                                        if ( !innerStyle.hasAttributes() )
     507                                        {
     508                                                var target = innerStyle.getParent();
     509                                                var child;
     510                                                while ( child = innerStyle.$.lastChild )
     511                                                        target.$.insertBefore( innerStyle.$.removeChild( child ), innerStyle.$.nextSibling );
     512                                                innerStyle.remove();
     513                                        }
     514                                }                               
     515
     516                                var removeList = {
     517                                        styles : {},
     518                                        attrs : {},
     519                                        // Styles cannot be removed.
     520                                        blockedStyles : {},
     521                                        // Attrs cannot be removed.
     522                                        blockedAttrs : {}
     523                                };
     524
     525                                var attName, styleName, value;
     526
    486527                                // Loop through the parents, removing the redundant attributes
    487528                                // from the element to be applied.
    488529                                while ( styleNode && parent )
    489530                                {
    490531                                        if ( parent.getName() == elementName )
    491532                                        {
    492                                                 for ( var attName in def.attributes )
     533                                                for ( attName in def.attributes )
    493534                                                {
    494                                                         if ( styleNode.getAttribute( attName ) == parent.getAttribute( attName ) )
    495                                                                 styleNode.removeAttribute( attName );
    496                                                 }
     535                                                        if ( removeList.blockedAttrs[ attName ] || !( value = parent.getAttribute( styleName ) ) )
     536                                                                continue;
    497537
    498                                                 for ( var styleName in def.styles )
    499                                                 {
    500                                                         if ( styleNode.getStyle( styleName ) == parent.getStyle( styleName ) )
    501                                                                 styleNode.removeStyle( styleName );
     538                                                        if ( styleNode.getAttribute( attName ) == value )
     539                                                                removeList.attrs[ attName ] = 1;
     540                                                        else
     541                                                                removeList.blockedAttrs[ attName ] = 1;
    502542                                                }
    503543
    504                                                 if ( !styleNode.hasAttributes() )
     544                                                for ( styleName in def.styles )
    505545                                                {
    506                                                         styleNode = null;
    507                                                         break;
     546                                                        if ( removeList.blockedStyles[ styleName ] || !( value = parent.getStyle( styleName ) ) )
     547                                                                continue;
     548
     549                                                        if ( styleNode.getStyle( styleName ) == value )
     550                                                                removeList.styles[ styleName ] = 1;
     551                                                        else
     552                                                                removeList.blockedStyles[ styleName ] = 1;
    508553                                                }
    509554                                        }
    510555
    511556                                        parent = parent.getParent();
    512557                                }
    513558
     559                                for ( attName in removeList.attrs )
     560                                {
     561                                        // Skip prototype extensions.
     562                                        if ( !removeList.attrs.hasOwnProperty( attName ) )
     563                                                continue;
     564                                        styleNode.removeAttribute( attName );
     565                                }
     566
     567                                for ( styleName in removeList.styles )
     568                                {
     569                                        // Skip prototype extensions.
     570                                        if ( !removeList.styles.hasOwnProperty( styleName ) )
     571                                                continue;
     572                                        styleNode.removeStyle( styleName );
     573                                }
     574
     575                                if ( !styleNode.hasAttributes() )
     576                                        styleNode = null;
     577
    514578                                if ( styleNode )
    515579                                {
    516580                                        // 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