twostepscarret.js 1.1 KB

1234567891011121314151617181920212223242526272829303132
  1. /**
  2. * @license Copyright (c) 2003-2018, CKSource - Frederico Knabben. All rights reserved.
  3. * For licensing, see LICENSE.md.
  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 LinkEngine from '@ckeditor/ckeditor5-link/src/linkengine';
  10. import Bold from '@ckeditor/ckeditor5-basic-styles/src/bold';
  11. import bindTwoStepCaretToAttribute from '@ckeditor/ckeditor5-engine/src/utils/bindtwostepcarettoattribute';
  12. ClassicEditor
  13. .create( document.querySelector( '#editor' ), {
  14. plugins: [ Essentials, Paragraph, LinkEngine, Bold ],
  15. toolbar: [ 'undo', 'redo', 'bold' ]
  16. } )
  17. .then( editor => {
  18. const selection = editor.model.document.selection;
  19. bindTwoStepCaretToAttribute( editor, editor, 'linkHref' );
  20. selection.on( 'change', () => {
  21. document.querySelector( '.status-box' ).classList.toggle( 'active', selection.hasAttribute( 'linkHref' ) );
  22. } );
  23. } )
  24. .catch( err => {
  25. console.error( err.stack );
  26. } );