blob: 7e56603b6edab73fa0b8a73312048e6cf222ea42 [file] [log] [blame]
Akrona6c32b92018-07-02 18:39:42 +02001/**
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
10define(["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
Akrone8e2c952018-07-04 13:43:12 +020022 // Initialize widget
Akrona6c32b92018-07-02 18:39:42 +020023 _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');
Akrone8e2c952018-07-04 13:43:12 +020043 i.style.height = '0px';
Akrona6c32b92018-07-02 18:39:42 +020044 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';
Akrona99315e2018-07-03 22:56:45 +020054 },
55
56 // Shutdown suspicious iframe
57 shutdown : function () {
Akrona99315e2018-07-03 22:56:45 +020058 this._element.parentNode.removeChild(this._element);
Akrona6c32b92018-07-02 18:39:42 +020059 }
60 }
61});