mutationobserver.js 900 B

1234567891011121314151617181920212223242526
  1. /**
  2. * @license Copyright (c) 2003-2020, CKSource - Frederico Knabben. All rights reserved.
  3. * For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-oss-license
  4. */
  5. /* globals console, document */
  6. import View from '../../../src/view/view';
  7. import createViewRoot from '../_utils/createroot';
  8. import { setData } from '../../../src/dev-utils/view';
  9. import { StylesProcessor } from '../../../src/view/stylesmap';
  10. const view = new View( new StylesProcessor() );
  11. const viewDocument = view.document;
  12. createViewRoot( viewDocument );
  13. view.attachDomRoot( document.getElementById( 'editor' ) );
  14. viewDocument.on( 'mutations', ( evt, mutations ) => console.log( mutations ) );
  15. viewDocument.on( 'selectionChange', ( evt, data ) => {
  16. view.change( writer => writer.setSelection( data.newSelection ) );
  17. } );
  18. setData( view,
  19. '<container:p>foo</container:p>' +
  20. '<container:p>bar</container:p>'
  21. );