Ticket #6020: 6020_4.patch

File 6020_4.patch, 3.8 KB (added by Sa'ar Zac Elias, 13 years ago)
  • _source/plugins/clipboard/plugin.js

     
    6161        var cutCopyCmd = function( type )
    6262        {
    6363                this.type = type;
    64                 this.canUndo = ( this.type == 'cut' );          // We can't undo copy to clipboard.
     64                this.canUndo = this.type == 'cut';              // We can't undo copy to clipboard.
     65                this.startDisabled = true;
    6566        };
    6667
    6768        cutCopyCmd.prototype =
     
    281282                }
    282283        }
    283284
     285        var depressBeforeEvent;
     286        function stateFromNamedCommand( command, editor )
     287        {
     288                // IE Bug: queryCommandEnabled('paste') fires also 'beforepaste(copy/cut)',
     289                // guard to distinguish from the ordinary sources( either
     290                // keyboard paste or execCommand ) (#4874).
     291                CKEDITOR.env.ie && ( depressBeforeEvent = 1 );
     292
     293                var retval = editor.document.$.queryCommandEnabled( command ) ? CKEDITOR.TRISTATE_OFF : CKEDITOR.TRISTATE_DISABLED;
     294                depressBeforeEvent = 0;
     295                return retval;
     296        }
     297
     298        var inReadOnly;
     299        function setToolbarStates()
     300        {
     301                if ( this.mode != 'wysiwyg' )
     302                        return;
     303
     304                this.getCommand( 'cut' ).setState( inReadOnly ? CKEDITOR.TRISTATE_DISABLED : stateFromNamedCommand( 'Cut', this ) );
     305                this.getCommand( 'copy' ).setState( stateFromNamedCommand( 'Copy', this ) );
     306                this.getCommand( 'paste' ).setState( inReadOnly ? CKEDITOR.TRISTATE_DISABLED :
     307                                                CKEDITOR.env.webkit ? CKEDITOR.TRISTATE_OFF : stateFromNamedCommand( 'Paste', this ) );
     308        }
     309
    284310        // Register the plugin.
    285311        CKEDITOR.plugins.add( 'clipboard',
    286312                {
     
    348374                                editor.on( 'contentDom', function()
    349375                                {
    350376                                        var body = editor.document.getBody();
    351                                         body.on( ( (mode == 'text' && CKEDITOR.env.ie ) || CKEDITOR.env.webkit ) ? 'paste' : 'beforepaste',
     377                                        body.on( ( ( mode == 'text' && CKEDITOR.env.ie ) || CKEDITOR.env.webkit ) ? 'paste' : 'beforepaste',
    352378                                                function( evt )
    353379                                                {
    354380                                                        if ( depressBeforeEvent )
     
    368394                                                });
    369395
    370396                                        body.on( 'beforecut', function() { !depressBeforeEvent && fixCut( editor ); } );
     397
     398                                        body.on( 'mouseup', setToolbarStates, editor );
     399                                        editor.on( 'key', setToolbarStates, editor );
    371400                                });
    372401
     402                                // For improved performance, we're checking the readOnly state on selectionChange instead of hooking a key event for that.
     403                                editor.on( 'selectionChange', function( evt )
     404                                {
     405                                        inReadOnly = evt.data.selection.getCommonAncestor().isReadOnly();
     406                                });
     407
    373408                                // If the "contextmenu" plugin is loaded, register the listeners.
    374409                                if ( editor.contextMenu )
    375410                                {
    376                                         var depressBeforeEvent;
    377                                         function stateFromNamedCommand( command )
    378                                         {
    379                                                 // IE Bug: queryCommandEnabled('paste') fires also 'beforepaste(copy/cut)',
    380                                                 // guard to distinguish from the ordinary sources( either
    381                                                 // keyboard paste or execCommand ) (#4874).
    382                                                 CKEDITOR.env.ie && ( depressBeforeEvent = 1 );
    383 
    384                                                 var retval = editor.document.$.queryCommandEnabled( command ) ? CKEDITOR.TRISTATE_OFF : CKEDITOR.TRISTATE_DISABLED;
    385                                                 depressBeforeEvent = 0;
    386                                                 return retval;
    387                                         }
    388 
    389411                                        editor.contextMenu.addListener( function( element, selection )
    390412                                                {
    391413                                                        var readOnly = selection.getCommonAncestor().isReadOnly();
    392414                                                        return {
    393                                                                 cut : !readOnly && stateFromNamedCommand( 'Cut' ),
    394                                                                 copy : stateFromNamedCommand( 'Copy' ),
    395                                                                 paste : !readOnly && ( CKEDITOR.env.webkit ? CKEDITOR.TRISTATE_OFF : stateFromNamedCommand( 'Paste' ) )
     415                                                                cut : !readOnly && stateFromNamedCommand( 'Cut', editor ),
     416                                                                copy : stateFromNamedCommand( 'Copy', editor ),
     417                                                                paste : !readOnly && ( CKEDITOR.env.webkit ? CKEDITOR.TRISTATE_OFF : stateFromNamedCommand( 'Paste', editor ) )
    396418                                                        };
    397419                                                });
    398420                                }
© 2003 – 2022, CKSource sp. z o.o. sp.k. All rights reserved. | Terms of use | Privacy policy