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