multicreator.js 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. /**
  2. * @license Copyright (c) 2003-2016, CKSource - Frederico Knabben. All rights reserved.
  3. * For licensing, see LICENSE.md.
  4. */
  5. 'use strict';
  6. import StandardCreator from '/ckeditor5/creator/standardcreator.js';
  7. import HtmlDataProcessor from '/ckeditor5/engine/dataprocessor/htmldataprocessor.js';
  8. import Editable from '/ckeditor5/editable.js';
  9. import { createEditableUI, createEditorUI } from '/ckeditor5/ui/creator-utils.js';
  10. import BoxedEditorUI from '/ckeditor5/ui/editorui/boxed/boxededitorui.js';
  11. import BoxedEditorUIView from '/ckeditor5/ui/editorui/boxed/boxededitoruiview.js';
  12. import EditableUI from '/ckeditor5/ui/editableui/editableui.js';
  13. import InlineEditableUIView from '/ckeditor5/ui/editableui/inline/inlineeditableuiview.js';
  14. import Model from '/ckeditor5/ui/model.js';
  15. import Toolbar from '/ckeditor5/ui/bindings/toolbar.js';
  16. import ToolbarView from '/ckeditor5/ui/toolbar/toolbarview.js';
  17. import { imitateFeatures, imitateDestroyFeatures } from '/ckeditor5/creator-classic/utils/imitatefeatures.js';
  18. export default class MultiCreator extends StandardCreator {
  19. constructor( editor ) {
  20. super( editor, new HtmlDataProcessor() );
  21. // Engine.
  22. this._createEditables();
  23. // UI.
  24. createEditorUI( editor, BoxedEditorUI, BoxedEditorUIView );
  25. }
  26. create() {
  27. const editor = this.editor;
  28. // Features mock.
  29. imitateFeatures( editor );
  30. // UI.
  31. this._createToolbar();
  32. for ( let editable of editor.editables ) {
  33. editor.ui.add( 'main', createEditableUI( editor, editable, EditableUI, InlineEditableUIView ) );
  34. }
  35. editor.elements.forEach( ( element ) => {
  36. this._replaceElement( element, null );
  37. } );
  38. // Init.
  39. return super.create()
  40. .then( () => editor.ui.init() )
  41. // We'll be able to do that much earlier once the loading will be done to the document model,
  42. // rather than straight to the editable.
  43. .then( () => this.loadDataFromEditorElements() );
  44. }
  45. destroy() {
  46. imitateDestroyFeatures();
  47. this.updateEditorElements();
  48. super.destroy();
  49. this.editor.ui.destroy();
  50. }
  51. _createEditables() {
  52. const editor = this.editor;
  53. editor.elements.forEach( ( editorElement, editableName ) => {
  54. const editable = new Editable( editor, editableName );
  55. editor.editables.add( editable );
  56. editor.document.createRoot( editableName, '$root' );
  57. } );
  58. }
  59. _createToolbar() {
  60. const editor = this.editor;
  61. const toolbarModel = new Model();
  62. const toolbar = new Toolbar( toolbarModel, new ToolbarView( toolbarModel, editor.locale ), editor );
  63. toolbar.addButtons( editor.config.toolbar );
  64. this.editor.ui.add( 'top', toolbar );
  65. }
  66. }