classictesteditor.js 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  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 StandardEditor from '/ckeditor5/editor/standardeditor.js';
  7. import HtmlDataProcessor from '/ckeditor5/engine/dataprocessor/htmldataprocessor.js';
  8. import BoxedEditorUI from '/ckeditor5/ui/editorui/boxed/boxededitorui.js';
  9. import BoxedEditorUIView from '/ckeditor5/ui/editorui/boxed/boxededitoruiview.js';
  10. /**
  11. * A simplified classic editor. Useful for testing features.
  12. *
  13. * @memberOf tests.ckeditor5._utils
  14. * @extends ckeditor5.editor.StandardEditor
  15. */
  16. export default class ClassicTestEditor extends StandardEditor {
  17. /**
  18. * @inheritDoc
  19. */
  20. constructor( element, config ) {
  21. super( element, config );
  22. const editableElement = document.createElement( 'div' );
  23. document.body.appendChild( editableElement );
  24. this.document.createRoot();
  25. this.editing.createRoot( editableElement );
  26. this.data.processor = new HtmlDataProcessor();
  27. }
  28. /**
  29. * @inheritDoc
  30. */
  31. destroy() {
  32. return this.ui.destroy()
  33. .then( () => super.destroy() );
  34. }
  35. /**
  36. * @inheritDoc
  37. */
  38. static create( element, config ) {
  39. return new Promise( ( resolve ) => {
  40. const editor = new this( element, config );
  41. resolve(
  42. editor._createUI()
  43. .then( () => editor.initPlugins() )
  44. .then( () => editor._initUI() )
  45. .then( () => editor.loadDataFromEditorElement() )
  46. .then( () => editor )
  47. );
  48. } );
  49. }
  50. /**
  51. * Creates boxed editor UI.
  52. *
  53. * @returns {Promise}
  54. */
  55. _createUI() {
  56. const editorUI = new BoxedEditorUI( this );
  57. const editorUIView = new BoxedEditorUIView( editorUI.viewModel, this.locale );
  58. editorUI.view = editorUIView;
  59. this.ui = editorUI;
  60. return Promise.resolve();
  61. }
  62. /**
  63. * Initilizes editor UI.
  64. *
  65. * @returns {Promise}
  66. */
  67. _initUI() {
  68. return this.ui.init();
  69. }
  70. }