Ticket #6020: 6020_3.patch

File 6020_3.patch, 3.6 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        }
     307
    284308        // Register the plugin.
    285309        CKEDITOR.plugins.add( 'clipboard',
    286310                {
     
    348372                                editor.on( 'contentDom', function()
    349373                                {
    350374                                        var body = editor.document.getBody();
    351                                         body.on( ( (mode == 'text' && CKEDITOR.env.ie ) || CKEDITOR.env.webkit ) ? 'paste' : 'beforepaste',
     375                                        body.on( ( ( mode == 'text' && CKEDITOR.env.ie ) || CKEDITOR.env.webkit ) ? 'paste' : 'beforepaste',
    352376                                                function( evt )
    353377                                                {
    354378                                                        if ( depressBeforeEvent )
     
    368392                                                });
    369393
    370394                                        body.on( 'beforecut', function() { !depressBeforeEvent && fixCut( editor ); } );
     395
     396                                        body.on( 'mouseup', setToolbarStates, editor );
     397                                        editor.on( 'key', setToolbarStates, editor );
    371398                                });
    372399
     400                                // For improved performance, we're checking the readOnly state on selectionChange instead of hooking a key event for that.
     401                                editor.on( 'selectionChange', function( evt )
     402                                {
     403                                        inReadOnly = evt.data.selection.getCommonAncestor().isReadOnly();
     404                                });
     405
    373406                                // If the "contextmenu" plugin is loaded, register the listeners.
    374407                                if ( editor.contextMenu )
    375408                                {
    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 
    389409                                        editor.contextMenu.addListener( function( element, selection )
    390410                                                {
    391411                                                        var readOnly = selection.getCommonAncestor().isReadOnly();
    392412                                                        return {
    393                                                                 cut : !readOnly && stateFromNamedCommand( 'Cut' ),
    394                                                                 copy : stateFromNamedCommand( 'Copy' ),
    395                                                                 paste : !readOnly && ( CKEDITOR.env.webkit ? CKEDITOR.TRISTATE_OFF : stateFromNamedCommand( 'Paste' ) )
     413                                                                cut : !readOnly && stateFromNamedCommand( 'Cut', editor ),
     414                                                                copy : stateFromNamedCommand( 'Copy', editor ),
     415                                                                paste : !readOnly && ( CKEDITOR.env.webkit ? CKEDITOR.TRISTATE_OFF : stateFromNamedCommand( 'Paste', editor ) )
    396416                                                        };
    397417                                                });
    398418                                }
© 2003 – 2022, CKSource sp. z o.o. sp.k. All rights reserved. | Terms of use | Privacy policy