1.js 1.4 KB

123456789101112131415161718192021222324252627282930313233343536
  1. /**
  2. * @license Copyright (c) 2003-2017, CKSource - Frederico Knabben. All rights reserved.
  3. * For licensing, see LICENSE.md.
  4. */
  5. /* globals console, window, document, setInterval */
  6. import ClassicEditor from '@ckeditor/ckeditor5-editor-classic/src/classic';
  7. import Enter from '@ckeditor/ckeditor5-enter/src/enter';
  8. import Typing from '@ckeditor/ckeditor5-typing/src/typing';
  9. import Paragraph from '@ckeditor/ckeditor5-paragraph/src/paragraph';
  10. import Bold from '@ckeditor/ckeditor5-basic-styles/src/bold';
  11. import Italic from '@ckeditor/ckeditor5-basic-styles/src/italic';
  12. ClassicEditor.create( document.querySelector( '#editor' ), {
  13. plugins: [ Enter, Typing, Paragraph, Bold, Italic ],
  14. toolbar: [ 'bold', 'italic' ]
  15. } )
  16. .then( editor => {
  17. window.editor = editor;
  18. setInterval( () => {
  19. console.clear();
  20. const domSelection = document.getSelection();
  21. const selectionExists = domSelection && domSelection.anchorNode;
  22. console.log( editor.editing.view.getDomRoot().innerHTML.replace( /\u200b/g, '@' ) );
  23. console.log( 'selection.hasAttribute( italic ):', editor.document.selection.hasAttribute( 'italic' ) );
  24. console.log( 'selection.hasAttribute( bold ):', editor.document.selection.hasAttribute( 'bold' ) );
  25. console.log( 'selection anchor\'s parentNode:', selectionExists ? domSelection.anchorNode.parentNode : 'no DOM selection' );
  26. }, 2000 );
  27. } )
  28. .catch( err => {
  29. console.error( err.stack );
  30. } );