diff options
Diffstat (limited to 'sources/plugins/pastetext/plugin.js')
-rw-r--r-- | sources/plugins/pastetext/plugin.js | 83 |
1 files changed, 83 insertions, 0 deletions
diff --git a/sources/plugins/pastetext/plugin.js b/sources/plugins/pastetext/plugin.js new file mode 100644 index 00000000..0c410e31 --- /dev/null +++ b/sources/plugins/pastetext/plugin.js | |||
@@ -0,0 +1,83 @@ | |||
1 | /** | ||
2 | * @license Copyright (c) 2003-2015, CKSource - Frederico Knabben. All rights reserved. | ||
3 | * For licensing, see LICENSE.md or http://ckeditor.com/license | ||
4 | */ | ||
5 | |||
6 | /** | ||
7 | * @fileOverview Paste as plain text plugin. | ||
8 | */ | ||
9 | |||
10 | ( function() { | ||
11 | // The pastetext command definition. | ||
12 | var pasteTextCmd = { | ||
13 | // Snapshots are done manually by editable.insertXXX methods. | ||
14 | canUndo: false, | ||
15 | async: true, | ||
16 | |||
17 | exec: function( editor ) { | ||
18 | editor.getClipboardData( { title: editor.lang.pastetext.title }, function( data ) { | ||
19 | // Do not use editor#paste, because it would start from beforePaste event. | ||
20 | data && editor.fire( 'paste', { | ||
21 | type: 'text', | ||
22 | dataValue: data.dataValue, | ||
23 | method: 'paste', | ||
24 | dataTransfer: CKEDITOR.plugins.clipboard.initPasteDataTransfer() | ||
25 | } ); | ||
26 | |||
27 | editor.fire( 'afterCommandExec', { | ||
28 | name: 'pastetext', | ||
29 | command: pasteTextCmd, | ||
30 | returnValue: !!data | ||
31 | } ); | ||
32 | } ); | ||
33 | } | ||
34 | }; | ||
35 | |||
36 | // Register the plugin. | ||
37 | CKEDITOR.plugins.add( 'pastetext', { | ||
38 | requires: 'clipboard', | ||
39 | // jscs:disable maximumLineLength | ||
40 | lang: 'af,ar,bg,bn,bs,ca,cs,cy,da,de,el,en,en-au,en-ca,en-gb,eo,es,et,eu,fa,fi,fo,fr,fr-ca,gl,gu,he,hi,hr,hu,id,is,it,ja,ka,km,ko,ku,lt,lv,mk,mn,ms,nb,nl,no,pl,pt,pt-br,ro,ru,si,sk,sl,sq,sr,sr-latn,sv,th,tr,tt,ug,uk,vi,zh,zh-cn', // %REMOVE_LINE_CORE% | ||
41 | // jscs:enable maximumLineLength | ||
42 | icons: 'pastetext,pastetext-rtl', // %REMOVE_LINE_CORE% | ||
43 | hidpi: true, // %REMOVE_LINE_CORE% | ||
44 | init: function( editor ) { | ||
45 | var commandName = 'pastetext'; | ||
46 | |||
47 | editor.addCommand( commandName, pasteTextCmd ); | ||
48 | |||
49 | editor.ui.addButton && editor.ui.addButton( 'PasteText', { | ||
50 | label: editor.lang.pastetext.button, | ||
51 | command: commandName, | ||
52 | toolbar: 'clipboard,40' | ||
53 | } ); | ||
54 | |||
55 | if ( editor.config.forcePasteAsPlainText ) { | ||
56 | editor.on( 'beforePaste', function( evt ) { | ||
57 | // Do NOT overwrite if HTML format is explicitly requested. | ||
58 | // This allows pastefromword dominates over pastetext. | ||
59 | if ( evt.data.type != 'html' ) | ||
60 | evt.data.type = 'text'; | ||
61 | } ); | ||
62 | } | ||
63 | |||
64 | editor.on( 'pasteState', function( evt ) { | ||
65 | editor.getCommand( commandName ).setState( evt.data ); | ||
66 | } ); | ||
67 | } | ||
68 | } ); | ||
69 | } )(); | ||
70 | |||
71 | |||
72 | /** | ||
73 | * Whether to force all pasting operations to insert on plain text into the | ||
74 | * editor, loosing any formatting information possibly available in the source | ||
75 | * text. | ||
76 | * | ||
77 | * **Note:** paste from word (dialog) is not affected by this configuration. | ||
78 | * | ||
79 | * config.forcePasteAsPlainText = true; | ||
80 | * | ||
81 | * @cfg {Boolean} [forcePasteAsPlainText=false] | ||
82 | * @member CKEDITOR.config | ||
83 | */ | ||