Ticket #6082: 6082_3.patch

File 6082_3.patch, 6.8 KB (added by Frederico Caldeira Knabben, 14 years ago)
  • _source/core/config.js

     
    330330        baseFloatZIndex : 10000
    331331};
    332332
     333/**
     334 * Indicates that some of the editor features, like alignement and text
     335 * direction, should used the "computed value" of the feature to indicate it's
     336 * on/off state, instead of using the "real value".
     337 *
     338 * If enabled, in a left to right written document, the "Left Justify"
     339 * alignment button will show as active, even if the aligment style is not
     340 * explicitly applied to the current paragraph in the editor.
     341 * @name CKEDITOR.config.useComputedState
     342 * @type Boolean
     343 * @default true
     344 * @example
     345 * config.useComputedState = false;
     346 */
     347
    333348// PACKAGER_RENAME( CKEDITOR.config )
  • _source/plugins/bidi/plugin.js

     
    1717
    1818        function getState( editor, path, dir )
    1919        {
    20                 var selection = editor.getSelection(),
    21                         ranges = selection.getRanges();
     20                var useComputedState = editor.config.useComputedState,
     21                        selectedElement;
    2222
    23                 var selectedElement = ranges && ranges[ 0 ].getEnclosedNode();
     23                useComputedState = useComputedState === undefined || useComputedState;
    2424
    25                 // If this is not our element of interest, apply to fully selected elements from guardElements.
    26                 if ( !selectedElement || selectedElement
    27                                 && !( selectedElement.type == CKEDITOR.NODE_ELEMENT && selectedElement.getName() in directSelectionGuardElements )
    28                         )
    29                         selectedElement = getFullySelected( selection, guardElements );
     25                if ( useComputedState )
     26                {
     27                        var selection = editor.getSelection(),
     28                                ranges = selection.getRanges();
    3029
     30                        selectedElement = ranges && ranges[ 0 ].getEnclosedNode();
     31
     32                        // If this is not our element of interest, apply to fully selected elements from guardElements.
     33                        if ( !selectedElement || selectedElement
     34                                        && !( selectedElement.type == CKEDITOR.NODE_ELEMENT && selectedElement.getName() in directSelectionGuardElements )
     35                                )
     36                                selectedElement = getFullySelected( selection, guardElements );
     37                }
     38
    3139                selectedElement = selectedElement || path.block || path.blockLimit;
    3240
    3341                if ( !selectedElement || selectedElement.getName() == 'body' )
    3442                        return CKEDITOR.TRISTATE_OFF;
    3543
    36                 return ( selectedElement.getComputedStyle( 'direction' ) == dir ) ?
     44                selectedElement = useComputedState ?
     45                        selectedElement.getComputedStyle( 'direction' ) :
     46                        selectedElement.getStyle( 'direction' ) || selectedElement.getAttribute( 'dir' );
     47
     48                return ( selectedElement == dir ) ?
    3749                        CKEDITOR.TRISTATE_ON : CKEDITOR.TRISTATE_OFF;
    3850        }
    3951
    4052        function switchDir( element, dir, editor )
    4153        {
    42                 var dirBefore = element.getComputedStyle( 'direction' );
     54                var dirBefore = element.getComputedStyle( 'direction' ),
     55                        currentDir = element.getStyle( 'direction' ) || element.getAttribute( 'dir' ) || '';
    4356
    44                 if ( element.hasAttribute( 'dir' ) && element.getAttribute( 'dir' ).toLowerCase() == dir )
     57                element.removeStyle( 'direction' );
     58
     59                if ( currentDir.toLowerCase() == dir )
    4560                        element.removeAttribute( 'dir' );
    4661                else
    4762                        element.setAttribute( 'dir', dir );
  • _source/plugins/justify/plugin.js

     
    1818                if ( !firstBlock || firstBlock.getName() == 'body' )
    1919                        return CKEDITOR.TRISTATE_OFF;
    2020
    21                 var currentAlign = firstBlock.getComputedStyle( 'text-align' ).replace( alignRemoveRegex, '' );
    22                 if ( ( !currentAlign && isDefaultAlign( this, firstBlock ) ) || currentAlign == this.value )
    23                         return CKEDITOR.TRISTATE_ON;
    24                 return CKEDITOR.TRISTATE_OFF;
     21                return ( getAlignment( firstBlock, editor.config.useComputedState ) == this.value ) ?
     22                        CKEDITOR.TRISTATE_ON :
     23                        CKEDITOR.TRISTATE_OFF;
    2524        }
    2625
     26        function getAlignment( element, useComputedState )
     27        {
     28                useComputedState = useComputedState === undefined || useComputedState;
     29
     30                var align = useComputedState ?
     31                        element.getComputedStyle( 'text-align' ) :
     32                        element.getStyle( 'text-align' ) || element.getAttribute( 'align' ) || '';
     33
     34                align && ( align = align.replace( /-moz-|-webkit-|start|auto/i, '' ) );
     35
     36                !align && useComputedState && ( align = element.getComputedStyle( 'direction' ) == 'rtl' ? 'right' : 'left' );
     37
     38                return align;
     39        }
     40
    2741        function onSelectionChange( evt )
    2842        {
    2943                var command = evt.editor.getCommand( this.name );
     
    3145                command.fire( 'state' );
    3246        }
    3347
    34         function isDefaultAlign( command, element )
    35         {
    36                 var direction = element.getComputedStyle( 'direction' ),
    37                         val = command.value;
    38                 return ( direction == 'rtl' && val == 'right' ) || ( direction == 'ltr' && val == 'left' );
    39 
    40         }
    41 
    4248        function justifyCommand( editor, name, value )
    4349        {
    4450                this.name = name;
     
    7985                        var bookmarks = selection.createBookmarks(),
    8086                                ranges = selection.getRanges( true );
    8187
    82 
    8388                        var cssClassName = this.cssClassName,
    8489                                iterator,
    8590                                block;
     91
     92                        var useComputedState = editor.config.useComputedState;
     93                        useComputedState = useComputedState === undefined || useComputedState;
     94
    8695                        for ( var i = ranges.length - 1 ; i >= 0 ; i-- )
    8796                        {
    8897                                iterator = ranges[ i ].createIterator();
     
    91100                                while ( ( block = iterator.getNextParagraph() ) )
    92101                                {
    93102                                        block.removeAttribute( 'align' );
     103                                        block.removeStyle( 'text-align' );
    94104
    95                                         var isDefault = isDefaultAlign( this, block );
     105                                        // Remove any of the alignment classes from the className.
     106                                        var className = cssClassName && ( block.$.className =
     107                                                CKEDITOR.tools.ltrim( block.$.className.replace( this.cssClassRegex, '' ) ) );
    96108
     109                                        var apply =
     110                                                ( this.state == CKEDITOR.TRISTATE_OFF ) &&
     111                                                ( !useComputedState || ( getAlignment( block, true ) == this.value ) );
     112
    97113                                        if ( cssClassName )
    98114                                        {
    99                                                 // Remove any of the alignment classes from the className.
    100                                                 var className = block.$.className =
    101                                                         CKEDITOR.tools.ltrim( block.$.className.replace( this.cssClassRegex, '' ) );
    102 
    103115                                                // Append the desired class name.
    104                                                 if ( this.state == CKEDITOR.TRISTATE_OFF && !isDefault )
     116                                                if ( apply )
    105117                                                        block.addClass( cssClassName );
    106118                                                else if ( !className )
    107119                                                        block.removeAttribute( 'class' );
    108120                                        }
    109                                         else
    110                                         {
    111                                                 if ( this.state == CKEDITOR.TRISTATE_OFF && !isDefault )
    112                                                         block.setStyle( 'text-align', this.value );
    113                                                 else
    114                                                         block.removeStyle( 'text-align' );
    115                                         }
     121                                        else if ( apply )
     122                                                block.setStyle( 'text-align', this.value );
    116123                                }
    117124
    118125                        }
© 2003 – 2022, CKSource sp. z o.o. sp.k. All rights reserved. | Terms of use | Privacy policy