]>
Commit | Line | Data |
---|---|---|
1 | /**\r | |
2 | * @license Copyright (c) 2003-2016, CKSource - Frederico Knabben. All rights reserved.\r | |
3 | * For licensing, see LICENSE.md or http://ckeditor.com/license\r | |
4 | */\r | |
5 | \r | |
6 | /**\r | |
7 | * @fileOverview Paste as plain text plugin.\r | |
8 | */\r | |
9 | \r | |
10 | ( function() {\r | |
11 | // The pastetext command definition.\r | |
12 | var pasteTextCmd = {\r | |
13 | // Snapshots are done manually by editable.insertXXX methods.\r | |
14 | canUndo: false,\r | |
15 | async: true,\r | |
16 | \r | |
17 | exec: function( editor ) {\r | |
18 | editor.getClipboardData( { title: editor.lang.pastetext.title }, function( data ) {\r | |
19 | // Do not use editor#paste, because it would start from beforePaste event.\r | |
20 | data && editor.fire( 'paste', {\r | |
21 | type: 'text',\r | |
22 | dataValue: data.dataValue,\r | |
23 | method: 'paste',\r | |
24 | dataTransfer: CKEDITOR.plugins.clipboard.initPasteDataTransfer()\r | |
25 | } );\r | |
26 | \r | |
27 | editor.fire( 'afterCommandExec', {\r | |
28 | name: 'pastetext',\r | |
29 | command: pasteTextCmd,\r | |
30 | returnValue: !!data\r | |
31 | } );\r | |
32 | } );\r | |
33 | }\r | |
34 | };\r | |
35 | \r | |
36 | // Register the plugin.\r | |
37 | CKEDITOR.plugins.add( 'pastetext', {\r | |
38 | requires: 'clipboard',\r | |
39 | // jscs:disable maximumLineLength\r | |
40 | lang: 'af,ar,bg,bn,bs,ca,cs,cy,da,de,de-ch,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%\r | |
41 | // jscs:enable maximumLineLength\r | |
42 | icons: 'pastetext,pastetext-rtl', // %REMOVE_LINE_CORE%\r | |
43 | hidpi: true, // %REMOVE_LINE_CORE%\r | |
44 | init: function( editor ) {\r | |
45 | var commandName = 'pastetext';\r | |
46 | \r | |
47 | editor.addCommand( commandName, pasteTextCmd );\r | |
48 | \r | |
49 | editor.ui.addButton && editor.ui.addButton( 'PasteText', {\r | |
50 | label: editor.lang.pastetext.button,\r | |
51 | command: commandName,\r | |
52 | toolbar: 'clipboard,40'\r | |
53 | } );\r | |
54 | \r | |
55 | if ( editor.config.forcePasteAsPlainText ) {\r | |
56 | editor.on( 'beforePaste', function( evt ) {\r | |
57 | // Do NOT overwrite if HTML format is explicitly requested.\r | |
58 | // This allows pastefromword dominates over pastetext.\r | |
59 | if ( evt.data.type != 'html' )\r | |
60 | evt.data.type = 'text';\r | |
61 | } );\r | |
62 | }\r | |
63 | \r | |
64 | editor.on( 'pasteState', function( evt ) {\r | |
65 | editor.getCommand( commandName ).setState( evt.data );\r | |
66 | } );\r | |
67 | }\r | |
68 | } );\r | |
69 | } )();\r | |
70 | \r | |
71 | \r | |
72 | /**\r | |
73 | * Whether to force all pasting operations to insert on plain text into the\r | |
74 | * editor, loosing any formatting information possibly available in the source\r | |
75 | * text.\r | |
76 | *\r | |
77 | * **Note:** paste from word (dialog) is not affected by this configuration.\r | |
78 | *\r | |
79 | * config.forcePasteAsPlainText = true;\r | |
80 | *\r | |
81 | * @cfg {Boolean} [forcePasteAsPlainText=false]\r | |
82 | * @member CKEDITOR.config\r | |
83 | */\r |