plugin.js 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  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. * @fileOverview Paste as plain text plugin.
  7. */
  8. ( function() {
  9. // The pastetext command definition.
  10. var pasteTextCmd = {
  11. // Snapshots are done manually by editable.insertXXX methods.
  12. canUndo: false,
  13. async: true,
  14. exec: function( editor ) {
  15. editor.getClipboardData( { title: editor.lang.pastetext.title }, function( data ) {
  16. // Do not use editor#paste, because it would start from beforePaste event.
  17. data && editor.fire( 'paste', {
  18. type: 'text',
  19. dataValue: data.dataValue,
  20. method: 'paste',
  21. dataTransfer: CKEDITOR.plugins.clipboard.initPasteDataTransfer()
  22. } );
  23. editor.fire( 'afterCommandExec', {
  24. name: 'pastetext',
  25. command: pasteTextCmd,
  26. returnValue: !!data
  27. } );
  28. } );
  29. }
  30. };
  31. // Register the plugin.
  32. CKEDITOR.plugins.add( 'pastetext', {
  33. requires: 'clipboard',
  34. // jscs:disable maximumLineLength
  35. 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%
  36. // jscs:enable maximumLineLength
  37. icons: 'pastetext,pastetext-rtl', // %REMOVE_LINE_CORE%
  38. hidpi: true, // %REMOVE_LINE_CORE%
  39. init: function( editor ) {
  40. var commandName = 'pastetext';
  41. editor.addCommand( commandName, pasteTextCmd );
  42. editor.ui.addButton && editor.ui.addButton( 'PasteText', {
  43. label: editor.lang.pastetext.button,
  44. command: commandName,
  45. toolbar: 'clipboard,40'
  46. } );
  47. if ( editor.config.forcePasteAsPlainText ) {
  48. editor.on( 'beforePaste', function( evt ) {
  49. // Do NOT overwrite if HTML format is explicitly requested.
  50. // This allows pastefromword dominates over pastetext.
  51. if ( evt.data.type != 'html' )
  52. evt.data.type = 'text';
  53. } );
  54. }
  55. editor.on( 'pasteState', function( evt ) {
  56. editor.getCommand( commandName ).setState( evt.data );
  57. } );
  58. }
  59. } );
  60. } )();
  61. /**
  62. * Whether to force all pasting operations to insert on plain text into the
  63. * editor, loosing any formatting information possibly available in the source
  64. * text.
  65. *
  66. * **Note:** paste from word (dialog) is not affected by this configuration.
  67. *
  68. * config.forcePasteAsPlainText = true;
  69. *
  70. * @cfg {Boolean} [forcePasteAsPlainText=false]
  71. * @member CKEDITOR.config
  72. */