blob: d246a8cb30b710401676556925b8e96b370aeddc [file] [log] [blame]
Akron7524be12016-06-01 17:31:33 +02001/*
Akron5cb9b2b2018-07-24 17:01:09 +02002 * Initialize The JS frontend part and decorate
3 * the static HTML data.
4 *
5 * @author Nils Diewald
6 *
Akron7524be12016-06-01 17:31:33 +02007 * TODO: Create lazy loading of objects including
8 * - obj.hint()
9 * - obj.alertify()
10 * - obj.session()
11 * - obj.tutorial()
12 * - obj.vc() // toggle
13 * - obj.matchCreate() (using webpack)
14 * - obj.koral() (show result, parse for errors ...)
15 * - obj.alignment() // toggle
16 */
17
Akrone51eaa32020-11-10 09:35:53 +010018"use strict";
Nils Diewald0e6992a2015-04-14 20:13:52 +000019define([
20 'match',
21 'hint',
22 'vc',
23 'tutorial',
24 'lib/domReady',
Akron27ae9ec2015-06-23 00:43:21 +020025 'vc/array',
Nils Diewald7148c6f2015-05-04 15:07:53 +000026 'lib/alertify',
Akron7716f012015-07-01 20:38:32 +020027 'session',
Akron6bb71582016-06-10 20:41:08 +020028 'selectMenu',
Akron5cb9b2b2018-07-24 17:01:09 +020029 'panel/result',
Akron2d0d96d2019-11-18 19:49:50 +010030 'panel/query',
hebasta75cfca52019-02-19 13:15:27 +010031 'tour/tours',
Akron24f48ea2020-07-01 09:37:19 +020032 'plugin/server',
33 'pipe',
Nils Diewald7148c6f2015-05-04 15:07:53 +000034 'api',
Nils Diewaldc46003b2015-05-07 15:55:35 +000035 'mailToChiffre',
Akron858cbc82019-12-05 16:53:13 +010036 'util',
37 'state'
Nils Diewald0e6992a2015-04-14 20:13:52 +000038], function (matchClass,
Akron19d97fe2016-09-06 20:47:05 +020039 hintClass,
40 vcClass,
41 tutClass,
42 domReady,
Akron19d97fe2016-09-06 20:47:05 +020043 vcArray,
44 alertifyClass,
45 sessionClass,
Akron4d926f12018-07-16 15:30:25 +020046 selectMenuClass,
hebasta75cfca52019-02-19 13:15:27 +010047 resultPanelClass,
Akron2d0d96d2019-11-18 19:49:50 +010048 queryPanelClass,
Akron24f48ea2020-07-01 09:37:19 +020049 tourClass,
50 pluginClass,
51 pipeClass) {
Nils Diewalda0defc42015-05-07 23:54:17 +000052
Akron0b489ad2018-02-02 16:49:32 +010053 const d = document;
Akron9cc3eaf2015-06-10 22:15:52 +020054
Akronbc6b3f22021-01-13 14:53:12 +010055 // Set base URL
56 KorAP.URL = d.body.getAttribute('data-korap-url') || "";
57
58 // Get koralQuery response
59 const kqe = d.getElementById('koralQuery');
60 if (kqe !== null) {
61 KorAP.koralQuery = JSON.parse(kqe.getAttribute('data-koralquery') || "");
62 };
63
Akron0c4cd222019-07-19 16:33:34 +020064 // Create suffix if KorAP is run in a subfolder
65 KorAP.session = sessionClass.create(
66 KorAP.URL.length > 0 ? 'kalamarJS-' + KorAP.URL.slugify() : 'kalamarJS'
67 );
Akronf8035592018-05-24 20:40:51 +020068
Nils Diewalda0defc42015-05-07 23:54:17 +000069 // Override KorAP.log
70 window.alertify = alertifyClass;
Akronc0a2da82018-07-04 15:27:37 +020071 KorAP.log = function (code, msg, src) {
72
73 if (src) {
74 msg += '<code class="src">'+src+'</code>';
75 };
Nils Diewalda0defc42015-05-07 23:54:17 +000076
77 // Use alertify to log errors
78 alertifyClass.log(
Akronf55504a2015-06-18 16:42:55 +020079 (code === 0 ? '' : code + ': ') +
Akron19d97fe2016-09-06 20:47:05 +020080 msg,
Nils Diewalda0defc42015-05-07 23:54:17 +000081 'error',
Akronf55504a2015-06-18 16:42:55 +020082 10000
Nils Diewalda0defc42015-05-07 23:54:17 +000083 );
84 };
85
hebasta2758b582018-11-19 15:59:42 +010086 KorAP.vc = vcClass.create(vcArray);
Akron690066c2021-01-22 17:39:18 +010087
88 let gt;
89 if (gt = document.getElementById('link-guided-tour')) {
90 gt.setAttribute('href', '#');
91 gt.addEventListener('click', function(){
92 tourClass.gTstartSearch().start();
93 });
94
95 KorAP.tourshowR = function(){
96 tourClass.gTshowResults().start();
97 };
hebasta5df796f2019-05-21 15:27:12 +020098 };
Akroncb5c1712021-01-26 18:01:04 +010099
Nils Diewald0e6992a2015-04-14 20:13:52 +0000100 domReady(function (event) {
hebasta5df796f2019-05-21 15:27:12 +0200101
Nils Diewald0e6992a2015-04-14 20:13:52 +0000102 var obj = {};
Akron71b91e42016-06-01 22:12:43 +0200103
Akron4d926f12018-07-16 15:30:25 +0200104 // What should be visible in the beginning?
Akronf8035592018-05-24 20:40:51 +0200105 var show = KorAP.session.get('show') || {};
hebasta043e96f2019-11-28 12:33:00 +0100106
107 KorAP.Panel = KorAP.Panel || {}
Nils Diewalda297f062015-04-02 00:23:46 +0000108
109 /**
Akronf55504a2015-06-18 16:42:55 +0200110 * Release notifications
111 */
Akroncb5c1712021-01-26 18:01:04 +0100112 d.querySelectorAll('#notifications div.notify').forEach(
113 function(e) {
114 let msg = e.textContent;
115
116 let src = e.getAttribute('data-src');
117 if (src) {
118 msg += '<code class="src">'+src+'</code>';
Akron8ea84292018-10-24 13:41:52 +0200119 };
Akroncb5c1712021-01-26 18:01:04 +0100120
121 let type = e.getAttribute('data-type') || "error";
122 alertifyClass.log(msg, type, 10000);
123 }
124 );
Akronf55504a2015-06-18 16:42:55 +0200125
126 /**
Akroncd42a142019-07-12 18:55:37 +0200127 * Replace Virtual Corpus field
Nils Diewald7148c6f2015-05-04 15:07:53 +0000128 */
Akron5c829e92017-05-12 18:10:00 +0200129 var vcname, vcchoose;
Akroncd42a142019-07-12 18:55:37 +0200130 var input = d.getElementById('cq');
Akron1f0521b2018-08-28 13:01:24 +0200131
hebasta2758b582018-11-19 15:59:42 +0100132 var vc = KorAP.vc;
hebasta48842cf2018-12-11 12:57:38 +0100133
Akron1f0521b2018-08-28 13:01:24 +0200134 // Add vc name object
Nils Diewald7148c6f2015-05-04 15:07:53 +0000135 if (input) {
136 input.style.display = 'none';
Akron0b489ad2018-02-02 16:49:32 +0100137 vcname = d.createElement('span');
Nils Diewald7148c6f2015-05-04 15:07:53 +0000138 vcname.setAttribute('id', 'vc-choose');
Akron6bb71582016-06-10 20:41:08 +0200139 vcname.classList.add('select');
Akron941551e2015-06-11 16:06:22 +0200140
Akron1f0521b2018-08-28 13:01:24 +0200141 // Load virtual corpus object
Akroncd42a142019-07-12 18:55:37 +0200142 // Supports "collection" for legacy reasons
143 if (KorAP.koralQuery !== undefined && (KorAP.koralQuery["collection"] || KorAP.koralQuery["corpus"])) {
Akron1f0521b2018-08-28 13:01:24 +0200144 try {
Akroncd42a142019-07-12 18:55:37 +0200145 vc.fromJson(KorAP.koralQuery["collection"] || KorAP.koralQuery["corpus"]);
Akron1f0521b2018-08-28 13:01:24 +0200146 }
147 catch (e) {
148 KorAP.log(0,e);
149 }
Akron27ae9ec2015-06-23 00:43:21 +0200150 };
151
Akron0b489ad2018-02-02 16:49:32 +0100152 vcchoose = vcname.addE('span');
Akronec6bb8e2018-08-29 13:07:56 +0200153 vcchoose.addT(vc.getName());
Akron27ae9ec2015-06-23 00:43:21 +0200154
Akron1f0521b2018-08-28 13:01:24 +0200155 if (vc.wasRewritten()) {
156 vcchoose.classList.add('rewritten');
157 };
158
Nils Diewald7148c6f2015-05-04 15:07:53 +0000159 input.parentNode.insertBefore(vcname, input);
160 };
161
Nils Diewald7148c6f2015-05-04 15:07:53 +0000162 /**
Nils Diewalda297f062015-04-02 00:23:46 +0000163 * Add actions to match entries
164 */
Akronb50964a2020-10-12 11:44:37 +0200165 var matchElements = d.querySelectorAll(
Akron3c390c42020-03-30 09:06:21 +0200166 '#search > ol > li'
Nils Diewald5c5a7472015-04-02 22:13:38 +0000167 );
Akron6a535d42015-08-26 20:16:58 +0200168
Akronb50964a2020-10-12 11:44:37 +0200169 matchElements.forEach(function(e) {
Akron3c390c42020-03-30 09:06:21 +0200170
171 // Define class for active elements
172 if (e.classList.contains('active')) {
173 if (this._match === undefined) {
Akron19d97fe2016-09-06 20:47:05 +0200174 // lazyLoad
Akron3c390c42020-03-30 09:06:21 +0200175 matchClass.create(e).init();
Akron19d97fe2016-09-06 20:47:05 +0200176 };
Akron3c390c42020-03-30 09:06:21 +0200177 }
178
179 // Define class for inactive elements
180 else {
181 e.addEventListener('click', function (e) {
Akron19d97fe2016-09-06 20:47:05 +0200182 if (this._match !== undefined)
Akron3c390c42020-03-30 09:06:21 +0200183 this._match.open();
Akron19d97fe2016-09-06 20:47:05 +0200184 else {
185 // lazyLoad
186 matchClass.create(this).open();
187 };
Akron3c390c42020-03-30 09:06:21 +0200188 // This would prevent the sidebar to go back
189 // e.halt();
190 });
191 e.addEventListener('keydown', function (e) {
192 var code = _codeFromEvent(e);
193
194 switch (code) {
195 case 32:
196 if (this._match !== undefined)
197 this._match.toggle();
198 else {
199 // lazyLoad
200 matchClass.create(this).open();
201 };
202 e.halt();
203 break;
204 };
205 });
206 };
Akronb50964a2020-10-12 11:44:37 +0200207 }, this);
Akron3c390c42020-03-30 09:06:21 +0200208
Akrone0c32c72017-04-25 22:38:23 +0200209 // Add focus listener to aside
Akron0b489ad2018-02-02 16:49:32 +0100210 var aside = d.getElementsByTagName('aside')[0];
Akrone0c32c72017-04-25 22:38:23 +0200211
212 if (aside && aside.classList.contains('active') == false) {
Akron1885ce92017-04-26 23:10:01 +0200213
Akron5258d462017-04-26 23:32:57 +0200214 // Horrible lock to deal with sidebar clicks
215 var asideClicked = false;
216
Akron1885ce92017-04-26 23:10:01 +0200217 // Make aside active on focus
218 aside.addEventListener('focus', function(e) {
Akrone0c32c72017-04-25 22:38:23 +0200219 this.classList.add('active');
220 });
221
Akron1885ce92017-04-26 23:10:01 +0200222 // Deactivate focus when clicking anywhere else
Akron0b489ad2018-02-02 16:49:32 +0100223 var body = d.getElementsByTagName('body')[0];
Akron1885ce92017-04-26 23:10:01 +0200224 if (body !== null) {
225 body.addEventListener('click', function() {
Akron5258d462017-04-26 23:32:57 +0200226 if (!asideClicked) {
227 aside.classList.remove('active');
228 }
229 else {
230 asideClicked = false;
231 };
Akron1885ce92017-04-26 23:10:01 +0200232 });
233 };
234
235 /* Stop click event on aside
236 * (to not trickle down to body)
237 */
238 aside.addEventListener('click', function(e) {
Akron5258d462017-04-26 23:32:57 +0200239 asideClicked = true;
Akrone0c32c72017-04-25 22:38:23 +0200240 });
241 };
Akronb9cdb102017-04-25 00:52:31 +0200242
243
Akron6bb71582016-06-10 20:41:08 +0200244 // Replace QL select menus with KorAP menus
Akron0b489ad2018-02-02 16:49:32 +0100245 var qlField = d.getElementById('ql-field');
Akronaba7a5a2016-08-15 21:58:33 +0200246 if (qlField !== null) {
Akron086fe5d2017-11-13 14:01:45 +0100247 KorAP.QLmenu = selectMenuClass.create(
Akron0b489ad2018-02-02 16:49:32 +0100248 d.getElementById('ql-field').parentNode
Akronaba7a5a2016-08-15 21:58:33 +0200249 ).limit(5);
250 };
Akron6bb71582016-06-10 20:41:08 +0200251
Akron4d926f12018-07-16 15:30:25 +0200252 var resultInfo = d.getElementById('resultinfo');
253
Akron4d926f12018-07-16 15:30:25 +0200254 /**
255 * Add result panel
256 */
Akron5cb9b2b2018-07-24 17:01:09 +0200257 var resultPanel = resultPanelClass.create(show);
258
Akron4d926f12018-07-16 15:30:25 +0200259 if (resultInfo != null) {
Akron4d926f12018-07-16 15:30:25 +0200260
261 // Move buttons to resultinfo
262 resultInfo.appendChild(resultPanel.actions.element());
263
Akrone6538cd2018-07-16 17:52:33 +0200264 // The views are at the top of the search results
Akron4d926f12018-07-16 15:30:25 +0200265 var sb = d.getElementById('search');
266 sb.insertBefore(resultPanel.element(), sb.firstChild);
Akron4d926f12018-07-16 15:30:25 +0200267 };
268
269
Akron179c8ac2015-06-30 19:30:50 +0200270 // There is a koralQuery
Akron4d926f12018-07-16 15:30:25 +0200271 if (KorAP.koralQuery !== undefined) {
Akron5cb9b2b2018-07-24 17:01:09 +0200272
273 // Add KoralQuery view to result panel
Akron4d926f12018-07-16 15:30:25 +0200274 if (resultInfo !== null) {
Akron5cb9b2b2018-07-24 17:01:09 +0200275 resultPanel.addKqAction()
Akron179c8ac2015-06-30 19:30:50 +0200276 };
Akron7716f012015-07-01 20:38:32 +0200277
Akron00cd4d12016-05-31 21:01:11 +0200278 if (KorAP.koralQuery["errors"]) {
Akron678c26f2020-10-09 08:52:50 +0200279 KorAP.koralQuery["errors"].forEach(function(e) {
Akronf0c31ed2016-06-11 11:27:01 +0200280
Akron19d97fe2016-09-06 20:47:05 +0200281 // Malformed query
Akron4a24b722020-10-13 12:44:25 +0200282 if (e[0] === 302 && e[2] !== undefined) {
Akron19d97fe2016-09-06 20:47:05 +0200283 obj.hint = hintClass.create();
Akron678c26f2020-10-09 08:52:50 +0200284 obj.hint.alert(e[2], e[1]);
Akron19d97fe2016-09-06 20:47:05 +0200285 }
Akronf0c31ed2016-06-11 11:27:01 +0200286
Akron19d97fe2016-09-06 20:47:05 +0200287 // no query
Akron678c26f2020-10-09 08:52:50 +0200288 else if (e[0] === 301) {
Akron19d97fe2016-09-06 20:47:05 +0200289 obj.hint = hintClass.create();
Akron678c26f2020-10-09 08:52:50 +0200290 obj.hint.alert(0, e[1]);
Akron19d97fe2016-09-06 20:47:05 +0200291 }
Akron678c26f2020-10-09 08:52:50 +0200292 });
Akron00cd4d12016-05-31 21:01:11 +0200293 };
Akron179c8ac2015-06-30 19:30:50 +0200294 };
295
Akron5cb9b2b2018-07-24 17:01:09 +0200296
297 /*
298 * There is more than 0 matches, so allow for
299 * alignment toggling (left <=> right)
300 */
Akronb50964a2020-10-12 11:44:37 +0200301 if (matchElements.length > 0)
Akron5cb9b2b2018-07-24 17:01:09 +0200302 resultPanel.addAlignAction();
Nils Diewald7148c6f2015-05-04 15:07:53 +0000303
hebasta043e96f2019-11-28 12:33:00 +0100304 KorAP.Panel['result'] = resultPanel;
Akron5cb9b2b2018-07-24 17:01:09 +0200305 /*
Akroncd42a142019-07-12 18:55:37 +0200306 * Toggle the Virtual Corpus builder
Nils Diewald7148c6f2015-05-04 15:07:53 +0000307 */
308 if (vcname) {
Akronec6bb8e2018-08-29 13:07:56 +0200309 vc.onMinimize = function () {
310 vcname.classList.remove('active');
Akroncd42a142019-07-12 18:55:37 +0200311 delete show['vc'];
Akronec6bb8e2018-08-29 13:07:56 +0200312 };
Nils Diewald6283d692015-04-23 20:32:53 +0000313
Akronec6bb8e2018-08-29 13:07:56 +0200314 vc.onOpen = function () {
315 vcname.classList.add('active');
Akroncfe8ecc2018-11-20 18:46:16 +0100316
317 var view = d.getElementById('vc-view');
318 if (!view.firstChild)
319 view.appendChild(this.element());
320
Akroncd42a142019-07-12 18:55:37 +0200321 show['vc'] = true;
Akronec6bb8e2018-08-29 13:07:56 +0200322 };
323
324 var vcclick = function () {
Akronec6bb8e2018-08-29 13:07:56 +0200325 if (vc.isOpen()) {
326 vc.minimize()
327 }
328 else {
Akronec6bb8e2018-08-29 13:07:56 +0200329 vc.open();
Akron19d97fe2016-09-06 20:47:05 +0200330 };
Nils Diewald58141332015-04-07 16:18:45 +0000331 };
Akron04671e72017-05-11 20:47:32 +0200332
Akron179c8ac2015-06-30 19:30:50 +0200333 vcname.onclick = vcclick;
Akron5c829e92017-05-12 18:10:00 +0200334
335 // Click, if the VC should be shown
Akroncd42a142019-07-12 18:55:37 +0200336 if (show['vc']) {
Akron19d97fe2016-09-06 20:47:05 +0200337 vcclick.apply();
Akron04671e72017-05-11 20:47:32 +0200338 };
Nils Diewald58141332015-04-07 16:18:45 +0000339 };
340
Akron19d97fe2016-09-06 20:47:05 +0200341
Nils Diewald58141332015-04-07 16:18:45 +0000342 /**
343 * Init Tutorial view
344 */
Akron0b489ad2018-02-02 16:49:32 +0100345 if (d.getElementById('view-tutorial')) {
Nils Diewaldfccfbcb2015-04-29 20:48:19 +0000346 window.tutorial = tutClass.create(
Akron0b489ad2018-02-02 16:49:32 +0100347 d.getElementById('view-tutorial'),
Akronf8035592018-05-24 20:40:51 +0200348 KorAP.session
Nils Diewaldfccfbcb2015-04-29 20:48:19 +0000349 );
350 obj.tutorial = window.tutorial;
351 }
Nils Diewald58141332015-04-07 16:18:45 +0000352
Nils Diewaldfccfbcb2015-04-29 20:48:19 +0000353 // Tutorial is in parent
354 else if (window.parent) {
355 obj.tutorial = window.parent.tutorial;
356 };
357
Akron0b489ad2018-02-02 16:49:32 +0100358 // Initialize queries for d
Akron6ed13992016-05-23 18:06:05 +0200359 if (obj.tutorial) {
Akron0b489ad2018-02-02 16:49:32 +0100360 obj.tutorial.initQueries(d);
Nils Diewaldfccfbcb2015-04-29 20:48:19 +0000361
Akron6ed13992016-05-23 18:06:05 +0200362 // Initialize documentation links
Akron0b489ad2018-02-02 16:49:32 +0100363 obj.tutorial.initDocLinks(d);
Akron6ed13992016-05-23 18:06:05 +0200364 };
Nils Diewald61e6ff52015-05-07 17:26:50 +0000365
Nils Diewald845282c2015-05-14 07:53:03 +0000366
Nils Diewald58141332015-04-07 16:18:45 +0000367 /**
Akronc1457bf2015-06-11 19:24:00 +0200368 * Add VC creation on submission.
369 */
Akron0b489ad2018-02-02 16:49:32 +0100370 var form = d.getElementById('searchform');
Akron792f58b2015-07-08 18:59:36 +0200371 if (form !== null) {
Akronc1457bf2015-06-11 19:24:00 +0200372 form.addEventListener('submit', function (e) {
Akron0b489ad2018-02-02 16:49:32 +0100373 var qf = d.getElementById('q-field');
Akron1be6c1c2020-01-07 15:29:58 +0100374
Akron19d97fe2016-09-06 20:47:05 +0200375 // No query was defined
376 if (qf.value === undefined || qf.value === '') {
377 qf.focus();
378 e.halt();
379 KorAP.log(700, "No query given");
380 return;
381 };
Akron1be6c1c2020-01-07 15:29:58 +0100382
Akron19d97fe2016-09-06 20:47:05 +0200383 // Store session information
Akronf8035592018-05-24 20:40:51 +0200384 KorAP.session.set("show", show);
Akron7716f012015-07-01 20:38:32 +0200385
Akron19d97fe2016-09-06 20:47:05 +0200386 if (vc !== undefined) {
387 input.value = vc.toQuery();
Akrond7ad9072019-12-09 07:08:20 +0100388 if (input.value == '')
389 input.removeAttribute('name');
Akron19d97fe2016-09-06 20:47:05 +0200390 }
391 else {
Akrond7ad9072019-12-09 07:08:20 +0100392 input.removeAttribute('value');
393 input.removeAttribute('name');
Akron19d97fe2016-09-06 20:47:05 +0200394 };
Akron1be6c1c2020-01-07 15:29:58 +0100395
396 // This would preferably set the query to be "disabled",
397 // but in that case the query wouldn't be submitted
398 // at all.
399 // Setting the cursor to "progress" fails in current versions
400 // of webkit.
401 qf.classList.add("loading");
402 d.getElementById('qsubmit').classList.add("loading");
Akronc1457bf2015-06-11 19:24:00 +0200403 });
404 };
hebasta5df796f2019-05-21 15:27:12 +0200405
406
407 //Starts the guided tour at the next page
408 if(KorAP.session.get("tour")){
409 tourClass.gTshowResults().start();
410 }
411
Akronc1457bf2015-06-11 19:24:00 +0200412 /**
Nils Diewald58141332015-04-07 16:18:45 +0000413 * Init hint helper
414 * has to be final because of
415 * reposition
416 */
Nils Diewald0e6992a2015-04-14 20:13:52 +0000417 // Todo: Pass an element, so this works with
418 // tutorial pages as well!
Akron00cd4d12016-05-31 21:01:11 +0200419 if (obj.hint === undefined)
420 obj.hint = hintClass.create();
Nils Diewald7148c6f2015-05-04 15:07:53 +0000421
Akron99713ef2017-06-28 18:19:28 +0200422 // Add the hinthelper to the KorAP object to make it manipulatable globally
Akron72f73572017-12-05 12:31:09 +0100423 KorAP.Hint = obj.hint;
Akron99713ef2017-06-28 18:19:28 +0200424
Akron2d0d96d2019-11-18 19:49:50 +0100425
426 /**
427 * Add query panel
428 */
429 var queryPanel = queryPanelClass.create();
430
431 // Get input field
432 var sform = d.getElementById("searchform");
433 var vcView = d.getElementById('vc-view')
434 if (sform && vcView) {
435 // The views are below the query bar
436 sform.insertBefore(queryPanel.element(), vcView);
Akron2d0d96d2019-11-18 19:49:50 +0100437 KorAP.Panel['query'] = queryPanel;
438 }
Akron24f48ea2020-07-01 09:37:19 +0200439
Akrona9c55802021-06-15 11:41:29 +0200440
441 /**
442 * Initialize password toggle.
443 */
444 initCopyToClipboard(d);
445
446
Akron24f48ea2020-07-01 09:37:19 +0200447 /**
Akron116eace2021-06-14 18:02:37 +0200448 * Initialize password toggle.
449 */
Akron1cfde272021-06-14 18:32:39 +0200450 initTogglePwdVisibility(d);
Akron116eace2021-06-14 18:02:37 +0200451
452 /**
Akron24f48ea2020-07-01 09:37:19 +0200453 * Initialize Plugin registry.
454 */
Akron8dda1c62021-01-20 10:27:32 +0100455 let pe;
456 if (pe = d.getElementById("kalamar-plugins")) {
457 let url = pe.getAttribute('data-plugins');
458 if (url !== undefined) {
459 KorAP.API.getPluginList(url, function (json) {
460 if (json && json.length > 0) {
461 // Load Plugin Server first
462 KorAP.Plugin = pluginClass.create();
Akron24f48ea2020-07-01 09:37:19 +0200463
Akron8dda1c62021-01-20 10:27:32 +0100464 // Add services container to head
465 d.head.appendChild(KorAP.Plugin.element());
Akron24f48ea2020-07-01 09:37:19 +0200466
Akron8dda1c62021-01-20 10:27:32 +0100467 // Add pipe form
468 KorAP.Pipe = pipeClass.create();
469 d.getElementById("searchform").appendChild(KorAP.Pipe.element());
470
471 try {
472
473 // Register all plugins
474 json.forEach(i => KorAP.Plugin.register(i));
475 }
476 catch (e) {
477 KorAP.log(0, e);
478 }
479 }
480 });
481 };
Akron24f48ea2020-07-01 09:37:19 +0200482 };
Akron8dda1c62021-01-20 10:27:32 +0100483
Nils Diewald58141332015-04-07 16:18:45 +0000484 return obj;
Nils Diewald0e6992a2015-04-14 20:13:52 +0000485 });
hebasta75cfca52019-02-19 13:15:27 +0100486
Nils Diewald0e6992a2015-04-14 20:13:52 +0000487});