X-Git-Url: https://jasonwoof.com/gitweb/?a=blobdiff_plain;f=_source%2Fplugins%2Fpastetext%2Fplugin.js;h=d09f4982e39f8534642ecb08851379cd2da41c37;hb=a272c66d841421f8bf933c16535bdcde1c4649fc;hp=3a1678d6d6746f20aa4258adf61a8d771b5d0392;hpb=ea7e3453c7b0f023b050aca6d9f83ab372860d91;p=ckeditor.git
diff --git a/_source/plugins/pastetext/plugin.js b/_source/plugins/pastetext/plugin.js
index 3a1678d..d09f498 100644
--- a/_source/plugins/pastetext/plugin.js
+++ b/_source/plugins/pastetext/plugin.js
@@ -1,5 +1,5 @@
/*
-Copyright (c) 2003-2009, CKSource - Frederico Knabben. All rights reserved.
+Copyright (c) 2003-2013, CKSource - Frederico Knabben. All rights reserved.
For licensing, see LICENSE.html or http://ckeditor.com/license
*/
@@ -14,15 +14,26 @@ For licensing, see LICENSE.html or http://ckeditor.com/license
{
exec : function( editor )
{
- // We use getClipboardData just to test if the clipboard access has
- // been granted by the user.
- if ( CKEDITOR.getClipboardData() === false || !window.clipboardData )
+ var clipboardText = CKEDITOR.tools.tryThese(
+ function()
+ {
+ var clipboardText = window.clipboardData.getData( 'Text' );
+ if ( !clipboardText )
+ throw 0;
+ return clipboardText;
+ }
+ // Any other approach that's working...
+ );
+
+ if ( !clipboardText ) // Clipboard access privilege is not granted.
{
editor.openDialog( 'pastetext' );
- return;
+ return false;
}
+ else
+ editor.fire( 'paste', { 'text' : clipboardText } );
- editor.insertText( window.clipboardData.getData( 'Text' ) );
+ return true;
}
};
@@ -44,99 +55,44 @@ For licensing, see LICENSE.html or http://ckeditor.com/license
if ( editor.config.forcePasteAsPlainText )
{
- editor.on( 'beforePaste', function( event )
+ // Intercept the default pasting process.
+ editor.on( 'beforeCommandExec', function ( evt )
+ {
+ var mode = evt.data.commandData;
+ // Do NOT overwrite if HTML format is explicitly requested.
+ if ( evt.data.name == 'paste' && mode != 'html' )
{
- if ( editor.mode == "wysiwyg" )
- {
- setTimeout( function() { command.exec(); }, 0 );
- event.cancel();
- }
- },
- null, null, 20 );
- }
- },
- requires : [ 'clipboard' ]
- });
+ editor.execCommand( 'pastetext' );
+ evt.cancel();
+ }
+ }, null, null, 0 );
- var clipboardDiv;
-
- CKEDITOR.getClipboardData = function()
- {
- if ( !CKEDITOR.env.ie )
- return false;
-
- var doc = CKEDITOR.document,
- body = doc.getBody();
-
- if ( !clipboardDiv )
- {
- clipboardDiv = doc.createElement( 'div',
+ editor.on( 'beforePaste', function( evt )
{
- attributes :
- {
- id: 'cke_hiddenDiv'
- },
- styles :
- {
- position : 'absolute',
- visibility : 'hidden',
- overflow : 'hidden',
- width : '1px',
- height : '1px'
- }
+ evt.data.mode = 'text';
});
+ }
- clipboardDiv.setHtml( '' );
-
- clipboardDiv.appendTo( body );
- }
-
- // The "enabled" flag is used to check whether the paste operation has
- // been completed (the onpaste event has been fired).
- var enabled = false;
- var setEnabled = function()
- {
- enabled = true;
- };
-
- body.on( 'paste', setEnabled );
-
- // Create a text range and move it inside the div.
- var textRange = body.$.createTextRange();
- textRange.moveToElementText( clipboardDiv.$ );
-
- // The execCommand in will fire the "onpaste", only if the
- // security settings are enabled.
- textRange.execCommand( 'Paste' );
-
- // Get the DIV html and reset it.
- var html = clipboardDiv.getHtml();
- clipboardDiv.setHtml( '' );
+ editor.on( 'pasteState', function( evt )
+ {
+ editor.getCommand( 'pastetext' ).setState( evt.data );
+ });
+ },
- body.removeListener( 'paste', setEnabled );
+ requires : [ 'clipboard' ]
+ });
- // Return the HTML or false if not enabled.
- return enabled && html;
- };
})();
-CKEDITOR.editor.prototype.insertText = function( text )
-{
- text = CKEDITOR.tools.htmlEncode( text );
-
- // TODO: Replace the following with fill line break processing (see V2).
- text = text.replace( /(?:\r\n)|\n|\r/g, '
' );
-
- this.insertHtml( text );
-};
/**
* Whether to force all pasting operations to insert on plain text into the
* editor, loosing any formatting information possibly available in the source
* text.
+ * Note: paste from word is not affected by this configuration.
+ * @name CKEDITOR.config.forcePasteAsPlainText
* @type Boolean
* @default false
* @example
* config.forcePasteAsPlainText = true;
*/
-CKEDITOR.config.forcePasteAsPlainText = false;