Ticket #3450: 3450_4.patch

File 3450_4.patch, 5.1 KB (added by Garry Yao, 15 years ago)
  • _source/plugins/styles/plugin.js

     
    197197                                        {
    198198                                                if ( attName == '_length' )
    199199                                                        continue;
    200 
    201                                                 if ( compareAttributeValues(attName, attribs[attName], element.getAttribute( attName ) ) )
     200                                                if ( attribs[attName] == element.getAttribute( attName ) )
    202201                                                {
    203202                                                        if ( !fullMatch )
    204203                                                                return true;
     
    269268                // Browsers make some changes to the style when applying them. So, here
    270269                // we normalize it to the browser format.
    271270                if ( stylesText.length )
    272                 {
    273271                        stylesText = normalizeCssText( stylesText );
    274 
    275                         if ( stylesText.length )
    276                                 stylesText = stylesText.replace( semicolonFixRegex, ';' );
    277                 }
    278 
     272               
    279273                // Return it, saving it to the next request.
    280274                return ( styleDefinition._ST = stylesText );
    281275        };
     
    889883                }
    890884        }
    891885
    892         var spacesRegex = /\s+/g;
    893886
    894887        // Returns an object that can be used for style matching comparison.
    895888        // Attributes names and values are all lowercased, and the styles get
     
    912905                        for ( var styleAtt in styleAttribs )
    913906                        {
    914907                                length++;
    915                                 attribs[ styleAtt.toLowerCase() ] = styleAttribs[ styleAtt ].toLowerCase();
     908                                attribs[ styleAtt ] = styleAttribs[ styleAtt ];
    916909                        }
    917910                }
    918911
    919912                // Includes the style definitions.
    920913                var styleText = CKEDITOR.style.getStyleText( styleDefinition );
    921                 if ( styleText.length > 0 )
     914                if ( styleText )
    922915                {
    923916                        if ( !attribs[ 'style' ] )
    924917                                length++;
    925 
    926                         attribs['style'] = styleText.replace( spacesRegex, '' ).toLowerCase();
     918                        attribs[ 'style' ] = styleText;
    927919                }
    928920
    929921                // Appends the "length" information to the object.
     
    1001993        {
    1002994                // Injects the style in a temporary span object, so the browser parses it,
    1003995                // retrieving its final format.
    1004                 var tempSpan = document.createElement( 'span' );
    1005                 tempSpan.style.cssText = unparsedCssText;
    1006                 return tempSpan.style.cssText;
     996                var temp = new CKEDITOR.dom.element( 'span' );
     997                temp.setAttribute( 'style', unparsedCssText );
     998                return temp.getAttribute( 'style' );
    1007999        }
    10081000
    1009         // valueA is our internal "for comparison" value.
    1010         // valueB is the value retrieved from the element.
    1011         function compareAttributeValues( attName, valueA, valueB )
    1012         {
    1013                 if ( valueA == valueB || ( !valueA && !valueB ) )
    1014                         return true;
    1015                 else if ( !valueA || !valueB )
    1016                         return false;
    1017 
    1018                 valueB = valueB.toLowerCase();
    1019 
    1020                 if ( attName == 'style' )
    1021                 {
    1022                         valueB = valueB.replace( spacesRegex, '' );
    1023                         if ( valueB.charAt( valueB.length - 1 ) != ';' )
    1024                                 valueB += ';';
    1025                 }
    1026 
    1027                 // Return true if they match or if valueA is null and valueB is an empty string
    1028                 return ( valueA == valueB );
    1029         }
    1030 
    10311001        function applyStyle( document, remove )
    10321002        {
    10331003                // Get all ranges from the selection.
  • _source/core/dom/element.js

     
    430430
    431431                                                case 'style':
    432432                                                        // IE does not return inline styles via getAttribute(). See #2947.
    433                                                         return this.$.style.cssText;
     433                                                        var styleText = this.$.style.cssText;
     434                                                        return styleText.toLowerCase().replace(
     435                                                                /\s*(?:;\s*|$)/, ';').replace(
     436                                                                        /([^;])$/, '$1;');
    434437                                        }
    435438
    436439                                        return standard.call( this, name );
  • _source/tests/core/dom/element.html

     
    172172                        var element = new CKEDITOR.dom.element( document.getElementById( 'test1' ) );
    173173                        element.setAttribute( 'style', 'position: absolute;' );
    174174
    175                         assert.areEqual( 'position:absolute', document.getElementById( 'test1' ).style.cssText.replace( /[\s;]/g, '' ).toLowerCase() );
     175                        assert.areEqual( 'position: absolute;', element.getAttribute( 'style' ) );
    176176                },
    177177
    178178                test_setAttribute3 : function()
     
    201201                                'rows'  : 5 });
    202202
    203203                        assert.areSame( 'Test', document.getElementById( 'test1' ).className, 'class is wrong' );
    204                         assert.areEqual( 'position:absolute', document.getElementById( 'test1' ).style.cssText.replace( /[\s;]/g, '' ).toLowerCase(), 'style is wrong' );
     204                        assert.areEqual( 'position: absolute;', element.getAttribute( 'style'), 'style is wrong' );
    205205                        assert.areEqual( 'TestName', document.getElementById( 'test1' ).name, 'name is wrong' );
    206206                        assert.areEqual( 5, document.getElementById( 'test1' ).rows, 'rows is wrong' );
    207207                },
     
    414414                        assert.areEqual( 'hasExpando', element.getAttribute( 'class' ), 'class is wrong' );
    415415                        element.removeAttribute( 'class' );
    416416
    417                         assert.areEqual( 'float:right', element.getAttribute( 'style' ).toLowerCase().replace( /[ ;]/g, '' ) );
     417                        assert.areEqual( 'float: right;', element.getAttribute( 'style' ) );
    418418
    419419                        element.removeAttribute( 'style' );
    420420                        element.removeAttribute( 'id' );
© 2003 – 2022, CKSource sp. z o.o. sp.k. All rights reserved. | Terms of use | Privacy policy