+ // 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