two-step-caret.js 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. /**
  2. * @license Copyright (c) 2003-2020, CKSource - Frederico Knabben. All rights reserved.
  3. * For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-oss-license
  4. */
  5. /* global console, document */
  6. import ClassicEditor from '@ckeditor/ckeditor5-editor-classic/src/classiceditor';
  7. import Essentials from '@ckeditor/ckeditor5-essentials/src/essentials';
  8. import Paragraph from '@ckeditor/ckeditor5-paragraph/src/paragraph';
  9. import Underline from '@ckeditor/ckeditor5-basic-styles/src/underline';
  10. import Bold from '@ckeditor/ckeditor5-basic-styles/src/bold';
  11. import Italic from '@ckeditor/ckeditor5-basic-styles/src/italic';
  12. import bindTwoStepCaretToAttribute from '../../src/utils/bindtwostepcarettoattribute';
  13. ClassicEditor
  14. .create( document.querySelector( '#editor-ltr' ), {
  15. plugins: [ Essentials, Paragraph, Underline, Bold, Italic ],
  16. toolbar: [ 'undo', 'redo', '|', 'bold', 'underline', 'italic' ]
  17. } )
  18. .then( editor => {
  19. const bold = editor.plugins.get( Italic );
  20. const underline = editor.plugins.get( Underline );
  21. bindTwoStepCaretToAttribute( {
  22. view: editor.editing.view,
  23. model: editor.model,
  24. emitter: bold,
  25. attribute: 'italic',
  26. locale: editor.locale
  27. } );
  28. bindTwoStepCaretToAttribute( {
  29. view: editor.editing.view,
  30. model: editor.model,
  31. emitter: underline,
  32. attribute: 'underline',
  33. locale: editor.locale
  34. } );
  35. } )
  36. .catch( err => {
  37. console.error( err.stack );
  38. } );
  39. ClassicEditor
  40. .create( document.querySelector( '#editor-rtl' ), {
  41. language: {
  42. content: 'he'
  43. },
  44. plugins: [ Essentials, Paragraph, Underline, Bold, Italic ],
  45. toolbar: [ 'undo', 'redo', '|', 'bold', 'underline', 'italic' ]
  46. } )
  47. .then( editor => {
  48. const bold = editor.plugins.get( Italic );
  49. const underline = editor.plugins.get( Underline );
  50. bindTwoStepCaretToAttribute( {
  51. view: editor.editing.view,
  52. model: editor.model,
  53. emitter: bold,
  54. attribute: 'italic',
  55. locale: editor.locale
  56. } );
  57. bindTwoStepCaretToAttribute( {
  58. view: editor.editing.view,
  59. model: editor.model,
  60. emitter: underline,
  61. attribute: 'underline',
  62. locale: editor.locale
  63. } );
  64. } )
  65. .catch( err => {
  66. console.error( err.stack );
  67. } );