legacycreator.js 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  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 FramedEditableUIIframe from '/tests/ckeditor5/_utils/ui/editableui/framed/framededitableuiiframe.js';
  13. import FramedEditableUIIframeView from '/tests/ckeditor5/_utils/ui/editableui/framed/framededitableuiiframeview.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 LegacyCreator extends StandardCreator {
  19. constructor( editor ) {
  20. super( editor, new HtmlDataProcessor() );
  21. const editableName = editor.firstElementName;
  22. editor.editables.add( new Editable( editor, editableName ) );
  23. editor.document.createRoot( editableName, '$root' );
  24. // UI.
  25. createEditorUI( editor, BoxedEditorUI, BoxedEditorUIView );
  26. }
  27. create() {
  28. const editor = this.editor;
  29. const editable = editor.editables.get( 0 );
  30. // Features mock.
  31. imitateFeatures( editor );
  32. // UI.
  33. this._replaceElement( editor.firstElement, editor.ui.view.element );
  34. this._createToolbar();
  35. editor.ui.add( 'main', createEditableUI( editor, editable, FramedEditableUIIframe, FramedEditableUIIframeView ) );
  36. // Init.
  37. return super.create()
  38. .then( () => editor.ui.init() )
  39. // We'll be able to do that much earlier once the loading will be done to the document model,
  40. // rather than straight to the editable.
  41. .then( () => this.loadDataFromEditorElement() );
  42. }
  43. destroy() {
  44. imitateDestroyFeatures();
  45. this.updateEditorElement();
  46. super.destroy();
  47. return this.editor.ui.destroy();
  48. }
  49. _createToolbar() {
  50. const editor = this.editor;
  51. const toolbarModel = new Model();
  52. const toolbar = new Toolbar( toolbarModel, new ToolbarView( toolbarModel, editor.locale ), editor );
  53. toolbar.addButtons( editor.config.toolbar );
  54. this.editor.ui.add( 'top', toolbar );
  55. }
  56. }