1.js 1.1 KB

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