Ticket #8463: 8463.patch

File 8463.patch, 2.9 KB (added by Piotrek Koszuliński, 12 years ago)
  • _source/plugins/clipboard/plugin.js

     
    275275                }
    276276        }
    277277
    278         var depressBeforeEvent;
     278        var depressBeforeEvent,
     279                inReadOnly;
    279280        function stateFromNamedCommand( command, editor )
    280281        {
    281                 // IE Bug: queryCommandEnabled('paste') fires also 'beforepaste(copy/cut)',
    282                 // guard to distinguish from the ordinary sources( either
    283                 // keyboard paste or execCommand ) (#4874).
    284                 CKEDITOR.env.ie && ( depressBeforeEvent = 1 );
     282                var retval;
    285283
    286                 var retval = CKEDITOR.TRISTATE_OFF;
    287                 try { retval = editor.document.$.queryCommandEnabled( command ) ? CKEDITOR.TRISTATE_OFF : CKEDITOR.TRISTATE_DISABLED; }catch( er ){}
     284                if ( inReadOnly && command in { Paste : 1, Cut : 1 } )
     285                        return CKEDITOR.TRISTATE_DISABLED;
    288286
    289                 depressBeforeEvent = 0;
    290                 return retval;
     287                if ( command == 'Paste' )
     288                {
     289                        // IE Bug: queryCommandEnabled('paste') fires also 'beforepaste(copy/cut)',
     290                        // guard to distinguish from the ordinary sources (either
     291                        // keyboard paste or execCommand) (#4874).
     292                        CKEDITOR.env.ie && ( depressBeforeEvent = 1 );
     293                        try
     294                        {
     295                                // Always return true for Webkit (which always returns false).
     296                                retval = editor.document.$.queryCommandEnabled( command ) || CKEDITOR.env.webkit;
     297                        }
     298                        catch( er ) {}
     299                        depressBeforeEvent = 0;
     300                }
     301                // Cut, Copy - check if the selection is not empty
     302                else
     303                {
     304                        var ranges = editor.getSelection().getRanges();
     305                        retval = !( ranges.length == 1 && ranges[ 0 ].collapsed );
     306                }
     307
     308                return retval ? CKEDITOR.TRISTATE_OFF : CKEDITOR.TRISTATE_DISABLED;
    291309        }
    292310
    293         var inReadOnly;
    294311        function setToolbarStates()
    295312        {
    296313                if ( this.mode != 'wysiwyg' )
    297314                        return;
    298315
    299                 this.getCommand( 'cut' ).setState( inReadOnly ? CKEDITOR.TRISTATE_DISABLED : stateFromNamedCommand( 'Cut', this ) );
     316                var pasteState = stateFromNamedCommand( 'Paste', this );
     317
     318                this.getCommand( 'cut' ).setState( stateFromNamedCommand( 'Cut', this ) );
    300319                this.getCommand( 'copy' ).setState( stateFromNamedCommand( 'Copy', this ) );
    301                 var pasteState = inReadOnly ? CKEDITOR.TRISTATE_DISABLED :
    302                                                 CKEDITOR.env.webkit ? CKEDITOR.TRISTATE_OFF : stateFromNamedCommand( 'Paste', this );
     320                this.getCommand( 'paste' ).setState( pasteState );
    303321                this.fire( 'pasteState', pasteState );
    304322        }
    305323
     
    451469                                                {
    452470                                                        var readOnly = selection.getRanges()[ 0 ].checkReadOnly();
    453471                                                        return {
    454                                                                 cut : !readOnly && stateFromNamedCommand( 'Cut', editor ),
     472                                                                cut : stateFromNamedCommand( 'Cut', editor ),
    455473                                                                copy : stateFromNamedCommand( 'Copy', editor ),
    456                                                                 paste : !readOnly && ( CKEDITOR.env.webkit ? CKEDITOR.TRISTATE_OFF : stateFromNamedCommand( 'Paste', editor ) )
     474                                                                paste : stateFromNamedCommand( 'Paste', editor )
    457475                                                        };
    458476                                                });
    459477                                }
© 2003 – 2022, CKSource sp. z o.o. sp.k. All rights reserved. | Terms of use | Privacy policy