Ticket #7430: 7430_3.patch

File 7430_3.patch, 5.1 KB (added by Garry Yao, 12 years ago)
  • _source/plugins/image/plugin.js

    IDEA additional info:
    Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP
    <+>UTF-8
     
    4848                                });
    4949                }
    5050
     51                function getSelectedImage( element )
     52                {
     53                        var selected = element || editor.getSelection().getSelectedElement();
     54                        if ( selected && selected.is( 'img' ) && !selected.data( 'cke-realelement' ) && !selected.isReadOnly() )
     55                                return selected;
     56                }
     57
    5158                // If the "contextmenu" plugin is loaded, register the listeners.
    5259                if ( editor.contextMenu )
    5360                {
    5461                        editor.contextMenu.addListener( function( element, selection )
    5562                                {
    56                                         if ( !element || !element.is( 'img' ) || element.data( 'cke-realelement' ) || element.isReadOnly() )
    57                                                 return null;
    58 
    59                                         return { image : CKEDITOR.TRISTATE_OFF };
     63                                        if ( getSelectedImage( element ) )
     64                                                return { image : CKEDITOR.TRISTATE_OFF };
    6065                                });
     66                }
     67
     68                editor.on( 'beforeCommandExec', function( evt )
     69                        {
     70                                var data = evt.data;
     71                                var img;
     72
     73                                if ( /^justify(left|right)/.exec( data.name ) && ( img = getSelectedImage() ) )
     74                                {
     75                                        var value = data.command.value;
     76                                        var align = getImageAlignment( img );
     77                                        align == value ? img.removeStyle( 'float' ) : img.setStyle( 'float', value )
     78
     79                                        evt.cancel();
     80                                }
     81                        });
     82
     83                editor.on( 'commandState', function( evt )
     84                        {
     85                                var cmd = evt.data.command, img;
     86                                if ( /^justify/.exec( cmd.name ) && ( img = getSelectedImage() ) )
     87                                {
     88                                        var value = cmd.value,
     89                                                align = getImageAlignment( img );
     90
     91                                        evt.data.state =
     92                                                ( align == value ) ? CKEDITOR.TRISTATE_ON :
     93                                                ( value == 'right' || value == 'left' ) ? CKEDITOR.TRISTATE_OFF :
     94                                                CKEDITOR.TRISTATE_DISABLED;
     95
     96                                        evt.cancel();
     97                                }
     98
     99                        }, null, null, 10 );
     100
     101
     102                function getImageAlignment( element )
     103                {
     104                        var align = element.getStyle( 'float' );
     105                        if ( align == 'inherit' || align == 'none' )
     106                                align = 0;
     107
     108                        if ( !align )
     109                                align = element.getAttribute( 'align' );
     110
     111                        return align;
    61112                }
    62113        }
    63114} );
  • _source/core/editor.js

    IDEA additional info:
    Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP
    <+>UTF-8
     
    573573                },
    574574
    575575                /**
     576                 * Query the state of the specified command name, optionally perform a
     577                 * fresh update.
     578                 *
     579                 * @param {String} commandName The indentifier name of the command.
     580                 * @param {Boolean} [doUpdate] If specified it fires a "commandState"
     581                 *              event on editor to update the state.
     582                 */
     583                queryCommandState : function( commandName, doUpdate )
     584                {
     585                        var command = this.getCommand( commandName );
     586                       
     587                        if ( !doUpdate )
     588                                return command.state;
     589
     590                        var sel = this.getSelection(),
     591                                start = sel && sel.getStartElement();
     592
     593                        // Perform a command state update.
     594                        var eventData =
     595                        {
     596                                name: commandName,
     597                                state : -1,
     598                                command: command,
     599                                selection : sel,
     600                                path : sel && new CKEDITOR.dom.elementPath( start )
     601                        };
     602
     603                        this.fire( 'commandState', eventData );
     604
     605                        if ( eventData.state != -1 )
     606                                command.setState( eventData.state );
     607
     608                        return command.state;
     609                },
     610
     611                /**
    576612                 * Executes a command associated with the editor.
    577613                 * @param {String} commandName The indentifier name of the command.
    578614                 * @param {Object} [data] Data to be passed to the command.
  • _source/plugins/justify/plugin.js

    IDEA additional info:
    Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP
    <+>UTF-8
     
    4040                        align = element.getStyle( 'text-align' ) || element.getAttribute( 'align' ) || '';
    4141                }
    4242
    43                 align && ( align = align.replace( /-moz-|-webkit-|start|auto/i, '' ) );
     43                // Sometimes computed values doesn't tell.
     44                align && ( align = align.replace( /(?:-(?:moz|webkit)-)?(?:start|auto)/i, '' ) );
    4445
    4546                !align && useComputedState && ( align = element.getComputedStyle( 'direction' ) == 'rtl' ? 'right' : 'left' );
    4647
     
    4950
    5051        function onSelectionChange( evt )
    5152        {
    52                 if ( evt.editor.readOnly )
     53                var editor = evt.editor;
     54                if ( editor.readOnly )
    5355                        return;
    5456
    55                 var command = evt.editor.getCommand( this.name );
    56                 command.state = getState.call( this, evt.editor, evt.data.path );
    57                 command.fire( 'state' );
     57                editor.queryCommandState( this.name, 1 );
    5858        }
    5959
    6060        function justifyCommand( editor, name, value )
     
    234234                        editor.on( 'selectionChange', CKEDITOR.tools.bind( onSelectionChange, right ) );
    235235                        editor.on( 'selectionChange', CKEDITOR.tools.bind( onSelectionChange, center ) );
    236236                        editor.on( 'selectionChange', CKEDITOR.tools.bind( onSelectionChange, justify ) );
     237                        editor.on( 'commandState', function( evt )
     238                        {
     239                                evt.data.state = getState.call( evt.data.command, editor, evt.data.path );
     240                        } );
    237241                        editor.on( 'dirChanged', onDirChanged );
    238242                },
    239243
© 2003 – 2022, CKSource sp. z o.o. sp.k. All rights reserved. | Terms of use | Privacy policy