Akron | a6c32b9 | 2018-07-02 18:39:42 +0200 | [diff] [blame] | 1 | /** |
| 2 | * The plugin system is based |
| 3 | * on registered widgets (iframes) from |
| 4 | * foreign services. |
| 5 | * The widget component represents a single iframe. |
| 6 | * |
| 7 | * @author Nils Diewald |
| 8 | */ |
| 9 | |
| 10 | define(["util"], function () { |
| 11 | "use strict"; |
| 12 | |
| 13 | return { |
| 14 | |
| 15 | /** |
| 16 | * Create new widget |
| 17 | */ |
| 18 | create : function (src, id) { |
| 19 | return Object.create(this)._init(src, id); |
| 20 | }, |
| 21 | |
Akron | e8e2c95 | 2018-07-04 13:43:12 +0200 | [diff] [blame] | 22 | // Initialize widget |
Akron | a6c32b9 | 2018-07-02 18:39:42 +0200 | [diff] [blame] | 23 | _init : function (src, id) { |
| 24 | this.src = src; |
| 25 | this.id = id; |
| 26 | return this; |
| 27 | }, |
| 28 | |
| 29 | /** |
| 30 | * The element of the widget |
| 31 | */ |
| 32 | element : function () { |
| 33 | |
| 34 | if (this._element) |
| 35 | return this._element; |
| 36 | |
| 37 | // Spawn new iframe |
| 38 | var i = document.createElement('iframe'); |
| 39 | i.setAttribute('allowTransparency',"true"); |
| 40 | i.setAttribute('frameborder', 0); |
| 41 | i.setAttribute('sandbox','allow-scripts'); |
| 42 | i.classList.add('widget'); |
Akron | e8e2c95 | 2018-07-04 13:43:12 +0200 | [diff] [blame] | 43 | i.style.height = '0px'; |
Akron | a6c32b9 | 2018-07-02 18:39:42 +0200 | [diff] [blame] | 44 | i.setAttribute('name', this.id); |
| 45 | i.setAttribute('src', this.src); |
| 46 | this._element = i; |
| 47 | |
| 48 | return i; |
| 49 | }, |
| 50 | |
| 51 | // Resize iframe |
| 52 | resize : function (data) { |
| 53 | this._element.style.height = data.height + 'px'; |
Akron | a99315e | 2018-07-03 22:56:45 +0200 | [diff] [blame] | 54 | }, |
| 55 | |
| 56 | // Shutdown suspicious iframe |
| 57 | shutdown : function () { |
Akron | a99315e | 2018-07-03 22:56:45 +0200 | [diff] [blame] | 58 | this._element.parentNode.removeChild(this._element); |
Akron | a6c32b9 | 2018-07-02 18:39:42 +0200 | [diff] [blame] | 59 | } |
| 60 | } |
| 61 | }); |