iframeview.js 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. /**
  2. * @license Copyright (c) 2003-2018, CKSource - Frederico Knabben. All rights reserved.
  3. * For licensing, see LICENSE.md.
  4. */
  5. /**
  6. * @module ui/iframe/iframeview
  7. */
  8. import View from '../view';
  9. /**
  10. * The iframe view class.
  11. *
  12. * @extends module:ui/view~View
  13. */
  14. export default class IframeView extends View {
  15. /**
  16. * Creates a new instance of the iframe view.
  17. *
  18. * @param {module:utils/locale~Locale} [locale] The locale instance.
  19. */
  20. constructor( locale ) {
  21. super( locale );
  22. const bind = this.bindTemplate;
  23. this.setTemplate( {
  24. tag: 'iframe',
  25. attributes: {
  26. class: [ 'ck-reset_all' ],
  27. // It seems that we need to allow scripts in order to be able to listen to events.
  28. // TODO: Research that. Perhaps the src must be set?
  29. sandbox: 'allow-same-origin allow-scripts'
  30. },
  31. on: {
  32. load: bind.to( 'loaded' )
  33. }
  34. } );
  35. }
  36. /**
  37. * Renders the iframe's {@link #element} and returns a `Promise` for asynchronous
  38. * child `contentDocument` loading process.
  39. *
  40. * @returns {Promise} A promise which resolves once the iframe `contentDocument` has
  41. * been {@link #event:loaded}.
  42. */
  43. render() {
  44. return new Promise( resolve => {
  45. this.on( 'loaded', resolve );
  46. super.render();
  47. } );
  48. }
  49. }
  50. /**
  51. * Fired when the DOM iframe's `contentDocument` finished loading.
  52. *
  53. * @event loaded
  54. */