blob: be567be898046d854e1372b925f96f91a8286974 [file] [log] [blame]
Akron22598cd2019-12-09 14:59:03 +01001define(function () {
2 "use strict";
Akronc3003642020-03-30 10:19:14 +02003
Akron22598cd2019-12-09 14:59:03 +01004 return {
5 create : function (name, src, id) {
6 return Object.create(this)._init(name, src, id);
7 },
8
9 // Initialize service
10 _init : function (name, src, id) {
11 if (!name || !src || !id)
12 throw Error("Service not well defined");
13 this.name = name;
14 this.src = src;
15 this.id = id;
16
17 // There is no close method defined yet
18 if (!this.close) {
19 this.close = function () {
20 this._closeIframe();
21 }
22 }
23
24 return this;
25 },
26
27 /**
28 * The element of the service as embedded in the panel
29 */
30 load : function () {
31 if (this._load)
32 return this._load;
33
34 // Spawn new iframe
35 let e = document.createElement('iframe');
36 e.setAttribute('allowTransparency',"true");
37 e.setAttribute('frameborder', 0);
hebasta78913242020-03-30 13:39:20 +020038 // Allow forms in Plugins
39 e.setAttribute('sandbox','allow-scripts allow-forms');
Akron22598cd2019-12-09 14:59:03 +010040 e.style.height = '0px';
41 e.setAttribute('name', this.id);
42 e.setAttribute('src', this.src);
43
44 this._load = e;
45 return e;
46 },
47
Akronc3003642020-03-30 10:19:14 +020048 /**
49 * Send a message to the embedded service.
50 */
51 sendMsg : function (d) {
52 let iframe = this.load();
53 iframe.contentWindow.postMessage(
54 d,
55 '*'
56 ); // TODO: Fix origin
57 },
58
Akron22598cd2019-12-09 14:59:03 +010059 // onClose : function () {},
60
61 /**
62 * Close the service iframe.
63 */
64 _closeIframe : function () {
65 var e = this._load;
66 if (e && e.parentNode) {
67 e.parentNode.removeChild(e);
68 };
69 this._load = null;
70 }
71 };
72});