Akron | 22598cd | 2019-12-09 14:59:03 +0100 | [diff] [blame] | 1 | define(function () { |
| 2 | "use strict"; |
| 3 | return { |
| 4 | create : function (name, src, id) { |
| 5 | return Object.create(this)._init(name, src, id); |
| 6 | }, |
| 7 | |
| 8 | // Initialize service |
| 9 | _init : function (name, src, id) { |
| 10 | if (!name || !src || !id) |
| 11 | throw Error("Service not well defined"); |
| 12 | this.name = name; |
| 13 | this.src = src; |
| 14 | this.id = id; |
| 15 | |
| 16 | // There is no close method defined yet |
| 17 | if (!this.close) { |
| 18 | this.close = function () { |
| 19 | this._closeIframe(); |
| 20 | } |
| 21 | } |
| 22 | |
| 23 | return this; |
| 24 | }, |
| 25 | |
| 26 | /** |
| 27 | * The element of the service as embedded in the panel |
| 28 | */ |
| 29 | load : function () { |
| 30 | if (this._load) |
| 31 | return this._load; |
| 32 | |
| 33 | // Spawn new iframe |
| 34 | let e = document.createElement('iframe'); |
| 35 | e.setAttribute('allowTransparency',"true"); |
| 36 | e.setAttribute('frameborder', 0); |
| 37 | e.setAttribute('sandbox','allow-scripts'); |
| 38 | e.style.height = '0px'; |
| 39 | e.setAttribute('name', this.id); |
| 40 | e.setAttribute('src', this.src); |
| 41 | |
| 42 | this._load = e; |
| 43 | return e; |
| 44 | }, |
| 45 | |
| 46 | // onClose : function () {}, |
| 47 | |
| 48 | /** |
| 49 | * Close the service iframe. |
| 50 | */ |
| 51 | _closeIframe : function () { |
| 52 | var e = this._load; |
| 53 | if (e && e.parentNode) { |
| 54 | e.parentNode.removeChild(e); |
| 55 | }; |
| 56 | this._load = null; |
| 57 | } |
| 58 | }; |
| 59 | }); |