blob: 724cfb3e2d70057ccb8bce2e55088d9c8b9ed134 [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',
Akron644ad9f2021-07-26 16:12:59 +020031 'panel/pagination',
hebasta75cfca52019-02-19 13:15:27 +010032 'tour/tours',
Akron24f48ea2020-07-01 09:37:19 +020033 'plugin/server',
34 'pipe',
Nils Diewald7148c6f2015-05-04 15:07:53 +000035 'api',
Nils Diewaldc46003b2015-05-07 15:55:35 +000036 'mailToChiffre',
Akron858cbc82019-12-05 16:53:13 +010037 'util',
38 'state'
Nils Diewald0e6992a2015-04-14 20:13:52 +000039], function (matchClass,
Akron19d97fe2016-09-06 20:47:05 +020040 hintClass,
41 vcClass,
42 tutClass,
43 domReady,
Akron19d97fe2016-09-06 20:47:05 +020044 vcArray,
45 alertifyClass,
46 sessionClass,
Akron4d926f12018-07-16 15:30:25 +020047 selectMenuClass,
hebasta75cfca52019-02-19 13:15:27 +010048 resultPanelClass,
Akron2d0d96d2019-11-18 19:49:50 +010049 queryPanelClass,
Akron644ad9f2021-07-26 16:12:59 +020050 paginationPanelClass,
Akron24f48ea2020-07-01 09:37:19 +020051 tourClass,
52 pluginClass,
53 pipeClass) {
Nils Diewalda0defc42015-05-07 23:54:17 +000054
Akron0b489ad2018-02-02 16:49:32 +010055 const d = document;
Akron9cc3eaf2015-06-10 22:15:52 +020056
Akronbc6b3f22021-01-13 14:53:12 +010057 // Set base URL
58 KorAP.URL = d.body.getAttribute('data-korap-url') || "";
59
60 // Get koralQuery response
61 const kqe = d.getElementById('koralQuery');
62 if (kqe !== null) {
63 KorAP.koralQuery = JSON.parse(kqe.getAttribute('data-koralquery') || "");
64 };
65
Akron0c4cd222019-07-19 16:33:34 +020066 // Create suffix if KorAP is run in a subfolder
67 KorAP.session = sessionClass.create(
68 KorAP.URL.length > 0 ? 'kalamarJS-' + KorAP.URL.slugify() : 'kalamarJS'
69 );
Akronf8035592018-05-24 20:40:51 +020070
Nils Diewalda0defc42015-05-07 23:54:17 +000071 // Override KorAP.log
72 window.alertify = alertifyClass;
Akronc0a2da82018-07-04 15:27:37 +020073 KorAP.log = function (code, msg, src) {
74
75 if (src) {
76 msg += '<code class="src">'+src+'</code>';
77 };
Nils Diewalda0defc42015-05-07 23:54:17 +000078
79 // Use alertify to log errors
80 alertifyClass.log(
Akronf55504a2015-06-18 16:42:55 +020081 (code === 0 ? '' : code + ': ') +
Akron19d97fe2016-09-06 20:47:05 +020082 msg,
Nils Diewalda0defc42015-05-07 23:54:17 +000083 'error',
Akronf55504a2015-06-18 16:42:55 +020084 10000
Nils Diewalda0defc42015-05-07 23:54:17 +000085 );
86 };
87
hebasta2758b582018-11-19 15:59:42 +010088 KorAP.vc = vcClass.create(vcArray);
Akron690066c2021-01-22 17:39:18 +010089
90 let gt;
91 if (gt = document.getElementById('link-guided-tour')) {
92 gt.setAttribute('href', '#');
93 gt.addEventListener('click', function(){
94 tourClass.gTstartSearch().start();
95 });
96
97 KorAP.tourshowR = function(){
98 tourClass.gTshowResults().start();
99 };
hebasta5df796f2019-05-21 15:27:12 +0200100 };
Akroncb5c1712021-01-26 18:01:04 +0100101
Nils Diewald0e6992a2015-04-14 20:13:52 +0000102 domReady(function (event) {
hebasta5df796f2019-05-21 15:27:12 +0200103
Nils Diewald0e6992a2015-04-14 20:13:52 +0000104 var obj = {};
Akron71b91e42016-06-01 22:12:43 +0200105
Akron4d926f12018-07-16 15:30:25 +0200106 // What should be visible in the beginning?
Akronf8035592018-05-24 20:40:51 +0200107 var show = KorAP.session.get('show') || {};
hebasta043e96f2019-11-28 12:33:00 +0100108
109 KorAP.Panel = KorAP.Panel || {}
Nils Diewalda297f062015-04-02 00:23:46 +0000110
111 /**
Akronf55504a2015-06-18 16:42:55 +0200112 * Release notifications
113 */
Akroncb5c1712021-01-26 18:01:04 +0100114 d.querySelectorAll('#notifications div.notify').forEach(
115 function(e) {
116 let msg = e.textContent;
117
118 let src = e.getAttribute('data-src');
119 if (src) {
120 msg += '<code class="src">'+src+'</code>';
Akron8ea84292018-10-24 13:41:52 +0200121 };
Akroncb5c1712021-01-26 18:01:04 +0100122
123 let type = e.getAttribute('data-type') || "error";
124 alertifyClass.log(msg, type, 10000);
125 }
126 );
Akronf55504a2015-06-18 16:42:55 +0200127
128 /**
Akroncd42a142019-07-12 18:55:37 +0200129 * Replace Virtual Corpus field
Nils Diewald7148c6f2015-05-04 15:07:53 +0000130 */
Akron5c829e92017-05-12 18:10:00 +0200131 var vcname, vcchoose;
Akroncd42a142019-07-12 18:55:37 +0200132 var input = d.getElementById('cq');
Akron1f0521b2018-08-28 13:01:24 +0200133
hebasta2758b582018-11-19 15:59:42 +0100134 var vc = KorAP.vc;
hebasta48842cf2018-12-11 12:57:38 +0100135
Akron1f0521b2018-08-28 13:01:24 +0200136 // Add vc name object
Nils Diewald7148c6f2015-05-04 15:07:53 +0000137 if (input) {
138 input.style.display = 'none';
Akron0b489ad2018-02-02 16:49:32 +0100139 vcname = d.createElement('span');
Nils Diewald7148c6f2015-05-04 15:07:53 +0000140 vcname.setAttribute('id', 'vc-choose');
Akron6bb71582016-06-10 20:41:08 +0200141 vcname.classList.add('select');
Akron941551e2015-06-11 16:06:22 +0200142
Akron1f0521b2018-08-28 13:01:24 +0200143 // Load virtual corpus object
Akroncd42a142019-07-12 18:55:37 +0200144 // Supports "collection" for legacy reasons
145 if (KorAP.koralQuery !== undefined && (KorAP.koralQuery["collection"] || KorAP.koralQuery["corpus"])) {
Akron1f0521b2018-08-28 13:01:24 +0200146 try {
Akroncd42a142019-07-12 18:55:37 +0200147 vc.fromJson(KorAP.koralQuery["collection"] || KorAP.koralQuery["corpus"]);
Akron1f0521b2018-08-28 13:01:24 +0200148 }
149 catch (e) {
150 KorAP.log(0,e);
151 }
Akron27ae9ec2015-06-23 00:43:21 +0200152 };
153
Akron0b489ad2018-02-02 16:49:32 +0100154 vcchoose = vcname.addE('span');
Akronec6bb8e2018-08-29 13:07:56 +0200155 vcchoose.addT(vc.getName());
Akron27ae9ec2015-06-23 00:43:21 +0200156
Akron1f0521b2018-08-28 13:01:24 +0200157 if (vc.wasRewritten()) {
158 vcchoose.classList.add('rewritten');
159 };
160
Nils Diewald7148c6f2015-05-04 15:07:53 +0000161 input.parentNode.insertBefore(vcname, input);
162 };
163
Nils Diewald7148c6f2015-05-04 15:07:53 +0000164 /**
Nils Diewalda297f062015-04-02 00:23:46 +0000165 * Add actions to match entries
166 */
Akronb50964a2020-10-12 11:44:37 +0200167 var matchElements = d.querySelectorAll(
Akron3c390c42020-03-30 09:06:21 +0200168 '#search > ol > li'
Nils Diewald5c5a7472015-04-02 22:13:38 +0000169 );
Akron6a535d42015-08-26 20:16:58 +0200170
Akronb50964a2020-10-12 11:44:37 +0200171 matchElements.forEach(function(e) {
Akron3c390c42020-03-30 09:06:21 +0200172
173 // Define class for active elements
174 if (e.classList.contains('active')) {
Akrond769d702021-08-16 11:09:08 +0200175 if (e._match === undefined) {
Akron19d97fe2016-09-06 20:47:05 +0200176 // lazyLoad
Akron3c390c42020-03-30 09:06:21 +0200177 matchClass.create(e).init();
Akron19d97fe2016-09-06 20:47:05 +0200178 };
Akron3c390c42020-03-30 09:06:21 +0200179 }
180
181 // Define class for inactive elements
182 else {
183 e.addEventListener('click', function (e) {
Akron19d97fe2016-09-06 20:47:05 +0200184 if (this._match !== undefined)
Akron3c390c42020-03-30 09:06:21 +0200185 this._match.open();
Akron19d97fe2016-09-06 20:47:05 +0200186 else {
187 // lazyLoad
188 matchClass.create(this).open();
189 };
Akron3c390c42020-03-30 09:06:21 +0200190 // This would prevent the sidebar to go back
191 // e.halt();
192 });
193 e.addEventListener('keydown', function (e) {
194 var code = _codeFromEvent(e);
195
196 switch (code) {
197 case 32:
198 if (this._match !== undefined)
199 this._match.toggle();
200 else {
201 // lazyLoad
202 matchClass.create(this).open();
203 };
204 e.halt();
205 break;
206 };
207 });
208 };
Akrond769d702021-08-16 11:09:08 +0200209 });
Akron3c390c42020-03-30 09:06:21 +0200210
Akrone0c32c72017-04-25 22:38:23 +0200211 // Add focus listener to aside
Akron0b489ad2018-02-02 16:49:32 +0100212 var aside = d.getElementsByTagName('aside')[0];
Akrone0c32c72017-04-25 22:38:23 +0200213
214 if (aside && aside.classList.contains('active') == false) {
Akron1885ce92017-04-26 23:10:01 +0200215
Akron5258d462017-04-26 23:32:57 +0200216 // Horrible lock to deal with sidebar clicks
217 var asideClicked = false;
218
Akron1885ce92017-04-26 23:10:01 +0200219 // Make aside active on focus
220 aside.addEventListener('focus', function(e) {
Akrone0c32c72017-04-25 22:38:23 +0200221 this.classList.add('active');
222 });
223
Akron1885ce92017-04-26 23:10:01 +0200224 // Deactivate focus when clicking anywhere else
Akron0b489ad2018-02-02 16:49:32 +0100225 var body = d.getElementsByTagName('body')[0];
Akron1885ce92017-04-26 23:10:01 +0200226 if (body !== null) {
227 body.addEventListener('click', function() {
Akron5258d462017-04-26 23:32:57 +0200228 if (!asideClicked) {
229 aside.classList.remove('active');
230 }
231 else {
232 asideClicked = false;
233 };
Akron1885ce92017-04-26 23:10:01 +0200234 });
235 };
236
237 /* Stop click event on aside
238 * (to not trickle down to body)
239 */
240 aside.addEventListener('click', function(e) {
Akron5258d462017-04-26 23:32:57 +0200241 asideClicked = true;
Akrone0c32c72017-04-25 22:38:23 +0200242 });
243 };
Akronb9cdb102017-04-25 00:52:31 +0200244
245
Akron6bb71582016-06-10 20:41:08 +0200246 // Replace QL select menus with KorAP menus
Akron0b489ad2018-02-02 16:49:32 +0100247 var qlField = d.getElementById('ql-field');
Akronaba7a5a2016-08-15 21:58:33 +0200248 if (qlField !== null) {
Akron086fe5d2017-11-13 14:01:45 +0100249 KorAP.QLmenu = selectMenuClass.create(
Akron0b489ad2018-02-02 16:49:32 +0100250 d.getElementById('ql-field').parentNode
Akronaba7a5a2016-08-15 21:58:33 +0200251 ).limit(5);
252 };
Akron6bb71582016-06-10 20:41:08 +0200253
Akron4d926f12018-07-16 15:30:25 +0200254 var resultInfo = d.getElementById('resultinfo');
255
Akron4d926f12018-07-16 15:30:25 +0200256 /**
257 * Add result panel
258 */
Akron5cb9b2b2018-07-24 17:01:09 +0200259 var resultPanel = resultPanelClass.create(show);
Akron644ad9f2021-07-26 16:12:59 +0200260
Akron4d926f12018-07-16 15:30:25 +0200261 if (resultInfo != null) {
Akron4d926f12018-07-16 15:30:25 +0200262
263 // Move buttons to resultinfo
Akron37ea1192021-07-28 10:40:14 +0200264 resultInfo.appendChild(resultPanel.actions().element());
Akron4d926f12018-07-16 15:30:25 +0200265
Akrone6538cd2018-07-16 17:52:33 +0200266 // The views are at the top of the search results
Akron4d926f12018-07-16 15:30:25 +0200267 var sb = d.getElementById('search');
268 sb.insertBefore(resultPanel.element(), sb.firstChild);
Akron4d926f12018-07-16 15:30:25 +0200269 };
270
271
Akron179c8ac2015-06-30 19:30:50 +0200272 // There is a koralQuery
Akron4d926f12018-07-16 15:30:25 +0200273 if (KorAP.koralQuery !== undefined) {
Akron5cb9b2b2018-07-24 17:01:09 +0200274
275 // Add KoralQuery view to result panel
Akron4d926f12018-07-16 15:30:25 +0200276 if (resultInfo !== null) {
Akron5cb9b2b2018-07-24 17:01:09 +0200277 resultPanel.addKqAction()
Akron179c8ac2015-06-30 19:30:50 +0200278 };
Akron7716f012015-07-01 20:38:32 +0200279
Akron00cd4d12016-05-31 21:01:11 +0200280 if (KorAP.koralQuery["errors"]) {
Akron678c26f2020-10-09 08:52:50 +0200281 KorAP.koralQuery["errors"].forEach(function(e) {
Akronf0c31ed2016-06-11 11:27:01 +0200282
Akron19d97fe2016-09-06 20:47:05 +0200283 // Malformed query
Akron4a24b722020-10-13 12:44:25 +0200284 if (e[0] === 302 && e[2] !== undefined) {
Akron19d97fe2016-09-06 20:47:05 +0200285 obj.hint = hintClass.create();
Akron678c26f2020-10-09 08:52:50 +0200286 obj.hint.alert(e[2], e[1]);
Akron19d97fe2016-09-06 20:47:05 +0200287 }
Akronf0c31ed2016-06-11 11:27:01 +0200288
Akron19d97fe2016-09-06 20:47:05 +0200289 // no query
Akron678c26f2020-10-09 08:52:50 +0200290 else if (e[0] === 301) {
Akron19d97fe2016-09-06 20:47:05 +0200291 obj.hint = hintClass.create();
Akron678c26f2020-10-09 08:52:50 +0200292 obj.hint.alert(0, e[1]);
Akron19d97fe2016-09-06 20:47:05 +0200293 }
Akron678c26f2020-10-09 08:52:50 +0200294 });
Akron00cd4d12016-05-31 21:01:11 +0200295 };
Akron179c8ac2015-06-30 19:30:50 +0200296 };
297
Akron5cb9b2b2018-07-24 17:01:09 +0200298
299 /*
300 * There is more than 0 matches, so allow for
301 * alignment toggling (left <=> right)
302 */
Akronb50964a2020-10-12 11:44:37 +0200303 if (matchElements.length > 0)
Akron5cb9b2b2018-07-24 17:01:09 +0200304 resultPanel.addAlignAction();
Nils Diewald7148c6f2015-05-04 15:07:53 +0000305
hebasta043e96f2019-11-28 12:33:00 +0100306 KorAP.Panel['result'] = resultPanel;
Akron5cb9b2b2018-07-24 17:01:09 +0200307 /*
Akroncd42a142019-07-12 18:55:37 +0200308 * Toggle the Virtual Corpus builder
Nils Diewald7148c6f2015-05-04 15:07:53 +0000309 */
310 if (vcname) {
Akronec6bb8e2018-08-29 13:07:56 +0200311 vc.onMinimize = function () {
312 vcname.classList.remove('active');
Akroncd42a142019-07-12 18:55:37 +0200313 delete show['vc'];
Akronec6bb8e2018-08-29 13:07:56 +0200314 };
Nils Diewald6283d692015-04-23 20:32:53 +0000315
Akronec6bb8e2018-08-29 13:07:56 +0200316 vc.onOpen = function () {
317 vcname.classList.add('active');
Akroncfe8ecc2018-11-20 18:46:16 +0100318
319 var view = d.getElementById('vc-view');
320 if (!view.firstChild)
321 view.appendChild(this.element());
322
Akroncd42a142019-07-12 18:55:37 +0200323 show['vc'] = true;
Akronec6bb8e2018-08-29 13:07:56 +0200324 };
325
326 var vcclick = function () {
Akronec6bb8e2018-08-29 13:07:56 +0200327 if (vc.isOpen()) {
328 vc.minimize()
329 }
330 else {
Akronec6bb8e2018-08-29 13:07:56 +0200331 vc.open();
Akron19d97fe2016-09-06 20:47:05 +0200332 };
Nils Diewald58141332015-04-07 16:18:45 +0000333 };
Akron04671e72017-05-11 20:47:32 +0200334
Akron179c8ac2015-06-30 19:30:50 +0200335 vcname.onclick = vcclick;
Akron5c829e92017-05-12 18:10:00 +0200336
337 // Click, if the VC should be shown
Akroncd42a142019-07-12 18:55:37 +0200338 if (show['vc']) {
Akron19d97fe2016-09-06 20:47:05 +0200339 vcclick.apply();
Akron04671e72017-05-11 20:47:32 +0200340 };
Nils Diewald58141332015-04-07 16:18:45 +0000341 };
342
Akron19d97fe2016-09-06 20:47:05 +0200343
Nils Diewald58141332015-04-07 16:18:45 +0000344 /**
345 * Init Tutorial view
346 */
Akron0b489ad2018-02-02 16:49:32 +0100347 if (d.getElementById('view-tutorial')) {
Nils Diewaldfccfbcb2015-04-29 20:48:19 +0000348 window.tutorial = tutClass.create(
Akron0b489ad2018-02-02 16:49:32 +0100349 d.getElementById('view-tutorial'),
Akronf8035592018-05-24 20:40:51 +0200350 KorAP.session
Nils Diewaldfccfbcb2015-04-29 20:48:19 +0000351 );
352 obj.tutorial = window.tutorial;
353 }
Nils Diewald58141332015-04-07 16:18:45 +0000354
Nils Diewaldfccfbcb2015-04-29 20:48:19 +0000355 // Tutorial is in parent
356 else if (window.parent) {
357 obj.tutorial = window.parent.tutorial;
358 };
359
Akron0b489ad2018-02-02 16:49:32 +0100360 // Initialize queries for d
Akron6ed13992016-05-23 18:06:05 +0200361 if (obj.tutorial) {
Akron0b489ad2018-02-02 16:49:32 +0100362 obj.tutorial.initQueries(d);
Nils Diewaldfccfbcb2015-04-29 20:48:19 +0000363
Akron6ed13992016-05-23 18:06:05 +0200364 // Initialize documentation links
Akron0b489ad2018-02-02 16:49:32 +0100365 obj.tutorial.initDocLinks(d);
Akron6ed13992016-05-23 18:06:05 +0200366 };
Nils Diewald61e6ff52015-05-07 17:26:50 +0000367
Nils Diewald845282c2015-05-14 07:53:03 +0000368
Nils Diewald58141332015-04-07 16:18:45 +0000369 /**
Akronc1457bf2015-06-11 19:24:00 +0200370 * Add VC creation on submission.
371 */
Akron0b489ad2018-02-02 16:49:32 +0100372 var form = d.getElementById('searchform');
Akron792f58b2015-07-08 18:59:36 +0200373 if (form !== null) {
Akronc1457bf2015-06-11 19:24:00 +0200374 form.addEventListener('submit', function (e) {
Akron0b489ad2018-02-02 16:49:32 +0100375 var qf = d.getElementById('q-field');
Akron1be6c1c2020-01-07 15:29:58 +0100376
Akron19d97fe2016-09-06 20:47:05 +0200377 // No query was defined
378 if (qf.value === undefined || qf.value === '') {
379 qf.focus();
380 e.halt();
381 KorAP.log(700, "No query given");
382 return;
383 };
Akron1be6c1c2020-01-07 15:29:58 +0100384
Akron19d97fe2016-09-06 20:47:05 +0200385 // Store session information
Akronf8035592018-05-24 20:40:51 +0200386 KorAP.session.set("show", show);
Akron7716f012015-07-01 20:38:32 +0200387
Akron19d97fe2016-09-06 20:47:05 +0200388 if (vc !== undefined) {
389 input.value = vc.toQuery();
Akrond7ad9072019-12-09 07:08:20 +0100390 if (input.value == '')
391 input.removeAttribute('name');
Akron19d97fe2016-09-06 20:47:05 +0200392 }
393 else {
Akrond7ad9072019-12-09 07:08:20 +0100394 input.removeAttribute('value');
395 input.removeAttribute('name');
Akron19d97fe2016-09-06 20:47:05 +0200396 };
Akron1be6c1c2020-01-07 15:29:58 +0100397
398 // This would preferably set the query to be "disabled",
399 // but in that case the query wouldn't be submitted
400 // at all.
401 // Setting the cursor to "progress" fails in current versions
402 // of webkit.
403 qf.classList.add("loading");
404 d.getElementById('qsubmit').classList.add("loading");
Akronc1457bf2015-06-11 19:24:00 +0200405 });
406 };
hebasta5df796f2019-05-21 15:27:12 +0200407
408
409 //Starts the guided tour at the next page
410 if(KorAP.session.get("tour")){
411 tourClass.gTshowResults().start();
412 }
413
Akronc1457bf2015-06-11 19:24:00 +0200414 /**
Nils Diewald58141332015-04-07 16:18:45 +0000415 * Init hint helper
416 * has to be final because of
417 * reposition
418 */
Nils Diewald0e6992a2015-04-14 20:13:52 +0000419 // Todo: Pass an element, so this works with
420 // tutorial pages as well!
Akron00cd4d12016-05-31 21:01:11 +0200421 if (obj.hint === undefined)
422 obj.hint = hintClass.create();
Nils Diewald7148c6f2015-05-04 15:07:53 +0000423
Akron99713ef2017-06-28 18:19:28 +0200424 // Add the hinthelper to the KorAP object to make it manipulatable globally
Akron72f73572017-12-05 12:31:09 +0100425 KorAP.Hint = obj.hint;
Akron99713ef2017-06-28 18:19:28 +0200426
Akron2d0d96d2019-11-18 19:49:50 +0100427
428 /**
429 * Add query panel
430 */
431 var queryPanel = queryPanelClass.create();
432
433 // Get input field
434 var sform = d.getElementById("searchform");
435 var vcView = d.getElementById('vc-view')
436 if (sform && vcView) {
437 // The views are below the query bar
438 sform.insertBefore(queryPanel.element(), vcView);
Akron2d0d96d2019-11-18 19:49:50 +0100439 KorAP.Panel['query'] = queryPanel;
Akron644ad9f2021-07-26 16:12:59 +0200440 };
441
442
443 /**
444 * Add pagination panel
445 */
446 const paginationPanel = paginationPanelClass.create();
447
448 if (paginationPanel) {
449 paginationPanel.addRandomPage();
450 KorAP.Panel['pagination'] = paginationPanel;
451 };
Akron24f48ea2020-07-01 09:37:19 +0200452
Akrona9c55802021-06-15 11:41:29 +0200453
454 /**
455 * Initialize password toggle.
456 */
457 initCopyToClipboard(d);
458
459
Akron24f48ea2020-07-01 09:37:19 +0200460 /**
Akron116eace2021-06-14 18:02:37 +0200461 * Initialize password toggle.
462 */
Akron1cfde272021-06-14 18:32:39 +0200463 initTogglePwdVisibility(d);
Akron116eace2021-06-14 18:02:37 +0200464
465 /**
Akron24f48ea2020-07-01 09:37:19 +0200466 * Initialize Plugin registry.
467 */
Akron8dda1c62021-01-20 10:27:32 +0100468 let pe;
469 if (pe = d.getElementById("kalamar-plugins")) {
470 let url = pe.getAttribute('data-plugins');
471 if (url !== undefined) {
472 KorAP.API.getPluginList(url, function (json) {
473 if (json && json.length > 0) {
474 // Load Plugin Server first
475 KorAP.Plugin = pluginClass.create();
Akron24f48ea2020-07-01 09:37:19 +0200476
Akron8dda1c62021-01-20 10:27:32 +0100477 // Add services container to head
478 d.head.appendChild(KorAP.Plugin.element());
Akron24f48ea2020-07-01 09:37:19 +0200479
Akron8dda1c62021-01-20 10:27:32 +0100480 // Add pipe form
481 KorAP.Pipe = pipeClass.create();
482 d.getElementById("searchform").appendChild(KorAP.Pipe.element());
483
484 try {
485
486 // Register all plugins
487 json.forEach(i => KorAP.Plugin.register(i));
488 }
489 catch (e) {
490 KorAP.log(0, e);
491 }
492 }
493 });
494 };
Akron24f48ea2020-07-01 09:37:19 +0200495 };
Akron8dda1c62021-01-20 10:27:32 +0100496
Nils Diewald58141332015-04-07 16:18:45 +0000497 return obj;
Nils Diewald0e6992a2015-04-14 20:13:52 +0000498 });
hebasta75cfca52019-02-19 13:15:27 +0100499
Nils Diewald0e6992a2015-04-14 20:13:52 +0000500});