Ticket #6020: 6020_5.patch

File 6020_5.patch, 5.2 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                var pasteState = inReadOnly ? CKEDITOR.TRISTATE_DISABLED :
     307                                                CKEDITOR.env.webkit ? CKEDITOR.TRISTATE_OFF : stateFromNamedCommand( 'Paste', this );
     308                this.fire( 'pasteState', pasteState );
     309        }
     310
    284311        // Register the plugin.
    285312        CKEDITOR.plugins.add( 'clipboard',
    286313                {
     
    308335                                                }, 0 );
    309336                                        });
    310337
     338                                editor.on( 'pasteState', function( evt )
     339                                        {
     340                                                editor.getCommand( 'paste' ).setState( evt.data );
     341                                        });
     342
    311343                                function addButtonCommand( buttonName, commandName, command, ctxMenuOrder )
    312344                                {
    313345                                        var lang = editor.lang[ commandName ];
     
    348380                                editor.on( 'contentDom', function()
    349381                                {
    350382                                        var body = editor.document.getBody();
    351                                         body.on( ( (mode == 'text' && CKEDITOR.env.ie ) || CKEDITOR.env.webkit ) ? 'paste' : 'beforepaste',
     383                                        body.on( ( ( mode == 'text' && CKEDITOR.env.ie ) || CKEDITOR.env.webkit ) ? 'paste' : 'beforepaste',
    352384                                                function( evt )
    353385                                                {
    354386                                                        if ( depressBeforeEvent )
     
    368400                                                });
    369401
    370402                                        body.on( 'beforecut', function() { !depressBeforeEvent && fixCut( editor ); } );
     403
     404                                        body.on( 'mouseup', setToolbarStates, editor );
     405                                        body.on( 'keyup', setToolbarStates, editor );
    371406                                });
    372407
     408                                // For improved performance, we're checking the readOnly state on selectionChange instead of hooking a key event for that.
     409                                editor.on( 'selectionChange', function( evt )
     410                                {
     411                                        inReadOnly = evt.data.selection.getCommonAncestor().isReadOnly();
     412                                });
     413
    373414                                // If the "contextmenu" plugin is loaded, register the listeners.
    374415                                if ( editor.contextMenu )
    375416                                {
    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 
    389417                                        editor.contextMenu.addListener( function( element, selection )
    390418                                                {
    391419                                                        var readOnly = selection.getCommonAncestor().isReadOnly();
    392420                                                        return {
    393                                                                 cut : !readOnly && stateFromNamedCommand( 'Cut' ),
    394                                                                 copy : stateFromNamedCommand( 'Copy' ),
    395                                                                 paste : !readOnly && ( CKEDITOR.env.webkit ? CKEDITOR.TRISTATE_OFF : stateFromNamedCommand( 'Paste' ) )
     421                                                                cut : !readOnly && stateFromNamedCommand( 'Cut', editor ),
     422                                                                copy : stateFromNamedCommand( 'Copy', editor ),
     423                                                                paste : !readOnly && ( CKEDITOR.env.webkit ? CKEDITOR.TRISTATE_OFF : stateFromNamedCommand( 'Paste', editor ) )
    396424                                                        };
    397425                                                });
    398426                                }
  • _source/plugins/pastefromword/plugin.js

     
    4747                                        command : 'pastefromword'
    4848                                });
    4949
     50                        editor.on( 'pasteState', function( evt )
     51                                {
     52                                        editor.getCommand( 'pastefromword' ).setState( evt.data );
     53                                });
     54
    5055                        editor.on( 'paste', function( evt )
    5156                        {
    5257                                var data = evt.data,
     
    9398                        }
    9499
    95100                        return !isLoaded;
    96                 }
     101                },
     102
     103                requires : [ 'clipboard' ]
    97104        });
    98105})();
    99106
  • _source/plugins/pastetext/plugin.js

     
    6565                                        }
    6666                                }, null, null, 0 );
    6767                        }
     68
     69                        editor.on( 'pasteState', function( evt )
     70                                {
     71                                        editor.getCommand( 'pastetext' ).setState( evt.data );
     72                                });
    6873                },
    6974
    7075                requires : [ 'clipboard' ]
© 2003 – 2022, CKSource sp. z o.o. sp.k. All rights reserved. | Terms of use | Privacy policy