blob: 17c1f5e0e1b5435112ab536025540ec47b9f31f1 [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.
Akrone1c27f62018-07-20 11:42:59 +02005 * The widget component represents a single iframe and is
6 * implemented as a view object.
Akrona6c32b92018-07-02 18:39:42 +02007 *
8 * @author Nils Diewald
9 */
10
Akrone1c27f62018-07-20 11:42:59 +020011define(["view","util"], function (viewClass) {
Akrona6c32b92018-07-02 18:39:42 +020012 "use strict";
13
14 return {
15
16 /**
17 * Create new widget
18 */
Akron7991b192018-07-09 17:28:43 +020019 create : function (name, src, id) {
Akrone1c27f62018-07-20 11:42:59 +020020 return Object.create(viewClass)._init(['widget']).upgradeTo(this)._init(name, src, id);
Akrona6c32b92018-07-02 18:39:42 +020021 },
22
Akrone8e2c952018-07-04 13:43:12 +020023 // Initialize widget
Akron7991b192018-07-09 17:28:43 +020024 _init : function (name, src, id) {
25 this.name = name;
Akrona6c32b92018-07-02 18:39:42 +020026 this.src = src;
27 this.id = id;
28 return this;
29 },
30
31 /**
Akrone1c27f62018-07-20 11:42:59 +020032 * The element of the widget as embedded in the view
Akrona6c32b92018-07-02 18:39:42 +020033 */
Akrone1c27f62018-07-20 11:42:59 +020034 show : function () {
Akrona6c32b92018-07-02 18:39:42 +020035
Akrone1c27f62018-07-20 11:42:59 +020036 if (this._show)
37 return this._show;
Akron8d646d72018-07-08 13:45:53 +020038
Akrona6c32b92018-07-02 18:39:42 +020039 // Spawn new iframe
Akrone1c27f62018-07-20 11:42:59 +020040 var i = document.createElement('iframe');
Akrona6c32b92018-07-02 18:39:42 +020041 i.setAttribute('allowTransparency',"true");
42 i.setAttribute('frameborder', 0);
43 i.setAttribute('sandbox','allow-scripts');
Akrone8e2c952018-07-04 13:43:12 +020044 i.style.height = '0px';
Akrona6c32b92018-07-02 18:39:42 +020045 i.setAttribute('name', this.id);
46 i.setAttribute('src', this.src);
Akrona6c32b92018-07-02 18:39:42 +020047
Akrone1c27f62018-07-20 11:42:59 +020048 // Per default there should at least be a button
49 // for settings, if the plugin requires settings.
50 // Otherwise a button indicating this is a plugin
51 // is a nice idea as well.
Akron8d646d72018-07-08 13:45:53 +020052
Akrone1c27f62018-07-20 11:42:59 +020053 this.actions.add(
54 this.name, ['button-icon', 'plugin'], function (e) {
Akron8d646d72018-07-08 13:45:53 +020055
Akrone1c27f62018-07-20 11:42:59 +020056 // Temporary
57 window.alert("Basic information about this plugin");
Akron8d646d72018-07-08 13:45:53 +020058 }.bind(this));
59
Akrone1c27f62018-07-20 11:42:59 +020060 this._show = i;
61 return i;
Akrona6c32b92018-07-02 18:39:42 +020062 },
63
64 // Resize iframe
65 resize : function (data) {
Akrone1c27f62018-07-20 11:42:59 +020066 this.show().style.height = data.height + 'px';
Akrona99315e2018-07-03 22:56:45 +020067 },
68
69 // Shutdown suspicious iframe
70 shutdown : function () {
Akrone1c27f62018-07-20 11:42:59 +020071 this.element().parentNode.removeChild(this.element());
Akrona6c32b92018-07-02 18:39:42 +020072 }
73 }
74});