plugin.js 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  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 The "selectall" plugin provides an editor command that
  7. * allows selecting the entire content of editable area.
  8. * This plugin also enables a toolbar button for the feature.
  9. */
  10. ( function() {
  11. CKEDITOR.plugins.add( 'selectall', {
  12. // jscs:disable maximumLineLength
  13. 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%
  14. // jscs:enable maximumLineLength
  15. icons: 'selectall', // %REMOVE_LINE_CORE%
  16. hidpi: true, // %REMOVE_LINE_CORE%
  17. init: function( editor ) {
  18. editor.addCommand( 'selectAll', { modes: { wysiwyg: 1, source: 1 },
  19. exec: function( editor ) {
  20. var editable = editor.editable();
  21. if ( editable.is( 'textarea' ) ) {
  22. var textarea = editable.$;
  23. if ( CKEDITOR.env.ie )
  24. textarea.createTextRange().execCommand( 'SelectAll' );
  25. else {
  26. textarea.selectionStart = 0;
  27. textarea.selectionEnd = textarea.value.length;
  28. }
  29. textarea.focus();
  30. } else {
  31. if ( editable.is( 'body' ) )
  32. editor.document.$.execCommand( 'SelectAll', false, null );
  33. else {
  34. var range = editor.createRange();
  35. range.selectNodeContents( editable );
  36. range.select();
  37. }
  38. // Force triggering selectionChange (#7008)
  39. editor.forceNextSelectionCheck();
  40. editor.selectionChange();
  41. }
  42. },
  43. canUndo: false
  44. } );
  45. editor.ui.addButton && editor.ui.addButton( 'SelectAll', {
  46. label: editor.lang.selectall.toolbar,
  47. command: 'selectAll',
  48. toolbar: 'selection,10'
  49. } );
  50. }
  51. } );
  52. } )();