8
0

1.js 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. /**
  2. * @license Copyright (c) 2003-2016, CKSource - Frederico Knabben. All rights reserved.
  3. * For licensing, see LICENSE.md.
  4. */
  5. /* globals console:false, document, window */
  6. import ClassicEditor from '/ckeditor5/editor-classic/classic.js';
  7. import { getData as getModelData } from '/ckeditor5/engine/dev-utils/model.js';
  8. import { getData as getViewData } from '/ckeditor5/engine/dev-utils/view.js';
  9. ClassicEditor.create( document.querySelector( '#editor' ), {
  10. features: [ 'enter', 'typing', 'paragraph' ],
  11. toolbar: []
  12. } )
  13. .then( editor => {
  14. window.editor = editor;
  15. editor.document.schema.allow( { name: '$text', inside: '$root' } );
  16. const editable = editor.ui.editableElement;
  17. document.querySelector( '#nbsp' ).addEventListener( 'click', () => {
  18. editor.document.enqueueChanges( () => {
  19. editor.document.selection.collapseToStart();
  20. editor.document.batch().weakInsert( editor.document.selection.getFirstPosition(), '\u00A0' );
  21. } );
  22. } );
  23. editor.document.on( 'changesDone', () => {
  24. console.clear();
  25. const modelData = getModelData( editor.document, { withoutSelection: true } );
  26. console.log( 'model:', modelData.replace( /\u00A0/g, ' ' ) );
  27. const viewData = getViewData( editor.editing.view, { withoutSelection: true } );
  28. console.log( 'view:', viewData.replace( /\u00A0/g, ' ' ) );
  29. console.log( 'dom:', editable.innerHTML );
  30. console.log( 'editor.getData', editor.getData() );
  31. }, { priority: 'lowest' } );
  32. } )
  33. .catch( err => {
  34. console.error( err.stack );
  35. } );