editoruiview.js 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. /**
  2. * @license Copyright (c) 2003-2017, CKSource - Frederico Knabben. All rights reserved.
  3. * For licensing, see LICENSE.md.
  4. */
  5. /**
  6. * @module ui/editorui/editoruiview
  7. */
  8. /* globals document */
  9. import View from '../view';
  10. import Template from '../template';
  11. /**
  12. * The editor UI view class. Base class for the editor main views.
  13. *
  14. * @extends module:ui/view~View
  15. */
  16. export default class EditorUIView extends View {
  17. /**
  18. * Creates an instance of the editor UI view class.
  19. *
  20. * @param {module:utils/locale~Locale} [locale] The locale instance.
  21. */
  22. constructor( locale ) {
  23. super( locale );
  24. /**
  25. * Collection of the child views, detached from the DOM
  26. * structure of the editor, like panels, icons etc.
  27. *
  28. * @readonly
  29. * @member {module:ui/viewcollection~ViewCollection} #body
  30. */
  31. this.body = this.createCollection();
  32. /**
  33. * The element holding elements of the 'body' region.
  34. *
  35. * @private
  36. * @member {HTMLElement} #_bodyCollectionContainer
  37. */
  38. }
  39. /**
  40. * @inheritDoc
  41. */
  42. init() {
  43. return Promise.resolve()
  44. .then( () => this._renderBodyCollection() )
  45. .then( () => super.init() );
  46. }
  47. /**
  48. * @inheritDoc
  49. */
  50. destroy() {
  51. this._bodyCollectionContainer.remove();
  52. return super.destroy();
  53. }
  54. /**
  55. * Creates and appends to `<body>` the {@link #body} collection container.
  56. *
  57. * @private
  58. */
  59. _renderBodyCollection() {
  60. const bodyElement = this._bodyCollectionContainer = new Template( {
  61. tag: 'div',
  62. attributes: {
  63. class: [
  64. 'ck-body',
  65. 'ck-rounded-corners',
  66. 'ck-reset_all'
  67. ]
  68. },
  69. children: this.body
  70. } ).render();
  71. document.body.appendChild( bodyElement );
  72. }
  73. }