X-Git-Url: https://jasonwoof.com/gitweb/?a=blobdiff_plain;f=_source%2Fplugins%2Fclipboard%2Fplugin.js;h=9dc230ebd1e0ff65f43078532fe353dd4b7334a9;hb=e371ddf8abcb89013e20e6d0dd746adec344d0e5;hp=8dbacc6cebd2ec1c4eebb65dbb27b1e23c064018;hpb=c6e377a02b54abc07129d72b632763c727476a15;p=ckeditor.git diff --git a/_source/plugins/clipboard/plugin.js b/_source/plugins/clipboard/plugin.js index 8dbacc6..9dc230e 100644 --- a/_source/plugins/clipboard/plugin.js +++ b/_source/plugins/clipboard/plugin.js @@ -28,7 +28,8 @@ For licensing, see LICENSE.html or http://ckeditor.com/license // the command to execute. body.on( command, onExec ); - doc.$.execCommand( command ); + // IE6/7: document.execCommand has problem to paste into positioned element. + ( CKEDITOR.env.version > 7 ? doc.$ : doc.$.selection.createRange() ) [ 'execCommand' ]( command ); body.removeListener( command, onExec ); @@ -67,6 +68,8 @@ For licensing, see LICENSE.html or http://ckeditor.com/license { exec : function( editor, data ) { + this.type == 'cut' && fixCut( editor ); + var success = tryToCutCopy( editor, this.type ); if ( !success ) @@ -181,29 +184,26 @@ For licensing, see LICENSE.html or http://ckeditor.com/license range = new CKEDITOR.dom.range( doc ); // Create container to paste into - var pastebin = new CKEDITOR.dom.element( mode == 'text' ? 'textarea' : 'div', doc ); + var pastebin = new CKEDITOR.dom.element( mode == 'text' ? 'textarea' : CKEDITOR.env.webkit ? 'body' : 'div', doc ); pastebin.setAttribute( 'id', 'cke_pastebin' ); // Safari requires a filler node inside the div to have the content pasted into it. (#4882) CKEDITOR.env.webkit && pastebin.append( doc.createText( '\xa0' ) ); doc.getBody().append( pastebin ); + pastebin.setStyles( + { + position : 'absolute', + // Position the bin exactly at the position of the selected element + // to avoid any subsequent document scroll. + top : sel.getStartElement().getDocumentPosition().y + 'px', + width : '1px', + height : '1px', + overflow : 'hidden' + }); + // It's definitely a better user experience if we make the paste-bin pretty unnoticed - // by pulling it off the screen, while this hack will make the paste-bin a control type element - // and that become a selection plain later. - if ( !CKEDITOR.env.ie && mode != 'html' ) - { - pastebin.setStyles( - { - position : 'absolute', - left : '-1000px', - // Position the bin exactly at the position of the selected element - // to avoid any subsequent document scroll. - top : sel.getStartElement().getDocumentPosition().y + 'px', - width : '1px', - height : '1px', - overflow : 'hidden' - }); - } + // by pulling it off the screen. + pastebin.setStyle( this.config.contentsLangDirection == 'ltr' ? 'left' : 'right', '-1000px' ); var bms = sel.createBookmarks(); @@ -251,6 +251,36 @@ For licensing, see LICENSE.html or http://ckeditor.com/license }, 0 ); } + // Cutting off control type element in IE standards breaks the selection entirely. (#4881) + function fixCut( editor ) + { + if ( !CKEDITOR.env.ie || editor.document.$.compatMode == 'BackCompat' ) + return; + + var sel = editor.getSelection(); + var control; + if( ( sel.getType() == CKEDITOR.SELECTION_ELEMENT ) && ( control = sel.getSelectedElement() ) ) + { + var range = sel.getRanges()[ 0 ]; + var dummy = editor.document.createText( '' ); + dummy.insertBefore( control ); + range.setStartBefore( dummy ); + range.setEndAfter( control ); + sel.selectRanges( [ range ] ); + + // Clear up the fix if the paste wasn't succeeded. + setTimeout( function() + { + // Element still online? + if ( control.getParent() ) + { + dummy.remove(); + sel.selectElement( control ); + } + }, 0 ); + } + } + // Register the plugin. CKEDITOR.plugins.add( 'clipboard', { @@ -321,7 +351,7 @@ For licensing, see LICENSE.html or http://ckeditor.com/license body.on( ( (mode == 'text' && CKEDITOR.env.ie) || CKEDITOR.env.webkit ) ? 'paste' : 'beforepaste', function( evt ) { - if ( depressBeforePasteEvent ) + if ( depressBeforeEvent ) return; getClipboardData.call( editor, evt, mode, function ( data ) @@ -337,32 +367,32 @@ For licensing, see LICENSE.html or http://ckeditor.com/license } ); }); + body.on( 'beforecut', function() { !depressBeforeEvent && fixCut( editor ); } ); }); // If the "contextmenu" plugin is loaded, register the listeners. if ( editor.contextMenu ) { - var depressBeforePasteEvent; + var depressBeforeEvent; function stateFromNamedCommand( command ) { - // IE Bug: queryCommandEnabled('paste') fires also 'beforepaste', + // 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 && command == 'Paste'&& ( depressBeforePasteEvent = 1 ); + CKEDITOR.env.ie && ( depressBeforeEvent = 1 ); var retval = editor.document.$.queryCommandEnabled( command ) ? CKEDITOR.TRISTATE_OFF : CKEDITOR.TRISTATE_DISABLED; - depressBeforePasteEvent = 0; + depressBeforeEvent = 0; return retval; } - editor.contextMenu.addListener( function() + editor.contextMenu.addListener( function( element, selection ) { + var readOnly = selection.getCommonAncestor().isReadOnly(); return { - cut : stateFromNamedCommand( 'Cut' ), - - // Browser bug: 'Cut' has the correct states for both Copy and Cut. - copy : stateFromNamedCommand( 'Cut' ), - paste : CKEDITOR.env.webkit ? CKEDITOR.TRISTATE_OFF : stateFromNamedCommand( 'Paste' ) + cut : !readOnly && stateFromNamedCommand( 'Cut' ), + copy : stateFromNamedCommand( 'Copy' ), + paste : !readOnly && ( CKEDITOR.env.webkit ? CKEDITOR.TRISTATE_OFF : stateFromNamedCommand( 'Paste' ) ) }; }); }