X-Git-Url: https://jasonwoof.com/gitweb/?p=ckeditor.git;a=blobdiff_plain;f=_source%2Fplugins%2Fclipboard%2Fplugin.js;h=6c21f5512a3454a76c4592a3b6451097edc241b2;hp=a285954cbb48d92e6df795a7360f85a34231f141;hb=6e682412d5cc0dfaedb376482e585bf2989c6863;hpb=2f22c0c38f17e75be5541089076885442aaa2377 diff --git a/_source/plugins/clipboard/plugin.js b/_source/plugins/clipboard/plugin.js index a285954..6c21f55 100644 --- a/_source/plugins/clipboard/plugin.js +++ b/_source/plugins/clipboard/plugin.js @@ -135,9 +135,10 @@ For licensing, see LICENSE.html or http://ckeditor.com/license var body = this.document.getBody(); - // Simulate 'paste' event for Opera/Firefox2. - if ( CKEDITOR.env.opera - || CKEDITOR.env.gecko && CKEDITOR.env.version < 10900 ) + // 1. Opera just misses the "paste" event. + // 2. Firefox's "paste" event comes too late to have the plain + // text paste bin to work. + if ( CKEDITOR.env.opera || CKEDITOR.env.gecko ) body.fire( 'paste' ); return; @@ -228,6 +229,19 @@ For licensing, see LICENSE.html or http://ckeditor.com/license editor.removeListener( 'selectionChange', cancel ); + // IE7: selection must go before removing paste bin. (#8691) + if ( CKEDITOR.env.ie7Compat ) + { + sel.selectBookmarks( bms ); + pastebin.remove(); + } + // Webkit: selection must go after removing paste bin. (#8921) + else + { + pastebin.remove(); + sel.selectBookmarks( bms ); + } + // Grab the HTML contents. // We need to look for a apple style wrapper on webkit it also adds // a div wrapper if you copy/paste the body of the editor. @@ -238,9 +252,6 @@ For licensing, see LICENSE.html or http://ckeditor.com/license && ( bogusSpan.is && bogusSpan.hasClass( 'Apple-style-span' ) ) ? bogusSpan : pastebin ); - // IE7: selection must go before removing paste. (#8691) - sel.selectBookmarks( bms ); - pastebin.remove(); callback( pastebin[ 'get' + ( mode == 'text' ? 'Value' : 'Html' ) ]() ); }, 0 ); } @@ -275,31 +286,50 @@ For licensing, see LICENSE.html or http://ckeditor.com/license } } - var depressBeforeEvent; + var depressBeforeEvent, + inReadOnly; function stateFromNamedCommand( command, editor ) { - // IE Bug: queryCommandEnabled('paste') fires also 'beforepaste(copy/cut)', - // guard to distinguish from the ordinary sources( either - // keyboard paste or execCommand ) (#4874). - CKEDITOR.env.ie && ( depressBeforeEvent = 1 ); + var retval; + + if ( inReadOnly && command in { Paste : 1, Cut : 1 } ) + return CKEDITOR.TRISTATE_DISABLED; - var retval = CKEDITOR.TRISTATE_OFF; - try { retval = editor.document.$.queryCommandEnabled( command ) ? CKEDITOR.TRISTATE_OFF : CKEDITOR.TRISTATE_DISABLED; }catch( er ){} + if ( command == 'Paste' ) + { + // IE Bug: queryCommandEnabled('paste') fires also 'beforepaste(copy/cut)', + // guard to distinguish from the ordinary sources (either + // keyboard paste or execCommand) (#4874). + CKEDITOR.env.ie && ( depressBeforeEvent = 1 ); + try + { + // Always return true for Webkit (which always returns false). + retval = editor.document.$.queryCommandEnabled( command ) || CKEDITOR.env.webkit; + } + catch( er ) {} + depressBeforeEvent = 0; + } + // Cut, Copy - check if the selection is not empty + else + { + var sel = editor.getSelection(), + ranges = sel && sel.getRanges(); + retval = sel && !( ranges.length == 1 && ranges[ 0 ].collapsed ); + } - depressBeforeEvent = 0; - return retval; + return retval ? CKEDITOR.TRISTATE_OFF : CKEDITOR.TRISTATE_DISABLED; } - var inReadOnly; function setToolbarStates() { if ( this.mode != 'wysiwyg' ) return; - this.getCommand( 'cut' ).setState( inReadOnly ? CKEDITOR.TRISTATE_DISABLED : stateFromNamedCommand( 'Cut', this ) ); + var pasteState = stateFromNamedCommand( 'Paste', this ); + + this.getCommand( 'cut' ).setState( stateFromNamedCommand( 'Cut', this ) ); this.getCommand( 'copy' ).setState( stateFromNamedCommand( 'Copy', this ) ); - var pasteState = inReadOnly ? CKEDITOR.TRISTATE_DISABLED : - CKEDITOR.env.webkit ? CKEDITOR.TRISTATE_OFF : stateFromNamedCommand( 'Paste', this ); + this.getCommand( 'paste' ).setState( pasteState ); this.fire( 'pasteState', pasteState ); } @@ -451,9 +481,9 @@ For licensing, see LICENSE.html or http://ckeditor.com/license { var readOnly = selection.getRanges()[ 0 ].checkReadOnly(); return { - cut : !readOnly && stateFromNamedCommand( 'Cut', editor ), + cut : stateFromNamedCommand( 'Cut', editor ), copy : stateFromNamedCommand( 'Copy', editor ), - paste : !readOnly && ( CKEDITOR.env.webkit ? CKEDITOR.TRISTATE_OFF : stateFromNamedCommand( 'Paste', editor ) ) + paste : stateFromNamedCommand( 'Paste', editor ) }; }); }