Ticket #4883: 4883.patch

File 4883.patch, 3.2 KB (added by Garry Yao, 14 years ago)
  • _source/plugins/pastefromword/filter/default.js

     
    258258                                };
    259259                        } )(),
    260260
     261                        // Providing a shorthand style then retrieve one or more style component values.
     262                        getStyleComponents : ( function()
     263                        {
     264                                var calculator = CKEDITOR.dom.element.createFromHtml(
     265                                                                '<div style="position:absolute;left:-9999px;top:-9999px;"></div>',
     266                                                                CKEDITOR.document );
     267                                CKEDITOR.document.getBody().append( calculator );
     268
     269                                return function( name, styleValue, fetchList )
     270                                {
     271                                        calculator.setStyle( name, styleValue );
     272                                        var styles = {},
     273                                                count = fetchList.length;
     274                                        for ( var i = 0; i < count; i++ )
     275                                                styles[ fetchList[ i ] ]  = calculator.getStyle( fetchList[ i ] );
     276
     277                                        return styles;
     278                                };
     279                        } )(),
     280
    261281                        listDtdParents : CKEDITOR.dtd.parentOf( 'ol' )
    262282                },
    263283
     
    453473                                                                                                whitelist && ( newValue = newValue || value );
    454474
    455475                                                                                                if( typeof newValue == 'function' )
    456                                                                                                         newValue = newValue( value, element );
     476                                                                                                        newValue = newValue( value, element, name );
     477
     478                                                                                                // Return an couple indicate both name and value
     479                                                                                                // changed.
     480                                                                                                if( newValue && newValue.push )
     481                                                                                                        name = newValue[ 0 ], newValue = newValue[ 1 ];
     482
    457483                                                                                                if( typeof newValue == 'string' )
    458484                                                                                                        rules.push( [ name, newValue ] );
    459485                                                                                                return;
     
    551577                                containsNothingButSpaces = this.utils.isContainingOnlySpaces,
    552578                                resolveListItem = this.utils.resolveList,
    553579                                convertToPx = this.utils.convertToPx,
     580                                getStyleComponents = this.utils.getStyleComponents,
    554581                                listDtdParents = this.utils.listDtdParents,
    555582                                removeFontStyles = config.pasteFromWordRemoveFontStyles !== false,
    556583                                removeStyles = config.pasteFromWordRemoveStyles !== false;
     
    887914                                        // Provide a white-list of styles that we preserve, those should
    888915                                        // be the ones that could later be altered with editor tools.
    889916                                        [
    890                                                 [ ( /^margin$|^margin-(?!bottom|top)/ ), null, function( value, element )
     917                                                // Preserve margin-left/right which used as default indent style in the editor.
     918                                                [ ( /^margin$|^margin-(?!bottom|top)/ ), null, function( value, element, name )
    891919                                                        {
    892                                                                 if( element.name in { p : 1, div : 1 }
    893                                                                         && !emptyMarginRegex.test( value ) )
    894                                                                         return value;
     920                                                                if( element.name in { p : 1, div : 1 } )
     921                                                                {
     922                                                                        var indentStyleName = config.contentsLangDirection == 'ltr' ?
     923                                                                                        'margin-left' : 'margin-right';
     924
     925                                                                        // Extract component value from 'margin' shorthand.
     926                                                                        if ( name == 'margin' )
     927                                                                        {
     928                                                                                value = getStyleComponents( name, value,
     929                                                                                                [ indentStyleName ] )[ indentStyleName ];
     930                                                                        }
     931                                                                        else if ( name != indentStyleName )
     932                                                                                return;
     933
     934                                                                        if ( value && !emptyMarginRegex.test( value ) )
     935                                                                                return [ indentStyleName, value ];
     936                                                                }
    895937                                                        } ],
    896938
    897939                                                [ ( /^border.*|margin.*|vertical-align|float$/ ), null,
© 2003 – 2022, CKSource sp. z o.o. sp.k. All rights reserved. | Terms of use | Privacy policy