2 Copyright (c) 2003-2011, CKSource - Frederico Knabben. All rights reserved.
3 For licensing, see LICENSE.html or http://ckeditor.com/license
7 * @file Paste as plain text plugin
12 // The pastetext command definition.
15 exec : function( editor )
17 var clipboardText = CKEDITOR.tools.tryThese(
20 var clipboardText = window.clipboardData.getData( 'Text' );
25 // Any other approach that's working...
28 if ( !clipboardText ) // Clipboard access privilege is not granted.
30 editor.openDialog( 'pastetext' );
34 editor.fire( 'paste', { 'text' : clipboardText } );
40 // Register the plugin.
41 CKEDITOR.plugins.add( 'pastetext',
43 init : function( editor )
45 var commandName = 'pastetext',
46 command = editor.addCommand( commandName, pasteTextCmd );
48 editor.ui.addButton( 'PasteText',
50 label : editor.lang.pasteText.button,
54 CKEDITOR.dialog.add( commandName, CKEDITOR.getUrl( this.path + 'dialogs/pastetext.js' ) );
56 if ( editor.config.forcePasteAsPlainText )
58 // Intercept the default pasting process.
59 editor.on( 'beforeCommandExec', function ( evt )
61 var mode = evt.data.commandData;
62 // Do NOT overwrite if HTML format is explicitly requested.
63 if ( evt.data.name == 'paste' && mode != 'html' )
65 editor.execCommand( 'pastetext' );
70 editor.on( 'beforePaste', function( evt )
72 evt.data.mode = 'text';
76 editor.on( 'pasteState', function( evt )
78 editor.getCommand( 'pastetext' ).setState( evt.data );
82 requires : [ 'clipboard' ]
89 * Whether to force all pasting operations to insert on plain text into the
90 * editor, loosing any formatting information possibly available in the source
92 * <strong>Note:</strong> paste from word is not affected by this configuration.
93 * @name CKEDITOR.config.forcePasteAsPlainText
97 * config.forcePasteAsPlainText = true;