framededitableuiiframeview.js 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  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 IframeView from '/ckeditor5/ui/iframe/iframeview.js';
  7. import FramedEditableUIView from './framededitableuiview.js';
  8. /**
  9. * The basic implementation of an {@link ui.iframe.IframeView IframeView}-based
  10. * {@link ui.editableUI.EditableUIView}.
  11. *
  12. * @memberOf ui.editableUI.iframe
  13. * @extends ui.iframe.IframeView
  14. */
  15. export default class FramedEditableUIIframeView extends IframeView {
  16. /**
  17. * Creates a new instance of the {@link ui.iframe.IframeView IframeView}–based
  18. * {@link ui.editableUI.EditableUIView EditableUIView}.
  19. *
  20. * @param {utils.Observable} [model] (View)Model of this View.
  21. * @param {utils.Locale} [locale] The {@link ckeditor5.Editor#locale editor's locale} instance.
  22. */
  23. constructor( model, locale ) {
  24. super( model, locale );
  25. this.template.attributes.class.push( 'ck-framededitable' );
  26. this.on( 'loaded', this._iframeLoaded, this );
  27. /**
  28. * A view which represents the editable `<body>` element within the iframe.
  29. *
  30. * @private
  31. * @member {FramedEditableUIView} ui.editableUI.iframe#_innerView
  32. */
  33. }
  34. /**
  35. * This getter exposes the {@link ui.editable.EditableUIView#editableElement}. It points to the
  36. * `<body>` inside the `<iframe>` document, which is provided by `FramedEditableUIView`.
  37. */
  38. get editableElement() {
  39. return this._innerView.editableElement;
  40. }
  41. /**
  42. * Destroys the View instance and child {@link _innerView}.
  43. */
  44. destroy() {
  45. super.destroy();
  46. return this._innerView.destroy();
  47. }
  48. /**
  49. * When the iframe is loaded, it creates a child view out of <body> element
  50. * and initializes it. Element of this view is exposed through {@link editableElement}.
  51. *
  52. * @protected
  53. */
  54. _iframeLoaded() {
  55. this._innerView = new FramedEditableUIView(
  56. this.model,
  57. this.locale,
  58. this.element.contentDocument.body
  59. );
  60. this._innerView.init();
  61. this._iframeDeferred.resolve();
  62. }
  63. }