blob: daea33c870198c4435afb0b9c5d4bad4d8351775 [file] [log] [blame]
Akron479994e2018-07-02 13:21:44 +02001/**
2 * The plugin system is based
Akron22598cd2019-12-09 14:59:03 +01003 * on registered services (iframes) from
Akron479994e2018-07-02 13:21:44 +02004 * foreign services.
5 * The server component spawns new iframes and
6 * listens to them.
7 *
8 * @author Nils Diewald
9 */
Akrone51eaa32020-11-10 09:35:53 +010010"use strict";
Akron479994e2018-07-02 13:21:44 +020011
Akron3d013802020-10-07 15:03:38 +020012define(['plugin/widget', 'plugin/service', 'state', 'util'], function (widgetClass, serviceClass, stateClass) {
Akron479994e2018-07-02 13:21:44 +020013
Akron2d0d96d2019-11-18 19:49:50 +010014 KorAP.Panel = KorAP.Panel || {};
15
Akron22598cd2019-12-09 14:59:03 +010016 // Contains all servicess to address with
Akrona6c32b92018-07-02 18:39:42 +020017 // messages to them
Akron22598cd2019-12-09 14:59:03 +010018 var services = {};
19 var plugins = {};
Akron10a47962018-07-12 21:17:10 +020020
21 // TODO:
22 // These should better be panels and every panel
23 // has a buttonGroup
Akron2d0d96d2019-11-18 19:49:50 +010024
25 // List of panels with dynamic buttons, i.e.
26 // panels that may occur multiple times.
Akron7c6e05f2018-07-12 19:08:13 +020027 var buttons = {
28 match : []
29 };
Akron2d0d96d2019-11-18 19:49:50 +010030
31 // List of panels with static buttons, i.e.
32 // panels that occur only once.
33 var buttonsSingle = {
hebasta043e96f2019-11-28 12:33:00 +010034 query : [],
35 result : []
Akron22598cd2019-12-09 14:59:03 +010036 }
Akron10a47962018-07-12 21:17:10 +020037
Akrone8e2c952018-07-04 13:43:12 +020038 // This is a counter to limit acceptable incoming messages
39 // to a certain amount. For every message, this counter will
40 // be decreased (down to 0), for every second this will be
41 // increased (up to 100).
42 // Once a widget surpasses the limit, it will be killed
43 // and called suspicious.
44 var maxMessages = 100;
45 var limits = {};
46
47 // TODO:
48 // It may be useful to establish a watcher that pings
Akrone1c27f62018-07-20 11:42:59 +020049 // all widgets every second to see if it is still alive,
50 // otherwise kill
Akrone8e2c952018-07-04 13:43:12 +020051
Akrone1c27f62018-07-20 11:42:59 +020052 // Load Plugin server
Akron479994e2018-07-02 13:21:44 +020053 return {
54
55 /**
56 * Create new plugin management system
57 */
58 create : function () {
59 return Object.create(this)._init();
60 },
61
62 /*
Akron76dd8d32018-07-06 09:30:22 +020063 * Initialize the plugin manager
Akron479994e2018-07-02 13:21:44 +020064 */
65 _init : function () {
Akron479994e2018-07-02 13:21:44 +020066 return this;
67 },
68
69 /**
Akron7c6e05f2018-07-12 19:08:13 +020070 * Register a plugin described as a JSON object.
71 *
72 * This is work in progress.
Akron10a47962018-07-12 21:17:10 +020073 *
74 * Example:
75 *
76 * KorAP.Plugin.register({
77 * 'name' : 'CatContent',
78 * 'desc' : 'Some content about cats',
79 * 'about' : 'https://localhost:5678/',
80 * 'embed' : [{
81 * 'panel' : 'match',
82 * 'title' : loc.TRANSLATE,
83 * 'classes' : ['translate']
84 * 'onClick' : {
85 * 'action' : 'addWidget',
86 * 'template' : 'https://localhost:5678/?match={matchid}',
87 * }
Akron22598cd2019-12-09 14:59:03 +010088 * },{
89 * 'title' : 'glemm',
90 * 'panel' : 'query',
91 * 'onClick' : {
92 * 'action' : 'toggle',
93 * 'state' : 'glemm',
94 * 'service' : {
95 * 'id' : 'glemm',
96 * 'template' : 'https://localhost:5678/'
97 * }
98 * }
Akron10a47962018-07-12 21:17:10 +020099 * }]
100 * });
101 *
Akron7c6e05f2018-07-12 19:08:13 +0200102 */
103 register : function (obj) {
Akron7c6e05f2018-07-12 19:08:13 +0200104 // TODO:
Akron10a47962018-07-12 21:17:10 +0200105 // These fields need to be localized for display by a structure like
106 // { de : { name : '..' }, en : { .. } }
Akron7c6e05f2018-07-12 19:08:13 +0200107 var name = obj["name"];
108
Akron10a47962018-07-12 21:17:10 +0200109 if (!name)
110 throw new Error("Missing name of plugin");
111
Akron3d013802020-10-07 15:03:38 +0200112 var desc = obj["desc"];
113
Akron7c6e05f2018-07-12 19:08:13 +0200114 // Register plugin by name
115 var plugin = plugins[name] = {
116 name : name,
Akron3d013802020-10-07 15:03:38 +0200117 desc : desc,
Akron7c6e05f2018-07-12 19:08:13 +0200118 about : obj["about"],
Akron22598cd2019-12-09 14:59:03 +0100119 widgets : [],
120 services : []
Akron7c6e05f2018-07-12 19:08:13 +0200121 };
Akron10a47962018-07-12 21:17:10 +0200122
123 if (typeof obj["embed"] !== 'object')
124 throw new Error("Embedding of plugin is no list");
Akron7c6e05f2018-07-12 19:08:13 +0200125
126 // Embed all embeddings of the plugin
Akrone1c27f62018-07-20 11:42:59 +0200127 var that = this;
Akron678c26f2020-10-09 08:52:50 +0200128 obj["embed"].forEach(function(embed) {
Akron10a47962018-07-12 21:17:10 +0200129
130 if (typeof embed !== 'object')
131 throw new Error("Embedding of plugin is no object");
132
Akron7c6e05f2018-07-12 19:08:13 +0200133 // Needs to be localized as well
Akron22598cd2019-12-09 14:59:03 +0100134 let title = embed["title"];
135 let panel = embed["panel"];
136 let onClick = embed["onClick"];
hebasta40a85cf2020-07-15 18:10:08 +0200137 let icon = embed["icon"];
138
Akron22598cd2019-12-09 14:59:03 +0100139 if (!panel || !(buttons[panel] || buttonsSingle[panel]))
Akronba09ed22020-10-01 16:01:45 +0200140 throw new Error("Panel for plugin is invalid");
Akron7c6e05f2018-07-12 19:08:13 +0200141
142 // The embedding will open a widget
Akronba09ed22020-10-01 16:01:45 +0200143 if (!onClick["action"] ||
144 onClick["action"] == "addWidget" ||
145 onClick["action"] == "setWidget") {
Akron22598cd2019-12-09 14:59:03 +0100146
147 let cb = function (e) {
Akron7c6e05f2018-07-12 19:08:13 +0200148
Akrone1c27f62018-07-20 11:42:59 +0200149 // "this" is bind to the panel
Akronba09ed22020-10-01 16:01:45 +0200150 // "this".button is the button
151 // "that" is the server object
Akrone1c27f62018-07-20 11:42:59 +0200152
Akronba09ed22020-10-01 16:01:45 +0200153 // The button has a state and the state is associated to the
154 // a intermediate object to toggle the view
155 if ('state' in this.button && this.button.state.associates() > 0) {
156
Akronba09ed22020-10-01 16:01:45 +0200157 let s = this.button.state;
Akronfcf89db2020-10-01 17:40:20 +0200158
159 // The associated service is existent
160 if (services[this.button['widgetID']]) {
Akron237abc42020-10-07 14:14:52 +0200161 s.roll();
Akronfcf89db2020-10-01 17:40:20 +0200162 return;
163 }
164
165 // The service is not existent
166 else {
167
168 // Remove broken state associations
169 s.clear();
Akronba09ed22020-10-01 16:01:45 +0200170 s.set(true);
Akronfcf89db2020-10-01 17:40:20 +0200171 }
Akronba09ed22020-10-01 16:01:45 +0200172 };
173
Akron7c6e05f2018-07-12 19:08:13 +0200174 // Add the widget to the panel
Akronbb891982020-10-05 16:07:18 +0200175 let id = that.addWidget(this, {
176 "name": name,
177 "src": onClick["template"], // that._interpolateURI(onClick["template"], this.match);
Akron3d013802020-10-07 15:03:38 +0200178 "permissions": onClick["permissions"],
179 "desc":desc
Akronbb891982020-10-05 16:07:18 +0200180 });
Akron7c6e05f2018-07-12 19:08:13 +0200181 plugin["widgets"].push(id);
Akronba09ed22020-10-01 16:01:45 +0200182
183 // If a state exists, associate with a mediator object
184 if ('state' in this.button) {
Akronfcf89db2020-10-01 17:40:20 +0200185 this.button['widgetID'] = id;
Akronba09ed22020-10-01 16:01:45 +0200186 this.button.state.associate({
187 setState : function (value) {
188 // Minimize the widget
189 if (value == false) {
190 services[id].minimize();
191 }
192 else {
193 services[id].show();
194 };
195 }
196 });
197 }
Akron7c6e05f2018-07-12 19:08:13 +0200198 };
199
Akron22598cd2019-12-09 14:59:03 +0100200
Akronba09ed22020-10-01 16:01:45 +0200201 // Button object
202 let obj = {'cls':embed["classes"], 'icon': icon }
203
204 if (onClick["action"] && onClick["action"] == "setWidget") {
205
206 // Create a boolean state value, that initializes to true == opened
Akron237abc42020-10-07 14:14:52 +0200207 obj['state'] = stateClass.create([true, false]);
Akronba09ed22020-10-01 16:01:45 +0200208 };
209
Akron2d0d96d2019-11-18 19:49:50 +0100210 // Add to dynamic button list (e.g. for matches)
211 if (buttons[panel]) {
Akronba09ed22020-10-01 16:01:45 +0200212 buttons[panel].push([title, obj, cb]);
Akron2d0d96d2019-11-18 19:49:50 +0100213 }
214
215 // Add to static button list (e.g. for query) already loaded
216 else if (KorAP.Panel[panel]) {
Akronba09ed22020-10-01 16:01:45 +0200217 KorAP.Panel[panel].actions.add(title, obj, cb);
Akron2d0d96d2019-11-18 19:49:50 +0100218 }
219
220 // Add to static button list (e.g. for query) not yet loaded
221 else {
Akronba09ed22020-10-01 16:01:45 +0200222 buttonsSingle[panel].push([title, obj, cb]);
Akron2d0d96d2019-11-18 19:49:50 +0100223 }
Akron22598cd2019-12-09 14:59:03 +0100224 }
Akronba09ed22020-10-01 16:01:45 +0200225
226 // TODO There is no possibility to add icons to an plugin toggle button right now.
Akron22598cd2019-12-09 14:59:03 +0100227 else if (onClick["action"] == "toggle") {
228
Akron237abc42020-10-07 14:14:52 +0200229 // TODO:
230 // Accept a "value" list here for toggling, which should
231 // also allow for "rolling" through states via CSS classes
232 // as 'toggle-true', 'toggle-false' etc.
233
234 let state = stateClass.create([true, false]);
Akron22598cd2019-12-09 14:59:03 +0100235
236 // TODO:
237 // Lazy registration (see above!)
Akron792b1a42020-09-14 18:56:38 +0200238 KorAP.Panel[panel].actions.addToggle(title, {'cls':["title"]}, state);
Akron22598cd2019-12-09 14:59:03 +0100239
Akron22598cd2019-12-09 14:59:03 +0100240 // Add the service
Akronbb891982020-10-05 16:07:18 +0200241 let id = this.addService({
242 "name" : name,
243 // TODO:
244 // Use the "service" keyword
245 "src" : onClick["template"],
246 "permissions" : onClick["permissions"]
247 });
Akronfb11a962020-10-05 12:12:55 +0200248
Akron22598cd2019-12-09 14:59:03 +0100249 // TODO:
250 // This is a bit stupid to get the service window
Akronc3003642020-03-30 10:19:14 +0200251 let service = services[id];
252 let iframe = service.load();
Akron22598cd2019-12-09 14:59:03 +0100253
254 // Create object to communicate the toggle state
255 // once the iframe is loaded.
256 iframe.onload = function () {
257 let sendToggle = {
258 setState : function (val) {
Akronc3003642020-03-30 10:19:14 +0200259 service.sendMsg({
Akron22598cd2019-12-09 14:59:03 +0100260 action: 'state',
261 key : onClick['state'],
262 value : val
Akronc3003642020-03-30 10:19:14 +0200263 });
Akron22598cd2019-12-09 14:59:03 +0100264 }
265 };
266
267 // Associate object with the state
268 state.associate(sendToggle);
269 };
270
271 plugin["services"].push(id);
Akron7c6e05f2018-07-12 19:08:13 +0200272 };
Akron678c26f2020-10-09 08:52:50 +0200273 }, this);
Akron7c6e05f2018-07-12 19:08:13 +0200274 },
275
Akron7c6e05f2018-07-12 19:08:13 +0200276 // TODO:
277 // Interpolate URIs similar to https://tools.ietf.org/html/rfc6570
278 // but as simple as possible
279 _interpolateURI : function (uri, obj) {
280 // ...
281 },
282
283
284 /**
Akron4a703872018-07-26 10:59:41 +0200285 * Get named button group - better rename to "action"
Akron7c6e05f2018-07-12 19:08:13 +0200286 */
287 buttonGroup : function (name) {
Akron2d0d96d2019-11-18 19:49:50 +0100288 if (buttons[name] != undefined) {
289 return buttons[name];
290 } else if (buttonsSingle[name] != undefined) {
291 return buttonsSingle[name];
292 };
293 return [];
294 },
295
296 /**
297 * Clear named button group - better rename to "action"
298 */
299 clearButtonGroup : function (name) {
300 if (buttons[name] != undefined) {
301 buttons[name] = [];
302 } else if (buttonsSingle[name] != undefined) {
303 buttonsSingle[name] = [];
304 }
Akron7c6e05f2018-07-12 19:08:13 +0200305 },
Akron479994e2018-07-02 13:21:44 +0200306
Akron22598cd2019-12-09 14:59:03 +0100307 // Optionally initialize the service mechanism and get an ID
308 _getServiceID : function () {
Akron4a703872018-07-26 10:59:41 +0200309
Akron22598cd2019-12-09 14:59:03 +0100310 // Is it the first service?
Akron76dd8d32018-07-06 09:30:22 +0200311 if (!this._listener) {
312
313 /*
314 * Establish the global 'message' hook.
315 */
316 this._listener = this._receiveMsg.bind(this);
317 window.addEventListener("message", this._listener);
318
Akron22598cd2019-12-09 14:59:03 +0100319 // Every second increase the limits of all registered services
Akron76dd8d32018-07-06 09:30:22 +0200320 this._timer = window.setInterval(function () {
Akron678c26f2020-10-09 08:52:50 +0200321 for (let i = 0; i < limits.length; i++) {
Akron76dd8d32018-07-06 09:30:22 +0200322 if (limits[i]++ >= maxMessages) {
323 limits[i] = maxMessages;
324 }
325 }
326 }, 1000);
327 };
328
Akron22598cd2019-12-09 14:59:03 +0100329 // Create a unique random ID per service
330 return 'id-' + this._randomID();
331 },
332
333 /**
334 * Add a service in a certain panel and return the id.
335 */
Akronbb891982020-10-05 16:07:18 +0200336 addService : function (data) {
337 if (!data["src"])
Akron22598cd2019-12-09 14:59:03 +0100338 return;
339
340 let id = this._getServiceID();
341
Akronbb891982020-10-05 16:07:18 +0200342 data["id"] = id;
343
Akron22598cd2019-12-09 14:59:03 +0100344 // Create a new service
Akronbb891982020-10-05 16:07:18 +0200345 let service = serviceClass.create(data);
Akron22598cd2019-12-09 14:59:03 +0100346
Akron22598cd2019-12-09 14:59:03 +0100347 services[id] = service;
348 limits[id] = maxMessages;
349
Akron22598cd2019-12-09 14:59:03 +0100350 // Add service to panel
351 this.element().appendChild(
352 service.load()
353 );
354
355 return id;
356 },
357
358
359 /**
360 * Open a new widget view in a certain panel and return
361 * the id.
362 */
Akronbb891982020-10-05 16:07:18 +0200363 addWidget : function (panel, data) {
364 // panel, name, src, permissions
Akron22598cd2019-12-09 14:59:03 +0100365
366 let id = this._getServiceID();
Akrona6c32b92018-07-02 18:39:42 +0200367
Akronbb891982020-10-05 16:07:18 +0200368 data["id"] = id;
369
Akrona6c32b92018-07-02 18:39:42 +0200370 // Create a new widget
Akronbb891982020-10-05 16:07:18 +0200371 var widget = widgetClass.create(data);
Akrona6c32b92018-07-02 18:39:42 +0200372
373 // Store the widget based on the identifier
Akron22598cd2019-12-09 14:59:03 +0100374 services[id] = widget;
Akrona99315e2018-07-03 22:56:45 +0200375 limits[id] = maxMessages;
Akrona6c32b92018-07-02 18:39:42 +0200376
Akron4a703872018-07-26 10:59:41 +0200377 widget._mgr = this;
378
Akrone1c27f62018-07-20 11:42:59 +0200379 // Add widget to panel
380 panel.add(widget);
Akronb43c8c62018-07-04 18:27:28 +0200381
382 return id;
Akron479994e2018-07-02 13:21:44 +0200383 },
384
Akron4a703872018-07-26 10:59:41 +0200385
386 /**
Akron22598cd2019-12-09 14:59:03 +0100387 * Get service by identifier
Akron4a703872018-07-26 10:59:41 +0200388 */
Akron22598cd2019-12-09 14:59:03 +0100389 service : function (id) {
390 return services[id];
Akron4a703872018-07-26 10:59:41 +0200391 },
392
393
Akron22598cd2019-12-09 14:59:03 +0100394 // Receive a call from an embedded service.
Akrone8e2c952018-07-04 13:43:12 +0200395 // The handling needs to be very careful,
396 // as this can easily become a security nightmare.
Akron479994e2018-07-02 13:21:44 +0200397 _receiveMsg : function (e) {
Akronbc94a9c2021-04-15 00:07:35 +0200398
Akron479994e2018-07-02 13:21:44 +0200399 // Get event data
400 var d = e.data;
401
Akrona99315e2018-07-03 22:56:45 +0200402 // If no data given - fail
403 // (probably check that it's an assoc array)
404 if (!d)
405 return;
406
407 // e.origin is probably set and okay - CHECK!
Akronbc94a9c2021-04-15 00:07:35 +0200408 // TODO: Check e.origin is in the list of registered participants
409 // if (e.origin !== "http://example.com:8080")
410 // return;
Akron479994e2018-07-02 13:21:44 +0200411
Akronbc94a9c2021-04-15 00:07:35 +0200412
Akrona99315e2018-07-03 22:56:45 +0200413 // Get origin ID
414 var id = d["originID"];
415
416 // If no origin ID given - fail
417 if (!id)
418 return;
419
Akron22598cd2019-12-09 14:59:03 +0100420 // Get the service
421 let service = services[id];
Akrona6c32b92018-07-02 18:39:42 +0200422
Akron22598cd2019-12-09 14:59:03 +0100423 // If the addressed service does not exist - fail
424 if (!service)
Akrona6c32b92018-07-02 18:39:42 +0200425 return;
426
Akrona99315e2018-07-03 22:56:45 +0200427 // Check for message limits
428 if (limits[id]-- < 0) {
Akrone8e2c952018-07-04 13:43:12 +0200429
Akron22598cd2019-12-09 14:59:03 +0100430 // Kill service
431 KorAP.log(0, 'Suspicious action by service', service.src);
Akron7c6e05f2018-07-12 19:08:13 +0200432
433 // TODO:
434 // Potentially kill the whole plugin!
Akron4a703872018-07-26 10:59:41 +0200435
Akron22598cd2019-12-09 14:59:03 +0100436 // This removes all connections before closing the service
437 this._closeService(service.id);
438
439 // if (service.isWidget)
440 service.close();
441
Akrona99315e2018-07-03 22:56:45 +0200442 return;
443 };
Akrona6c32b92018-07-02 18:39:42 +0200444
Akron479994e2018-07-02 13:21:44 +0200445 // Resize the iframe
Akron22598cd2019-12-09 14:59:03 +0100446 switch (d.action) {
447 case 'resize':
448 if (service.isWidget)
449 service.resize(d);
450 break;
Akron479994e2018-07-02 13:21:44 +0200451
452 // Log message from iframe
Akron22598cd2019-12-09 14:59:03 +0100453 case 'log':
454 KorAP.log(d.code, d.msg, service.src);
455 break;
Akron51ee6232019-12-17 21:00:05 +0100456
457 // Modify pipes
458 case 'pipe':
459 if (KorAP.Pipe != undefined) {
460 if (d.job == 'del') {
461 KorAP.Pipe.remove(d.service);
462 } else {
463 KorAP.Pipe.append(d.service);
464 };
465 };
466 break;
Akronc3003642020-03-30 10:19:14 +0200467
468 // Get information from the embedding platform
469 case 'get':
Akron45308ce2020-08-28 14:10:23 +0200470
471 // Get KoralQuery
Akronc3003642020-03-30 10:19:14 +0200472 if (d.key == 'KQ') {
473 if (KorAP.koralQuery !== undefined) {
474 d["value"] = KorAP.koralQuery;
475 };
Akron45308ce2020-08-28 14:10:23 +0200476 }
477
Akron432972b2020-09-18 17:05:53 +0200478 // Get Query information from from
Akron45308ce2020-08-28 14:10:23 +0200479 else if (d.key == 'QueryForm') {
480 let doc = document;
481 let v = d["value"] = {};
482
483 var el;
484 if (el = doc.getElementById('q-field')) {
485 v["q"] = el.value;
486 };
487 if (el = doc.getElementById('ql-field')) {
488 v["ql"] = el.value;
489 };
490 if (el = KorAP.vc) {
491 v["cq"] = el.toQuery();
492 };
Akron432972b2020-09-18 17:05:53 +0200493 }
494
495 // Get Query information from parameters
496 else if (d.key == 'QueryParam') {
497
498 // Supported in all modern browsers
499 var p = new URLSearchParams(window.location.search);
500 let v = d["value"] = {};
501 v["q"] = p.get('q');
502 v["ql"] = p.get('ql');
503 v["cq"] = p.get('cq');
Akronc3003642020-03-30 10:19:14 +0200504 };
505 };
506
507 // data needs to be mirrored
508 if (d._id) {
509 service.sendMsg(d);
Akrona6c32b92018-07-02 18:39:42 +0200510 };
511
512 // TODO:
513 // Close
Akron479994e2018-07-02 13:21:44 +0200514 },
515
Akron22598cd2019-12-09 14:59:03 +0100516 // Close the service
517 _closeService : function (id) {
Akron4a703872018-07-26 10:59:41 +0200518 delete limits[id];
Akronfcf89db2020-10-01 17:40:20 +0200519
Akron22598cd2019-12-09 14:59:03 +0100520 // Close the iframe
521 if (services[id] && services[id]._closeIframe) {
522 services[id]._closeIframe();
523
524 // Remove from list
525 delete services[id];
526 };
527
Akron76dd8d32018-07-06 09:30:22 +0200528
529 // Remove listeners in case no widget
530 // is available any longer
531 if (Object.keys(limits).length == 0)
532 this._removeListener();
533 },
534
Akrona6c32b92018-07-02 18:39:42 +0200535 // Get a random identifier
536 _randomID : function () {
537 return randomID(20);
Akronb43c8c62018-07-04 18:27:28 +0200538 },
539
Akron76dd8d32018-07-06 09:30:22 +0200540 // Remove the listener
541 _removeListener : function () {
542 window.clearInterval(this._timer);
543 this._timer = undefined;
544 window.removeEventListener("message", this._listener);
545 this._listener = undefined;
546 },
547
Akron22598cd2019-12-09 14:59:03 +0100548 /**
549 * Return the service element.
550 */
551 element : function () {
Akron24aa0052020-11-10 11:00:34 +0100552 if (!this._el) {
553 this._el = document.createElement('div');
554 this._el.setAttribute("id", "services");
Akron22598cd2019-12-09 14:59:03 +0100555 }
Akron24aa0052020-11-10 11:00:34 +0100556 return this._el;
Akron22598cd2019-12-09 14:59:03 +0100557 },
558
Akronb43c8c62018-07-04 18:27:28 +0200559 // Destructor, just for testing scenarios
560 destroy : function () {
561 limits = {};
Akron678c26f2020-10-09 08:52:50 +0200562 Object.keys(services).forEach(
563 s => services[s].close()
564 );
Akron22598cd2019-12-09 14:59:03 +0100565 services = {};
Akron678c26f2020-10-09 08:52:50 +0200566 Object.keys(buttons).forEach(
567 b => buttons[b] = []
568 );
569 Object.keys(buttonsSingle).forEach(
570 b => buttonsSingle[b] = []
571 );
Akron22598cd2019-12-09 14:59:03 +0100572
Akron24aa0052020-11-10 11:00:34 +0100573 if (this._el) {
574 let e = this._el;
Akron22598cd2019-12-09 14:59:03 +0100575 if (e.parentNode) {
576 e.parentNode.removeChild(e);
577 };
Akron24aa0052020-11-10 11:00:34 +0100578 this._el = null;
Akron22598cd2019-12-09 14:59:03 +0100579 };
580
Akron76dd8d32018-07-06 09:30:22 +0200581 this._removeListener();
Akron479994e2018-07-02 13:21:44 +0200582 }
Akrone1c27f62018-07-20 11:42:59 +0200583 };
Akron479994e2018-07-02 13:21:44 +0200584});