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 | |
| 22 | _init : function (src, id) { |
| 23 | this.src = src; |
| 24 | this.id = id; |
| 25 | return this; |
| 26 | }, |
| 27 | |
| 28 | /** |
| 29 | * The element of the widget |
| 30 | */ |
| 31 | element : function () { |
| 32 | |
| 33 | if (this._element) |
| 34 | return this._element; |
| 35 | |
| 36 | // Spawn new iframe |
| 37 | var i = document.createElement('iframe'); |
| 38 | i.setAttribute('allowTransparency',"true"); |
| 39 | i.setAttribute('frameborder', 0); |
| 40 | i.setAttribute('sandbox','allow-scripts'); |
| 41 | i.classList.add('widget'); |
| 42 | i.setAttribute('name', this.id); |
| 43 | i.setAttribute('src', this.src); |
| 44 | this._element = i; |
| 45 | |
| 46 | return i; |
| 47 | }, |
| 48 | |
| 49 | // Resize iframe |
| 50 | resize : function (data) { |
| 51 | this._element.style.height = data.height + 'px'; |
| 52 | } |
| 53 | } |
| 54 | }); |