+ function cancel( evt ) { evt.cancel(); }\r
+\r
+ // Allow to peek clipboard content by redirecting the\r
+ // pasting content into a temporary bin and grab the content of it.\r
+ function getClipboardData( evt, mode, callback )\r
+ {\r
+ var doc = this.document;\r
+\r
+ // Avoid recursions on 'paste' event or consequent paste too fast. (#5730)\r
+ if ( doc.getById( 'cke_pastebin' ) )\r
+ return;\r
+\r
+ // If the browser supports it, get the data directly\r
+ if ( mode == 'text' && evt.data && evt.data.$.clipboardData )\r
+ {\r
+ // evt.data.$.clipboardData.types contains all the flavours in Mac's Safari, but not on windows.\r
+ var plain = evt.data.$.clipboardData.getData( 'text/plain' );\r
+ if ( plain )\r
+ {\r
+ evt.data.preventDefault();\r
+ callback( plain );\r
+ return;\r
+ }\r
+ }\r
+\r
+ var sel = this.getSelection(),\r
+ range = new CKEDITOR.dom.range( doc );\r
+\r
+ // Create container to paste into\r
+ var pastebin = new CKEDITOR.dom.element( mode == 'text' ? 'textarea' : CKEDITOR.env.webkit ? 'body' : 'div', doc );\r
+ pastebin.setAttribute( 'id', 'cke_pastebin' );\r
+ // Safari requires a filler node inside the div to have the content pasted into it. (#4882)\r
+ CKEDITOR.env.webkit && pastebin.append( doc.createText( '\xa0' ) );\r
+ doc.getBody().append( pastebin );\r
+\r
+ pastebin.setStyles(\r
+ {\r
+ position : 'absolute',\r
+ // Position the bin exactly at the position of the selected element\r
+ // to avoid any subsequent document scroll.\r
+ top : sel.getStartElement().getDocumentPosition().y + 'px',\r
+ width : '1px',\r
+ height : '1px',\r
+ overflow : 'hidden'\r
+ });\r
+\r
+ // It's definitely a better user experience if we make the paste-bin pretty unnoticed\r
+ // by pulling it off the screen.\r
+ pastebin.setStyle( this.config.contentsLangDirection == 'ltr' ? 'left' : 'right', '-1000px' );\r
+\r
+ var bms = sel.createBookmarks();\r
+\r
+ this.on( 'selectionChange', cancel, null, null, 0 );\r
+\r
+ // Turn off design mode temporarily before give focus to the paste bin.\r
+ if ( mode == 'text' )\r
+ pastebin.$.focus();\r
+ else\r
+ {\r
+ range.setStartAt( pastebin, CKEDITOR.POSITION_AFTER_START );\r
+ range.setEndAt( pastebin, CKEDITOR.POSITION_BEFORE_END );\r
+ range.select( true );\r
+ }\r
+\r
+ var editor = this;\r
+ // Wait a while and grab the pasted contents\r
+ window.setTimeout( function()\r
+ {\r
+ // Restore properly the document focus. (#5684, #8849)\r
+ editor.document.getBody().focus();\r
+\r
+ editor.removeListener( 'selectionChange', cancel );\r
+\r
+ // IE7: selection must go before removing paste bin. (#8691)\r
+ if ( CKEDITOR.env.ie7Compat )\r
+ {\r
+ sel.selectBookmarks( bms );\r
+ pastebin.remove();\r
+ }\r
+ // Webkit: selection must go after removing paste bin. (#8921)\r
+ else\r
+ {\r
+ pastebin.remove();\r
+ sel.selectBookmarks( bms );\r
+ }\r
+\r
+ // Grab the HTML contents.\r
+ // We need to look for a apple style wrapper on webkit it also adds\r
+ // a div wrapper if you copy/paste the body of the editor.\r
+ // Remove hidden div and restore selection.\r
+ var bogusSpan;\r
+ pastebin = ( CKEDITOR.env.webkit\r
+ && ( bogusSpan = pastebin.getFirst() )\r
+ && ( bogusSpan.is && bogusSpan.hasClass( 'Apple-style-span' ) ) ?\r
+ bogusSpan : pastebin );\r
+\r
+ callback( pastebin[ 'get' + ( mode == 'text' ? 'Value' : 'Html' ) ]() );\r
+ }, 0 );\r
+ }\r
+\r
+ // Cutting off control type element in IE standards breaks the selection entirely. (#4881)\r
+ function fixCut( editor )\r
+ {\r
+ if ( !CKEDITOR.env.ie || CKEDITOR.env.quirks )\r
+ return;\r
+\r
+ var sel = editor.getSelection();\r
+ var control;\r
+ if( ( sel.getType() == CKEDITOR.SELECTION_ELEMENT ) && ( control = sel.getSelectedElement() ) )\r
+ {\r
+ var range = sel.getRanges()[ 0 ];\r
+ var dummy = editor.document.createText( '' );\r
+ dummy.insertBefore( control );\r
+ range.setStartBefore( dummy );\r
+ range.setEndAfter( control );\r
+ sel.selectRanges( [ range ] );\r
+\r
+ // Clear up the fix if the paste wasn't succeeded.\r
+ setTimeout( function()\r
+ {\r
+ // Element still online?\r
+ if ( control.getParent() )\r
+ {\r
+ dummy.remove();\r
+ sel.selectElement( control );\r
+ }\r
+ }, 0 );\r
+ }\r
+ }\r
+\r
+ var depressBeforeEvent,\r
+ inReadOnly;\r
+ function stateFromNamedCommand( command, editor )\r
+ {\r
+ var retval;\r
+\r
+ if ( inReadOnly && command in { Paste : 1, Cut : 1 } )\r
+ return CKEDITOR.TRISTATE_DISABLED;\r
+\r
+ if ( command == 'Paste' )\r
+ {\r
+ // IE Bug: queryCommandEnabled('paste') fires also 'beforepaste(copy/cut)',\r
+ // guard to distinguish from the ordinary sources (either\r
+ // keyboard paste or execCommand) (#4874).\r
+ CKEDITOR.env.ie && ( depressBeforeEvent = 1 );\r
+ try\r
+ {\r
+ // Always return true for Webkit (which always returns false).\r
+ retval = editor.document.$.queryCommandEnabled( command ) || CKEDITOR.env.webkit;\r
+ }\r
+ catch( er ) {}\r
+ depressBeforeEvent = 0;\r
+ }\r
+ // Cut, Copy - check if the selection is not empty\r
+ else\r
+ {\r
+ var sel = editor.getSelection(),\r
+ ranges = sel && sel.getRanges();\r
+ retval = sel && !( ranges.length == 1 && ranges[ 0 ].collapsed );\r
+ }\r
+\r
+ return retval ? CKEDITOR.TRISTATE_OFF : CKEDITOR.TRISTATE_DISABLED;\r
+ }\r
+\r
+ function setToolbarStates()\r
+ {\r
+ if ( this.mode != 'wysiwyg' )\r
+ return;\r
+\r
+ var pasteState = stateFromNamedCommand( 'Paste', this );\r
+\r
+ this.getCommand( 'cut' ).setState( stateFromNamedCommand( 'Cut', this ) );\r
+ this.getCommand( 'copy' ).setState( stateFromNamedCommand( 'Copy', this ) );\r
+ this.getCommand( 'paste' ).setState( pasteState );\r
+ this.fire( 'pasteState', pasteState );\r
+ }\r
+\r