blob: 1e9a805eff8bbb5565c99677399dd909280cff10 [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',
Akronda32e7a2021-11-16 17:28:57 +010028 'state/manager',
Akron6bb71582016-06-10 20:41:08 +020029 'selectMenu',
Akron5cb9b2b2018-07-24 17:01:09 +020030 'panel/result',
Akron2d0d96d2019-11-18 19:49:50 +010031 'panel/query',
Akron644ad9f2021-07-26 16:12:59 +020032 'panel/pagination',
hebasta75cfca52019-02-19 13:15:27 +010033 'tour/tours',
Akron24f48ea2020-07-01 09:37:19 +020034 'plugin/server',
35 'pipe',
Nils Diewald7148c6f2015-05-04 15:07:53 +000036 'api',
Nils Diewaldc46003b2015-05-07 15:55:35 +000037 'mailToChiffre',
Akron858cbc82019-12-05 16:53:13 +010038 'util',
39 'state'
Nils Diewald0e6992a2015-04-14 20:13:52 +000040], function (matchClass,
Akron19d97fe2016-09-06 20:47:05 +020041 hintClass,
42 vcClass,
43 tutClass,
44 domReady,
Akron19d97fe2016-09-06 20:47:05 +020045 vcArray,
46 alertifyClass,
47 sessionClass,
Akronda32e7a2021-11-16 17:28:57 +010048 stateManagerClass,
Akron4d926f12018-07-16 15:30:25 +020049 selectMenuClass,
hebasta75cfca52019-02-19 13:15:27 +010050 resultPanelClass,
Akron2d0d96d2019-11-18 19:49:50 +010051 queryPanelClass,
Akron644ad9f2021-07-26 16:12:59 +020052 paginationPanelClass,
Akron24f48ea2020-07-01 09:37:19 +020053 tourClass,
54 pluginClass,
55 pipeClass) {
Nils Diewalda0defc42015-05-07 23:54:17 +000056
Akron0b489ad2018-02-02 16:49:32 +010057 const d = document;
Akron9cc3eaf2015-06-10 22:15:52 +020058
Akronbc6b3f22021-01-13 14:53:12 +010059 // Set base URL
60 KorAP.URL = d.body.getAttribute('data-korap-url') || "";
61
62 // Get koralQuery response
63 const kqe = d.getElementById('koralQuery');
64 if (kqe !== null) {
65 KorAP.koralQuery = JSON.parse(kqe.getAttribute('data-koralquery') || "");
66 };
67
Akron0c4cd222019-07-19 16:33:34 +020068 // Create suffix if KorAP is run in a subfolder
69 KorAP.session = sessionClass.create(
70 KorAP.URL.length > 0 ? 'kalamarJS-' + KorAP.URL.slugify() : 'kalamarJS'
71 );
Akronf8035592018-05-24 20:40:51 +020072
Nils Diewalda0defc42015-05-07 23:54:17 +000073 // Override KorAP.log
74 window.alertify = alertifyClass;
Akronc0a2da82018-07-04 15:27:37 +020075 KorAP.log = function (code, msg, src) {
76
77 if (src) {
78 msg += '<code class="src">'+src+'</code>';
79 };
Nils Diewalda0defc42015-05-07 23:54:17 +000080
81 // Use alertify to log errors
82 alertifyClass.log(
Akronf55504a2015-06-18 16:42:55 +020083 (code === 0 ? '' : code + ': ') +
Akron19d97fe2016-09-06 20:47:05 +020084 msg,
Nils Diewalda0defc42015-05-07 23:54:17 +000085 'error',
Akronf55504a2015-06-18 16:42:55 +020086 10000
Nils Diewalda0defc42015-05-07 23:54:17 +000087 );
88 };
89
hebasta2758b582018-11-19 15:59:42 +010090 KorAP.vc = vcClass.create(vcArray);
Akron690066c2021-01-22 17:39:18 +010091
92 let gt;
93 if (gt = document.getElementById('link-guided-tour')) {
94 gt.setAttribute('href', '#');
95 gt.addEventListener('click', function(){
96 tourClass.gTstartSearch().start();
97 });
98
99 KorAP.tourshowR = function(){
100 tourClass.gTshowResults().start();
101 };
hebasta5df796f2019-05-21 15:27:12 +0200102 };
Akroncb5c1712021-01-26 18:01:04 +0100103
Nils Diewald0e6992a2015-04-14 20:13:52 +0000104 domReady(function (event) {
hebasta5df796f2019-05-21 15:27:12 +0200105
Nils Diewald0e6992a2015-04-14 20:13:52 +0000106 var obj = {};
Akron71b91e42016-06-01 22:12:43 +0200107
Akron4d926f12018-07-16 15:30:25 +0200108 // What should be visible in the beginning?
Akronf8035592018-05-24 20:40:51 +0200109 var show = KorAP.session.get('show') || {};
hebasta043e96f2019-11-28 12:33:00 +0100110
111 KorAP.Panel = KorAP.Panel || {}
Nils Diewalda297f062015-04-02 00:23:46 +0000112
113 /**
Akronf55504a2015-06-18 16:42:55 +0200114 * Release notifications
115 */
Akroncb5c1712021-01-26 18:01:04 +0100116 d.querySelectorAll('#notifications div.notify').forEach(
117 function(e) {
118 let msg = e.textContent;
119
120 let src = e.getAttribute('data-src');
121 if (src) {
122 msg += '<code class="src">'+src+'</code>';
Akron8ea84292018-10-24 13:41:52 +0200123 };
Akroncb5c1712021-01-26 18:01:04 +0100124
125 let type = e.getAttribute('data-type') || "error";
126 alertifyClass.log(msg, type, 10000);
127 }
128 );
Akronf55504a2015-06-18 16:42:55 +0200129
130 /**
Akroncd42a142019-07-12 18:55:37 +0200131 * Replace Virtual Corpus field
Nils Diewald7148c6f2015-05-04 15:07:53 +0000132 */
Akron5c829e92017-05-12 18:10:00 +0200133 var vcname, vcchoose;
Akroncd42a142019-07-12 18:55:37 +0200134 var input = d.getElementById('cq');
Akron1f0521b2018-08-28 13:01:24 +0200135
hebasta2758b582018-11-19 15:59:42 +0100136 var vc = KorAP.vc;
hebasta48842cf2018-12-11 12:57:38 +0100137
Akron1f0521b2018-08-28 13:01:24 +0200138 // Add vc name object
Nils Diewald7148c6f2015-05-04 15:07:53 +0000139 if (input) {
140 input.style.display = 'none';
Akron0b489ad2018-02-02 16:49:32 +0100141 vcname = d.createElement('span');
Nils Diewald7148c6f2015-05-04 15:07:53 +0000142 vcname.setAttribute('id', 'vc-choose');
Akron6bb71582016-06-10 20:41:08 +0200143 vcname.classList.add('select');
Akron941551e2015-06-11 16:06:22 +0200144
Akron1f0521b2018-08-28 13:01:24 +0200145 // Load virtual corpus object
Akroncd42a142019-07-12 18:55:37 +0200146 // Supports "collection" for legacy reasons
147 if (KorAP.koralQuery !== undefined && (KorAP.koralQuery["collection"] || KorAP.koralQuery["corpus"])) {
Akron1f0521b2018-08-28 13:01:24 +0200148 try {
Akroncd42a142019-07-12 18:55:37 +0200149 vc.fromJson(KorAP.koralQuery["collection"] || KorAP.koralQuery["corpus"]);
Akron1f0521b2018-08-28 13:01:24 +0200150 }
151 catch (e) {
152 KorAP.log(0,e);
153 }
Akron27ae9ec2015-06-23 00:43:21 +0200154 };
155
Akron0b489ad2018-02-02 16:49:32 +0100156 vcchoose = vcname.addE('span');
Akronec6bb8e2018-08-29 13:07:56 +0200157 vcchoose.addT(vc.getName());
Akron27ae9ec2015-06-23 00:43:21 +0200158
Akron1f0521b2018-08-28 13:01:24 +0200159 if (vc.wasRewritten()) {
160 vcchoose.classList.add('rewritten');
161 };
162
Nils Diewald7148c6f2015-05-04 15:07:53 +0000163 input.parentNode.insertBefore(vcname, input);
164 };
165
Nils Diewald7148c6f2015-05-04 15:07:53 +0000166 /**
Nils Diewalda297f062015-04-02 00:23:46 +0000167 * Add actions to match entries
168 */
Akronb50964a2020-10-12 11:44:37 +0200169 var matchElements = d.querySelectorAll(
Akron3c390c42020-03-30 09:06:21 +0200170 '#search > ol > li'
Nils Diewald5c5a7472015-04-02 22:13:38 +0000171 );
Akron6a535d42015-08-26 20:16:58 +0200172
Akronb50964a2020-10-12 11:44:37 +0200173 matchElements.forEach(function(e) {
Akron3c390c42020-03-30 09:06:21 +0200174
175 // Define class for active elements
176 if (e.classList.contains('active')) {
Akrond769d702021-08-16 11:09:08 +0200177 if (e._match === undefined) {
Akron19d97fe2016-09-06 20:47:05 +0200178 // lazyLoad
Akron3c390c42020-03-30 09:06:21 +0200179 matchClass.create(e).init();
Akron19d97fe2016-09-06 20:47:05 +0200180 };
Akron3c390c42020-03-30 09:06:21 +0200181 }
182
183 // Define class for inactive elements
184 else {
185 e.addEventListener('click', function (e) {
Akron19d97fe2016-09-06 20:47:05 +0200186 if (this._match !== undefined)
Akron3c390c42020-03-30 09:06:21 +0200187 this._match.open();
Akron19d97fe2016-09-06 20:47:05 +0200188 else {
189 // lazyLoad
190 matchClass.create(this).open();
191 };
Akron3c390c42020-03-30 09:06:21 +0200192 // This would prevent the sidebar to go back
193 // e.halt();
194 });
195 e.addEventListener('keydown', function (e) {
196 var code = _codeFromEvent(e);
197
198 switch (code) {
199 case 32:
200 if (this._match !== undefined)
201 this._match.toggle();
202 else {
203 // lazyLoad
204 matchClass.create(this).open();
205 };
206 e.halt();
207 break;
208 };
209 });
210 };
Akrond769d702021-08-16 11:09:08 +0200211 });
Akron3c390c42020-03-30 09:06:21 +0200212
Akrone0c32c72017-04-25 22:38:23 +0200213 // Add focus listener to aside
Akron0b489ad2018-02-02 16:49:32 +0100214 var aside = d.getElementsByTagName('aside')[0];
Akrone0c32c72017-04-25 22:38:23 +0200215
216 if (aside && aside.classList.contains('active') == false) {
Akron1885ce92017-04-26 23:10:01 +0200217
Akron5258d462017-04-26 23:32:57 +0200218 // Horrible lock to deal with sidebar clicks
219 var asideClicked = false;
220
Akron1885ce92017-04-26 23:10:01 +0200221 // Make aside active on focus
222 aside.addEventListener('focus', function(e) {
Akrone0c32c72017-04-25 22:38:23 +0200223 this.classList.add('active');
224 });
225
Akron1885ce92017-04-26 23:10:01 +0200226 // Deactivate focus when clicking anywhere else
Akron0b489ad2018-02-02 16:49:32 +0100227 var body = d.getElementsByTagName('body')[0];
Akron1885ce92017-04-26 23:10:01 +0200228 if (body !== null) {
229 body.addEventListener('click', function() {
Akron5258d462017-04-26 23:32:57 +0200230 if (!asideClicked) {
231 aside.classList.remove('active');
232 }
233 else {
234 asideClicked = false;
235 };
Akron1885ce92017-04-26 23:10:01 +0200236 });
237 };
238
239 /* Stop click event on aside
240 * (to not trickle down to body)
241 */
242 aside.addEventListener('click', function(e) {
Akron5258d462017-04-26 23:32:57 +0200243 asideClicked = true;
Akrone0c32c72017-04-25 22:38:23 +0200244 });
245 };
Akronb9cdb102017-04-25 00:52:31 +0200246
247
Akron6bb71582016-06-10 20:41:08 +0200248 // Replace QL select menus with KorAP menus
Akron0b489ad2018-02-02 16:49:32 +0100249 var qlField = d.getElementById('ql-field');
Akronaba7a5a2016-08-15 21:58:33 +0200250 if (qlField !== null) {
Akron086fe5d2017-11-13 14:01:45 +0100251 KorAP.QLmenu = selectMenuClass.create(
Akron0b489ad2018-02-02 16:49:32 +0100252 d.getElementById('ql-field').parentNode
Marc Kupietz95455822023-09-19 20:14:31 +0200253 ).limit(10);
Akronaba7a5a2016-08-15 21:58:33 +0200254 };
Akron6bb71582016-06-10 20:41:08 +0200255
Akron4d926f12018-07-16 15:30:25 +0200256 var resultInfo = d.getElementById('resultinfo');
257
Akron4d926f12018-07-16 15:30:25 +0200258 /**
259 * Add result panel
260 */
Akron5cb9b2b2018-07-24 17:01:09 +0200261 var resultPanel = resultPanelClass.create(show);
Akron644ad9f2021-07-26 16:12:59 +0200262
Akron4d926f12018-07-16 15:30:25 +0200263 if (resultInfo != null) {
Akron4d926f12018-07-16 15:30:25 +0200264
265 // Move buttons to resultinfo
Akron37ea1192021-07-28 10:40:14 +0200266 resultInfo.appendChild(resultPanel.actions().element());
Akron4d926f12018-07-16 15:30:25 +0200267
Akrone6538cd2018-07-16 17:52:33 +0200268 // The views are at the top of the search results
Akron4d926f12018-07-16 15:30:25 +0200269 var sb = d.getElementById('search');
270 sb.insertBefore(resultPanel.element(), sb.firstChild);
Akron4d926f12018-07-16 15:30:25 +0200271 };
272
273
Akron179c8ac2015-06-30 19:30:50 +0200274 // There is a koralQuery
Akron4d926f12018-07-16 15:30:25 +0200275 if (KorAP.koralQuery !== undefined) {
Akron5cb9b2b2018-07-24 17:01:09 +0200276
277 // Add KoralQuery view to result panel
Akron4d926f12018-07-16 15:30:25 +0200278 if (resultInfo !== null) {
Akron5cb9b2b2018-07-24 17:01:09 +0200279 resultPanel.addKqAction()
Akron179c8ac2015-06-30 19:30:50 +0200280 };
Akron7716f012015-07-01 20:38:32 +0200281
Akron00cd4d12016-05-31 21:01:11 +0200282 if (KorAP.koralQuery["errors"]) {
Akron678c26f2020-10-09 08:52:50 +0200283 KorAP.koralQuery["errors"].forEach(function(e) {
Akronf0c31ed2016-06-11 11:27:01 +0200284
Akron19d97fe2016-09-06 20:47:05 +0200285 // Malformed query
Akron4a24b722020-10-13 12:44:25 +0200286 if (e[0] === 302 && e[2] !== undefined) {
Akron19d97fe2016-09-06 20:47:05 +0200287 obj.hint = hintClass.create();
Akron678c26f2020-10-09 08:52:50 +0200288 obj.hint.alert(e[2], e[1]);
Akron19d97fe2016-09-06 20:47:05 +0200289 }
Akronf0c31ed2016-06-11 11:27:01 +0200290
Akron19d97fe2016-09-06 20:47:05 +0200291 // no query
Akron678c26f2020-10-09 08:52:50 +0200292 else if (e[0] === 301) {
Akron19d97fe2016-09-06 20:47:05 +0200293 obj.hint = hintClass.create();
Akron678c26f2020-10-09 08:52:50 +0200294 obj.hint.alert(0, e[1]);
Akron19d97fe2016-09-06 20:47:05 +0200295 }
Akron678c26f2020-10-09 08:52:50 +0200296 });
Akron00cd4d12016-05-31 21:01:11 +0200297 };
Akron179c8ac2015-06-30 19:30:50 +0200298 };
299
Akron5cb9b2b2018-07-24 17:01:09 +0200300
301 /*
302 * There is more than 0 matches, so allow for
303 * alignment toggling (left <=> right)
304 */
Akronb50964a2020-10-12 11:44:37 +0200305 if (matchElements.length > 0)
Akron5cb9b2b2018-07-24 17:01:09 +0200306 resultPanel.addAlignAction();
Nils Diewald7148c6f2015-05-04 15:07:53 +0000307
hebasta043e96f2019-11-28 12:33:00 +0100308 KorAP.Panel['result'] = resultPanel;
Akron5cb9b2b2018-07-24 17:01:09 +0200309 /*
Akroncd42a142019-07-12 18:55:37 +0200310 * Toggle the Virtual Corpus builder
Nils Diewald7148c6f2015-05-04 15:07:53 +0000311 */
312 if (vcname) {
Akronec6bb8e2018-08-29 13:07:56 +0200313 vc.onMinimize = function () {
314 vcname.classList.remove('active');
Akroncd42a142019-07-12 18:55:37 +0200315 delete show['vc'];
Akronec6bb8e2018-08-29 13:07:56 +0200316 };
Nils Diewald6283d692015-04-23 20:32:53 +0000317
Akronec6bb8e2018-08-29 13:07:56 +0200318 vc.onOpen = function () {
319 vcname.classList.add('active');
Akroncfe8ecc2018-11-20 18:46:16 +0100320
321 var view = d.getElementById('vc-view');
322 if (!view.firstChild)
323 view.appendChild(this.element());
324
Akroncd42a142019-07-12 18:55:37 +0200325 show['vc'] = true;
Akronec6bb8e2018-08-29 13:07:56 +0200326 };
327
328 var vcclick = function () {
Akronec6bb8e2018-08-29 13:07:56 +0200329 if (vc.isOpen()) {
330 vc.minimize()
331 }
332 else {
Akronec6bb8e2018-08-29 13:07:56 +0200333 vc.open();
Akron19d97fe2016-09-06 20:47:05 +0200334 };
Nils Diewald58141332015-04-07 16:18:45 +0000335 };
Akron04671e72017-05-11 20:47:32 +0200336
Akron179c8ac2015-06-30 19:30:50 +0200337 vcname.onclick = vcclick;
Akron5c829e92017-05-12 18:10:00 +0200338
339 // Click, if the VC should be shown
Akroncd42a142019-07-12 18:55:37 +0200340 if (show['vc']) {
Akron19d97fe2016-09-06 20:47:05 +0200341 vcclick.apply();
Akron04671e72017-05-11 20:47:32 +0200342 };
Nils Diewald58141332015-04-07 16:18:45 +0000343 };
344
Akron19d97fe2016-09-06 20:47:05 +0200345
Nils Diewald58141332015-04-07 16:18:45 +0000346 /**
347 * Init Tutorial view
348 */
Akron0b489ad2018-02-02 16:49:32 +0100349 if (d.getElementById('view-tutorial')) {
Nils Diewaldfccfbcb2015-04-29 20:48:19 +0000350 window.tutorial = tutClass.create(
Akron0b489ad2018-02-02 16:49:32 +0100351 d.getElementById('view-tutorial'),
Akronf8035592018-05-24 20:40:51 +0200352 KorAP.session
Nils Diewaldfccfbcb2015-04-29 20:48:19 +0000353 );
354 obj.tutorial = window.tutorial;
355 }
Nils Diewald58141332015-04-07 16:18:45 +0000356
Nils Diewaldfccfbcb2015-04-29 20:48:19 +0000357 // Tutorial is in parent
358 else if (window.parent) {
359 obj.tutorial = window.parent.tutorial;
360 };
361
Akron0b489ad2018-02-02 16:49:32 +0100362 // Initialize queries for d
Akron6ed13992016-05-23 18:06:05 +0200363 if (obj.tutorial) {
Akron0b489ad2018-02-02 16:49:32 +0100364 obj.tutorial.initQueries(d);
Nils Diewaldfccfbcb2015-04-29 20:48:19 +0000365
Akron6ed13992016-05-23 18:06:05 +0200366 // Initialize documentation links
Akron0b489ad2018-02-02 16:49:32 +0100367 obj.tutorial.initDocLinks(d);
Akron6ed13992016-05-23 18:06:05 +0200368 };
Nils Diewald61e6ff52015-05-07 17:26:50 +0000369
Nils Diewald845282c2015-05-14 07:53:03 +0000370
Nils Diewald58141332015-04-07 16:18:45 +0000371 /**
Akronc1457bf2015-06-11 19:24:00 +0200372 * Add VC creation on submission.
373 */
Akron0b489ad2018-02-02 16:49:32 +0100374 var form = d.getElementById('searchform');
Akron792f58b2015-07-08 18:59:36 +0200375 if (form !== null) {
Akronc1457bf2015-06-11 19:24:00 +0200376 form.addEventListener('submit', function (e) {
Akron0b489ad2018-02-02 16:49:32 +0100377 var qf = d.getElementById('q-field');
Akron1be6c1c2020-01-07 15:29:58 +0100378
Akron19d97fe2016-09-06 20:47:05 +0200379 // No query was defined
380 if (qf.value === undefined || qf.value === '') {
381 qf.focus();
382 e.halt();
383 KorAP.log(700, "No query given");
384 return;
385 };
Akron1be6c1c2020-01-07 15:29:58 +0100386
Akron19d97fe2016-09-06 20:47:05 +0200387 // Store session information
Akronf8035592018-05-24 20:40:51 +0200388 KorAP.session.set("show", show);
Akron7716f012015-07-01 20:38:32 +0200389
Akron19d97fe2016-09-06 20:47:05 +0200390 if (vc !== undefined) {
391 input.value = vc.toQuery();
Akrond7ad9072019-12-09 07:08:20 +0100392 if (input.value == '')
393 input.removeAttribute('name');
Akron19d97fe2016-09-06 20:47:05 +0200394 }
395 else {
Akrond7ad9072019-12-09 07:08:20 +0100396 input.removeAttribute('value');
397 input.removeAttribute('name');
Akron19d97fe2016-09-06 20:47:05 +0200398 };
Akron1be6c1c2020-01-07 15:29:58 +0100399
400 // This would preferably set the query to be "disabled",
401 // but in that case the query wouldn't be submitted
402 // at all.
403 // Setting the cursor to "progress" fails in current versions
404 // of webkit.
405 qf.classList.add("loading");
406 d.getElementById('qsubmit').classList.add("loading");
Akronc1457bf2015-06-11 19:24:00 +0200407 });
408 };
hebasta5df796f2019-05-21 15:27:12 +0200409
410
411 //Starts the guided tour at the next page
412 if(KorAP.session.get("tour")){
413 tourClass.gTshowResults().start();
414 }
415
Akronc1457bf2015-06-11 19:24:00 +0200416 /**
Nils Diewald58141332015-04-07 16:18:45 +0000417 * Init hint helper
418 * has to be final because of
419 * reposition
420 */
Nils Diewald0e6992a2015-04-14 20:13:52 +0000421 // Todo: Pass an element, so this works with
422 // tutorial pages as well!
Akron00cd4d12016-05-31 21:01:11 +0200423 if (obj.hint === undefined)
424 obj.hint = hintClass.create();
Nils Diewald7148c6f2015-05-04 15:07:53 +0000425
Akron99713ef2017-06-28 18:19:28 +0200426 // Add the hinthelper to the KorAP object to make it manipulatable globally
Akron72f73572017-12-05 12:31:09 +0100427 KorAP.Hint = obj.hint;
Akron99713ef2017-06-28 18:19:28 +0200428
Akron2d0d96d2019-11-18 19:49:50 +0100429
430 /**
431 * Add query panel
432 */
433 var queryPanel = queryPanelClass.create();
434
435 // Get input field
Akron2d0d96d2019-11-18 19:49:50 +0100436 var vcView = d.getElementById('vc-view')
Akron96b97d62023-11-07 15:56:54 +0100437 if (form && vcView) {
Akron2d0d96d2019-11-18 19:49:50 +0100438 // The views are below the query bar
Akron96b97d62023-11-07 15:56:54 +0100439 form.insertBefore(queryPanel.element(), vcView);
Akron2d0d96d2019-11-18 19:49:50 +0100440 KorAP.Panel['query'] = queryPanel;
Akron644ad9f2021-07-26 16:12:59 +0200441 };
442
443
444 /**
445 * Add pagination panel
446 */
447 const paginationPanel = paginationPanelClass.create();
448
449 if (paginationPanel) {
450 paginationPanel.addRandomPage();
451 KorAP.Panel['pagination'] = paginationPanel;
452 };
Akron24f48ea2020-07-01 09:37:19 +0200453
Akrona9c55802021-06-15 11:41:29 +0200454
455 /**
456 * Initialize password toggle.
457 */
458 initCopyToClipboard(d);
459
460
Akron24f48ea2020-07-01 09:37:19 +0200461 /**
Akron116eace2021-06-14 18:02:37 +0200462 * Initialize password toggle.
463 */
Akron1cfde272021-06-14 18:32:39 +0200464 initTogglePwdVisibility(d);
Akron116eace2021-06-14 18:02:37 +0200465
466 /**
Akron24f48ea2020-07-01 09:37:19 +0200467 * Initialize Plugin registry.
468 */
Akron8dda1c62021-01-20 10:27:32 +0100469 let pe;
470 if (pe = d.getElementById("kalamar-plugins")) {
471 let url = pe.getAttribute('data-plugins');
472 if (url !== undefined) {
473 KorAP.API.getPluginList(url, function (json) {
474 if (json && json.length > 0) {
Akronda32e7a2021-11-16 17:28:57 +0100475
476 // Add state manager
Akron96b97d62023-11-07 15:56:54 +0100477 form = d.getElementById("searchform");
478 if (!form) {
479 return;
480 };
481
482 const input = form.addE("input");
Akronda32e7a2021-11-16 17:28:57 +0100483 input.setAttribute("name","state");
484 KorAP.States = stateManagerClass.create(input);
485
Akron8dda1c62021-01-20 10:27:32 +0100486 // Load Plugin Server first
487 KorAP.Plugin = pluginClass.create();
Akron24f48ea2020-07-01 09:37:19 +0200488
Akron8dda1c62021-01-20 10:27:32 +0100489 // Add services container to head
490 d.head.appendChild(KorAP.Plugin.element());
Akron24f48ea2020-07-01 09:37:19 +0200491
Akron8dda1c62021-01-20 10:27:32 +0100492 // Add pipe form
493 KorAP.Pipe = pipeClass.create();
494 d.getElementById("searchform").appendChild(KorAP.Pipe.element());
Akronda32e7a2021-11-16 17:28:57 +0100495
Akron8dda1c62021-01-20 10:27:32 +0100496 try {
497
498 // Register all plugins
499 json.forEach(i => KorAP.Plugin.register(i));
500 }
501 catch (e) {
502 KorAP.log(0, e);
503 }
504 }
505 });
506 };
Akron24f48ea2020-07-01 09:37:19 +0200507 };
Akron8dda1c62021-01-20 10:27:32 +0100508
Nils Diewald58141332015-04-07 16:18:45 +0000509 return obj;
Nils Diewald0e6992a2015-04-14 20:13:52 +0000510 });
hebasta75cfca52019-02-19 13:15:27 +0100511
Nils Diewald0e6992a2015-04-14 20:13:52 +0000512});