8
0

uielement.js 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. /**
  2. * @license Copyright (c) 2003-2017, CKSource - Frederico Knabben. All rights reserved.
  3. * For licensing, see LICENSE.md.
  4. */
  5. /* global document */
  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 Undo from '@ckeditor/ckeditor5-undo/src/undo';
  11. import Plugin from '@ckeditor/ckeditor5-core/src/plugin';
  12. import UIElement from '../../../src/view/uielement';
  13. class MyUIElement extends UIElement {
  14. render( domDocument ) {
  15. const root = super.render( domDocument );
  16. root.setAttribute( 'contenteditable', 'false' );
  17. root.classList.add( 'ui-element' );
  18. root.innerHTML = '<span>END OF PARAGRAPH</span>';
  19. return root;
  20. }
  21. }
  22. class UIElementTestPlugin extends Plugin {
  23. init() {
  24. const editor = this.editor;
  25. const editing = editor.editing;
  26. // Add some UIElement to each paragraph.
  27. editing.modelToView.on( 'insert:paragraph', ( evt, data, consumable, conversionApi ) => {
  28. const viewP = conversionApi.mapper.toViewElement( data.item );
  29. viewP.appendChildren( new MyUIElement( 'div' ) );
  30. }, { priority: 'lowest' } );
  31. }
  32. }
  33. ClassicEditor.create( document.querySelector( '#editor' ), {
  34. plugins: [ Enter, Typing, Paragraph, Undo, UIElementTestPlugin ],
  35. toolbar: [ 'undo', 'redo' ]
  36. } );