1.js 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637
  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/classiceditor';
  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
  13. .create( document.querySelector( '#editor' ), {
  14. plugins: [ Enter, Typing, Paragraph, Bold, Italic ],
  15. toolbar: [ 'bold', 'italic' ]
  16. } )
  17. .then( editor => {
  18. window.editor = editor;
  19. setInterval( () => {
  20. console.clear();
  21. const domSelection = document.getSelection();
  22. const selectionExists = domSelection && domSelection.anchorNode;
  23. console.log( editor.editing.view.getDomRoot().innerHTML.replace( /\u200b/g, '@' ) );
  24. console.log( 'selection.hasAttribute( italic ):', editor.document.selection.hasAttribute( 'italic' ) );
  25. console.log( 'selection.hasAttribute( bold ):', editor.document.selection.hasAttribute( 'bold' ) );
  26. console.log( 'selection anchor\'s parentNode:', selectionExists ? domSelection.anchorNode.parentNode : 'no DOM selection' );
  27. }, 2000 );
  28. } )
  29. .catch( err => {
  30. console.error( err.stack );
  31. } );