Akron | 7524be1 | 2016-06-01 17:31:33 +0200 | [diff] [blame] | 1 | /* |
Akron | 5cb9b2b | 2018-07-24 17:01:09 +0200 | [diff] [blame] | 2 | * Initialize The JS frontend part and decorate |
| 3 | * the static HTML data. |
| 4 | * |
| 5 | * @author Nils Diewald |
| 6 | * |
Akron | 7524be1 | 2016-06-01 17:31:33 +0200 | [diff] [blame] | 7 | * 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 | |
Nils Diewald | 0e6992a | 2015-04-14 20:13:52 +0000 | [diff] [blame] | 18 | define([ |
| 19 | 'match', |
| 20 | 'hint', |
| 21 | 'vc', |
| 22 | 'tutorial', |
| 23 | 'lib/domReady', |
Akron | 27ae9ec | 2015-06-23 00:43:21 +0200 | [diff] [blame] | 24 | 'vc/array', |
Nils Diewald | 7148c6f | 2015-05-04 15:07:53 +0000 | [diff] [blame] | 25 | 'lib/alertify', |
Akron | 7716f01 | 2015-07-01 20:38:32 +0200 | [diff] [blame] | 26 | 'session', |
Akron | 6bb7158 | 2016-06-10 20:41:08 +0200 | [diff] [blame] | 27 | 'selectMenu', |
Akron | 5cb9b2b | 2018-07-24 17:01:09 +0200 | [diff] [blame] | 28 | 'panel/result', |
Akron | 2d0d96d | 2019-11-18 19:49:50 +0100 | [diff] [blame] | 29 | 'panel/query', |
hebasta | 75cfca5 | 2019-02-19 13:15:27 +0100 | [diff] [blame] | 30 | 'tour/tours', |
Nils Diewald | 7148c6f | 2015-05-04 15:07:53 +0000 | [diff] [blame] | 31 | 'api', |
Nils Diewald | c46003b | 2015-05-07 15:55:35 +0000 | [diff] [blame] | 32 | 'mailToChiffre', |
Nils Diewald | 0e6992a | 2015-04-14 20:13:52 +0000 | [diff] [blame] | 33 | 'util' |
| 34 | ], function (matchClass, |
Akron | 19d97fe | 2016-09-06 20:47:05 +0200 | [diff] [blame] | 35 | hintClass, |
| 36 | vcClass, |
| 37 | tutClass, |
| 38 | domReady, |
Akron | 19d97fe | 2016-09-06 20:47:05 +0200 | [diff] [blame] | 39 | vcArray, |
| 40 | alertifyClass, |
| 41 | sessionClass, |
Akron | 4d926f1 | 2018-07-16 15:30:25 +0200 | [diff] [blame] | 42 | selectMenuClass, |
hebasta | 75cfca5 | 2019-02-19 13:15:27 +0100 | [diff] [blame] | 43 | resultPanelClass, |
Akron | 2d0d96d | 2019-11-18 19:49:50 +0100 | [diff] [blame] | 44 | queryPanelClass, |
hebasta | 75cfca5 | 2019-02-19 13:15:27 +0100 | [diff] [blame] | 45 | tourClass) { |
Nils Diewald | a0defc4 | 2015-05-07 23:54:17 +0000 | [diff] [blame] | 46 | |
Akron | 0b489ad | 2018-02-02 16:49:32 +0100 | [diff] [blame] | 47 | const d = document; |
Akron | 9cc3eaf | 2015-06-10 22:15:52 +0200 | [diff] [blame] | 48 | |
Akron | 0c4cd22 | 2019-07-19 16:33:34 +0200 | [diff] [blame] | 49 | // Create suffix if KorAP is run in a subfolder |
| 50 | KorAP.session = sessionClass.create( |
| 51 | KorAP.URL.length > 0 ? 'kalamarJS-' + KorAP.URL.slugify() : 'kalamarJS' |
| 52 | ); |
Akron | f803559 | 2018-05-24 20:40:51 +0200 | [diff] [blame] | 53 | |
Nils Diewald | a0defc4 | 2015-05-07 23:54:17 +0000 | [diff] [blame] | 54 | // Override KorAP.log |
| 55 | window.alertify = alertifyClass; |
Akron | c0a2da8 | 2018-07-04 15:27:37 +0200 | [diff] [blame] | 56 | KorAP.log = function (code, msg, src) { |
| 57 | |
| 58 | if (src) { |
| 59 | msg += '<code class="src">'+src+'</code>'; |
| 60 | }; |
Nils Diewald | a0defc4 | 2015-05-07 23:54:17 +0000 | [diff] [blame] | 61 | |
| 62 | // Use alertify to log errors |
| 63 | alertifyClass.log( |
Akron | f55504a | 2015-06-18 16:42:55 +0200 | [diff] [blame] | 64 | (code === 0 ? '' : code + ': ') + |
Akron | 19d97fe | 2016-09-06 20:47:05 +0200 | [diff] [blame] | 65 | msg, |
Nils Diewald | a0defc4 | 2015-05-07 23:54:17 +0000 | [diff] [blame] | 66 | 'error', |
Akron | f55504a | 2015-06-18 16:42:55 +0200 | [diff] [blame] | 67 | 10000 |
Nils Diewald | a0defc4 | 2015-05-07 23:54:17 +0000 | [diff] [blame] | 68 | ); |
| 69 | }; |
| 70 | |
hebasta | 2758b58 | 2018-11-19 15:59:42 +0100 | [diff] [blame] | 71 | KorAP.vc = vcClass.create(vcArray); |
| 72 | |
hebasta | 5df796f | 2019-05-21 15:27:12 +0200 | [diff] [blame] | 73 | KorAP.tourshow = function(){ |
| 74 | tourClass.gTstartSearch().start(); |
| 75 | }; |
| 76 | |
| 77 | KorAP.tourshowR = function(){ |
| 78 | tourClass.gTshowResults().start(); |
| 79 | }; |
| 80 | |
Nils Diewald | 0e6992a | 2015-04-14 20:13:52 +0000 | [diff] [blame] | 81 | domReady(function (event) { |
hebasta | 5df796f | 2019-05-21 15:27:12 +0200 | [diff] [blame] | 82 | |
Nils Diewald | 0e6992a | 2015-04-14 20:13:52 +0000 | [diff] [blame] | 83 | var obj = {}; |
Akron | 71b91e4 | 2016-06-01 22:12:43 +0200 | [diff] [blame] | 84 | |
Akron | 4d926f1 | 2018-07-16 15:30:25 +0200 | [diff] [blame] | 85 | // What should be visible in the beginning? |
Akron | f803559 | 2018-05-24 20:40:51 +0200 | [diff] [blame] | 86 | var show = KorAP.session.get('show') || {}; |
hebasta | 043e96f | 2019-11-28 12:33:00 +0100 | [diff] [blame] | 87 | |
| 88 | KorAP.Panel = KorAP.Panel || {} |
Nils Diewald | a297f06 | 2015-04-02 00:23:46 +0000 | [diff] [blame] | 89 | |
| 90 | /** |
Akron | f55504a | 2015-06-18 16:42:55 +0200 | [diff] [blame] | 91 | * Release notifications |
| 92 | */ |
| 93 | if (KorAP.Notifications !== undefined) { |
| 94 | var n = KorAP.Notifications; |
| 95 | for (var i = 0; i < n.length; i++) { |
Akron | 8ea8429 | 2018-10-24 13:41:52 +0200 | [diff] [blame] | 96 | var msg = n[i][1]; |
| 97 | if (n[i][2]) { |
| 98 | msg += '<code class="src">'+n[i][2]+'</code>'; |
| 99 | }; |
| 100 | alertifyClass.log(msg, n[i][0], 10000); |
Akron | f55504a | 2015-06-18 16:42:55 +0200 | [diff] [blame] | 101 | }; |
| 102 | }; |
| 103 | |
| 104 | /** |
Akron | cd42a14 | 2019-07-12 18:55:37 +0200 | [diff] [blame] | 105 | * Replace Virtual Corpus field |
Nils Diewald | 7148c6f | 2015-05-04 15:07:53 +0000 | [diff] [blame] | 106 | */ |
Akron | 5c829e9 | 2017-05-12 18:10:00 +0200 | [diff] [blame] | 107 | var vcname, vcchoose; |
Akron | cd42a14 | 2019-07-12 18:55:37 +0200 | [diff] [blame] | 108 | var input = d.getElementById('cq'); |
Akron | 1f0521b | 2018-08-28 13:01:24 +0200 | [diff] [blame] | 109 | |
hebasta | 2758b58 | 2018-11-19 15:59:42 +0100 | [diff] [blame] | 110 | var vc = KorAP.vc; |
hebasta | 48842cf | 2018-12-11 12:57:38 +0100 | [diff] [blame] | 111 | |
Akron | 1f0521b | 2018-08-28 13:01:24 +0200 | [diff] [blame] | 112 | // Add vc name object |
Nils Diewald | 7148c6f | 2015-05-04 15:07:53 +0000 | [diff] [blame] | 113 | if (input) { |
| 114 | input.style.display = 'none'; |
Akron | 0b489ad | 2018-02-02 16:49:32 +0100 | [diff] [blame] | 115 | vcname = d.createElement('span'); |
Nils Diewald | 7148c6f | 2015-05-04 15:07:53 +0000 | [diff] [blame] | 116 | vcname.setAttribute('id', 'vc-choose'); |
Akron | 6bb7158 | 2016-06-10 20:41:08 +0200 | [diff] [blame] | 117 | vcname.classList.add('select'); |
Akron | 941551e | 2015-06-11 16:06:22 +0200 | [diff] [blame] | 118 | |
Akron | 1f0521b | 2018-08-28 13:01:24 +0200 | [diff] [blame] | 119 | // Load virtual corpus object |
Akron | cd42a14 | 2019-07-12 18:55:37 +0200 | [diff] [blame] | 120 | // Supports "collection" for legacy reasons |
| 121 | if (KorAP.koralQuery !== undefined && (KorAP.koralQuery["collection"] || KorAP.koralQuery["corpus"])) { |
Akron | 1f0521b | 2018-08-28 13:01:24 +0200 | [diff] [blame] | 122 | try { |
Akron | cd42a14 | 2019-07-12 18:55:37 +0200 | [diff] [blame] | 123 | vc.fromJson(KorAP.koralQuery["collection"] || KorAP.koralQuery["corpus"]); |
Akron | 1f0521b | 2018-08-28 13:01:24 +0200 | [diff] [blame] | 124 | } |
| 125 | catch (e) { |
| 126 | KorAP.log(0,e); |
| 127 | } |
Akron | 27ae9ec | 2015-06-23 00:43:21 +0200 | [diff] [blame] | 128 | }; |
| 129 | |
Akron | 0b489ad | 2018-02-02 16:49:32 +0100 | [diff] [blame] | 130 | vcchoose = vcname.addE('span'); |
Akron | ec6bb8e | 2018-08-29 13:07:56 +0200 | [diff] [blame] | 131 | vcchoose.addT(vc.getName()); |
Akron | 27ae9ec | 2015-06-23 00:43:21 +0200 | [diff] [blame] | 132 | |
Akron | 1f0521b | 2018-08-28 13:01:24 +0200 | [diff] [blame] | 133 | if (vc.wasRewritten()) { |
| 134 | vcchoose.classList.add('rewritten'); |
| 135 | }; |
| 136 | |
Nils Diewald | 7148c6f | 2015-05-04 15:07:53 +0000 | [diff] [blame] | 137 | input.parentNode.insertBefore(vcname, input); |
| 138 | }; |
| 139 | |
Nils Diewald | 7148c6f | 2015-05-04 15:07:53 +0000 | [diff] [blame] | 140 | /** |
Nils Diewald | a297f06 | 2015-04-02 00:23:46 +0000 | [diff] [blame] | 141 | * Add actions to match entries |
| 142 | */ |
Akron | 0b489ad | 2018-02-02 16:49:32 +0100 | [diff] [blame] | 143 | var inactiveLi = d.querySelectorAll( |
Nils Diewald | 5c5a747 | 2015-04-02 22:13:38 +0000 | [diff] [blame] | 144 | '#search > ol > li:not(.active)' |
| 145 | ); |
Akron | 5cb9b2b | 2018-07-24 17:01:09 +0200 | [diff] [blame] | 146 | var matchCount = 0; |
Akron | 6a535d4 | 2015-08-26 20:16:58 +0200 | [diff] [blame] | 147 | |
Akron | 5cb9b2b | 2018-07-24 17:01:09 +0200 | [diff] [blame] | 148 | for (matchCount = 0; matchCount < inactiveLi.length; matchCount++) { |
Akron | 6112b52 | 2018-07-25 13:48:53 +0200 | [diff] [blame] | 149 | inactiveLi[matchCount].addEventListener('click', function (e) { |
Akron | 19d97fe | 2016-09-06 20:47:05 +0200 | [diff] [blame] | 150 | if (this._match !== undefined) |
| 151 | this._match.open(); |
| 152 | else { |
| 153 | // lazyLoad |
| 154 | matchClass.create(this).open(); |
| 155 | }; |
Akron | e0c32c7 | 2017-04-25 22:38:23 +0200 | [diff] [blame] | 156 | // This would prevent the sidebar to go back |
| 157 | // e.halt(); |
Nils Diewald | a297f06 | 2015-04-02 00:23:46 +0000 | [diff] [blame] | 158 | }); |
Akron | 5cb9b2b | 2018-07-24 17:01:09 +0200 | [diff] [blame] | 159 | inactiveLi[matchCount].addEventListener('keydown', function (e) { |
Akron | 19d97fe | 2016-09-06 20:47:05 +0200 | [diff] [blame] | 160 | var code = _codeFromEvent(e); |
| 161 | |
| 162 | switch (code) { |
| 163 | case 32: |
| 164 | if (this._match !== undefined) |
| 165 | this._match.toggle(); |
| 166 | else { |
| 167 | // lazyLoad |
| 168 | matchClass.create(this).open(); |
| 169 | }; |
| 170 | e.halt(); |
| 171 | break; |
| 172 | }; |
Akron | 6a535d4 | 2015-08-26 20:16:58 +0200 | [diff] [blame] | 173 | }); |
Nils Diewald | a297f06 | 2015-04-02 00:23:46 +0000 | [diff] [blame] | 174 | }; |
| 175 | |
Akron | e0c32c7 | 2017-04-25 22:38:23 +0200 | [diff] [blame] | 176 | // Add focus listener to aside |
Akron | 0b489ad | 2018-02-02 16:49:32 +0100 | [diff] [blame] | 177 | var aside = d.getElementsByTagName('aside')[0]; |
Akron | e0c32c7 | 2017-04-25 22:38:23 +0200 | [diff] [blame] | 178 | |
| 179 | if (aside && aside.classList.contains('active') == false) { |
Akron | 1885ce9 | 2017-04-26 23:10:01 +0200 | [diff] [blame] | 180 | |
Akron | 5258d46 | 2017-04-26 23:32:57 +0200 | [diff] [blame] | 181 | // Horrible lock to deal with sidebar clicks |
| 182 | var asideClicked = false; |
| 183 | |
Akron | 1885ce9 | 2017-04-26 23:10:01 +0200 | [diff] [blame] | 184 | // Make aside active on focus |
| 185 | aside.addEventListener('focus', function(e) { |
Akron | e0c32c7 | 2017-04-25 22:38:23 +0200 | [diff] [blame] | 186 | this.classList.add('active'); |
| 187 | }); |
| 188 | |
Akron | 1885ce9 | 2017-04-26 23:10:01 +0200 | [diff] [blame] | 189 | // Deactivate focus when clicking anywhere else |
Akron | 0b489ad | 2018-02-02 16:49:32 +0100 | [diff] [blame] | 190 | var body = d.getElementsByTagName('body')[0]; |
Akron | 1885ce9 | 2017-04-26 23:10:01 +0200 | [diff] [blame] | 191 | if (body !== null) { |
| 192 | body.addEventListener('click', function() { |
Akron | 5258d46 | 2017-04-26 23:32:57 +0200 | [diff] [blame] | 193 | if (!asideClicked) { |
| 194 | aside.classList.remove('active'); |
| 195 | } |
| 196 | else { |
| 197 | asideClicked = false; |
| 198 | }; |
Akron | 1885ce9 | 2017-04-26 23:10:01 +0200 | [diff] [blame] | 199 | }); |
| 200 | }; |
| 201 | |
| 202 | /* Stop click event on aside |
| 203 | * (to not trickle down to body) |
| 204 | */ |
| 205 | aside.addEventListener('click', function(e) { |
Akron | 5258d46 | 2017-04-26 23:32:57 +0200 | [diff] [blame] | 206 | asideClicked = true; |
Akron | e0c32c7 | 2017-04-25 22:38:23 +0200 | [diff] [blame] | 207 | }); |
| 208 | }; |
Akron | b9cdb10 | 2017-04-25 00:52:31 +0200 | [diff] [blame] | 209 | |
| 210 | |
Akron | 6bb7158 | 2016-06-10 20:41:08 +0200 | [diff] [blame] | 211 | // Replace QL select menus with KorAP menus |
Akron | 0b489ad | 2018-02-02 16:49:32 +0100 | [diff] [blame] | 212 | var qlField = d.getElementById('ql-field'); |
Akron | aba7a5a | 2016-08-15 21:58:33 +0200 | [diff] [blame] | 213 | if (qlField !== null) { |
Akron | 086fe5d | 2017-11-13 14:01:45 +0100 | [diff] [blame] | 214 | KorAP.QLmenu = selectMenuClass.create( |
Akron | 0b489ad | 2018-02-02 16:49:32 +0100 | [diff] [blame] | 215 | d.getElementById('ql-field').parentNode |
Akron | aba7a5a | 2016-08-15 21:58:33 +0200 | [diff] [blame] | 216 | ).limit(5); |
| 217 | }; |
Akron | 6bb7158 | 2016-06-10 20:41:08 +0200 | [diff] [blame] | 218 | |
Akron | 4d926f1 | 2018-07-16 15:30:25 +0200 | [diff] [blame] | 219 | var resultInfo = d.getElementById('resultinfo'); |
| 220 | |
Akron | 4d926f1 | 2018-07-16 15:30:25 +0200 | [diff] [blame] | 221 | /** |
| 222 | * Add result panel |
| 223 | */ |
Akron | 5cb9b2b | 2018-07-24 17:01:09 +0200 | [diff] [blame] | 224 | var resultPanel = resultPanelClass.create(show); |
| 225 | |
Akron | 4d926f1 | 2018-07-16 15:30:25 +0200 | [diff] [blame] | 226 | if (resultInfo != null) { |
Akron | 4d926f1 | 2018-07-16 15:30:25 +0200 | [diff] [blame] | 227 | |
| 228 | // Move buttons to resultinfo |
| 229 | resultInfo.appendChild(resultPanel.actions.element()); |
| 230 | |
Akron | e6538cd | 2018-07-16 17:52:33 +0200 | [diff] [blame] | 231 | // The views are at the top of the search results |
Akron | 4d926f1 | 2018-07-16 15:30:25 +0200 | [diff] [blame] | 232 | var sb = d.getElementById('search'); |
| 233 | sb.insertBefore(resultPanel.element(), sb.firstChild); |
Akron | 4d926f1 | 2018-07-16 15:30:25 +0200 | [diff] [blame] | 234 | }; |
| 235 | |
| 236 | |
Akron | 179c8ac | 2015-06-30 19:30:50 +0200 | [diff] [blame] | 237 | // There is a koralQuery |
Akron | 4d926f1 | 2018-07-16 15:30:25 +0200 | [diff] [blame] | 238 | if (KorAP.koralQuery !== undefined) { |
Akron | 5cb9b2b | 2018-07-24 17:01:09 +0200 | [diff] [blame] | 239 | |
| 240 | // Add KoralQuery view to result panel |
Akron | 4d926f1 | 2018-07-16 15:30:25 +0200 | [diff] [blame] | 241 | if (resultInfo !== null) { |
Akron | 5cb9b2b | 2018-07-24 17:01:09 +0200 | [diff] [blame] | 242 | resultPanel.addKqAction() |
Akron | 179c8ac | 2015-06-30 19:30:50 +0200 | [diff] [blame] | 243 | }; |
Akron | 7716f01 | 2015-07-01 20:38:32 +0200 | [diff] [blame] | 244 | |
Akron | 00cd4d1 | 2016-05-31 21:01:11 +0200 | [diff] [blame] | 245 | if (KorAP.koralQuery["errors"]) { |
Akron | 19d97fe | 2016-09-06 20:47:05 +0200 | [diff] [blame] | 246 | var errors = KorAP.koralQuery["errors"]; |
| 247 | for (var i in errors) { |
Akron | f0c31ed | 2016-06-11 11:27:01 +0200 | [diff] [blame] | 248 | |
Akron | 19d97fe | 2016-09-06 20:47:05 +0200 | [diff] [blame] | 249 | // Malformed query |
| 250 | if (errors[i][0] === 302 && errors[i][2]) { |
| 251 | obj.hint = hintClass.create(); |
| 252 | obj.hint.alert(errors[i][2], errors[i][1]); |
| 253 | break; |
| 254 | } |
Akron | f0c31ed | 2016-06-11 11:27:01 +0200 | [diff] [blame] | 255 | |
Akron | 19d97fe | 2016-09-06 20:47:05 +0200 | [diff] [blame] | 256 | // no query |
| 257 | else if (errors[i][0] === 301) { |
| 258 | obj.hint = hintClass.create(); |
| 259 | obj.hint.alert(0, errors[i][1]); |
| 260 | } |
| 261 | } |
Akron | 00cd4d1 | 2016-05-31 21:01:11 +0200 | [diff] [blame] | 262 | }; |
Akron | 179c8ac | 2015-06-30 19:30:50 +0200 | [diff] [blame] | 263 | }; |
| 264 | |
Akron | 5cb9b2b | 2018-07-24 17:01:09 +0200 | [diff] [blame] | 265 | |
| 266 | /* |
| 267 | * There is more than 0 matches, so allow for |
| 268 | * alignment toggling (left <=> right) |
| 269 | */ |
| 270 | if (matchCount > 0) |
| 271 | resultPanel.addAlignAction(); |
Nils Diewald | 7148c6f | 2015-05-04 15:07:53 +0000 | [diff] [blame] | 272 | |
hebasta | 043e96f | 2019-11-28 12:33:00 +0100 | [diff] [blame] | 273 | KorAP.Panel['result'] = resultPanel; |
Akron | 5cb9b2b | 2018-07-24 17:01:09 +0200 | [diff] [blame] | 274 | /* |
Akron | cd42a14 | 2019-07-12 18:55:37 +0200 | [diff] [blame] | 275 | * Toggle the Virtual Corpus builder |
Nils Diewald | 7148c6f | 2015-05-04 15:07:53 +0000 | [diff] [blame] | 276 | */ |
| 277 | if (vcname) { |
Akron | ec6bb8e | 2018-08-29 13:07:56 +0200 | [diff] [blame] | 278 | vc.onMinimize = function () { |
| 279 | vcname.classList.remove('active'); |
Akron | cd42a14 | 2019-07-12 18:55:37 +0200 | [diff] [blame] | 280 | delete show['vc']; |
Akron | ec6bb8e | 2018-08-29 13:07:56 +0200 | [diff] [blame] | 281 | }; |
Nils Diewald | 6283d69 | 2015-04-23 20:32:53 +0000 | [diff] [blame] | 282 | |
Akron | ec6bb8e | 2018-08-29 13:07:56 +0200 | [diff] [blame] | 283 | vc.onOpen = function () { |
| 284 | vcname.classList.add('active'); |
Akron | cfe8ecc | 2018-11-20 18:46:16 +0100 | [diff] [blame] | 285 | |
| 286 | var view = d.getElementById('vc-view'); |
| 287 | if (!view.firstChild) |
| 288 | view.appendChild(this.element()); |
| 289 | |
Akron | cd42a14 | 2019-07-12 18:55:37 +0200 | [diff] [blame] | 290 | show['vc'] = true; |
Akron | ec6bb8e | 2018-08-29 13:07:56 +0200 | [diff] [blame] | 291 | }; |
| 292 | |
| 293 | var vcclick = function () { |
Akron | ec6bb8e | 2018-08-29 13:07:56 +0200 | [diff] [blame] | 294 | if (vc.isOpen()) { |
| 295 | vc.minimize() |
| 296 | } |
| 297 | else { |
Akron | ec6bb8e | 2018-08-29 13:07:56 +0200 | [diff] [blame] | 298 | vc.open(); |
Akron | 19d97fe | 2016-09-06 20:47:05 +0200 | [diff] [blame] | 299 | }; |
Nils Diewald | 5814133 | 2015-04-07 16:18:45 +0000 | [diff] [blame] | 300 | }; |
Akron | 04671e7 | 2017-05-11 20:47:32 +0200 | [diff] [blame] | 301 | |
Akron | 179c8ac | 2015-06-30 19:30:50 +0200 | [diff] [blame] | 302 | vcname.onclick = vcclick; |
Akron | 5c829e9 | 2017-05-12 18:10:00 +0200 | [diff] [blame] | 303 | |
| 304 | // Click, if the VC should be shown |
Akron | cd42a14 | 2019-07-12 18:55:37 +0200 | [diff] [blame] | 305 | if (show['vc']) { |
Akron | 19d97fe | 2016-09-06 20:47:05 +0200 | [diff] [blame] | 306 | vcclick.apply(); |
Akron | 04671e7 | 2017-05-11 20:47:32 +0200 | [diff] [blame] | 307 | }; |
Nils Diewald | 5814133 | 2015-04-07 16:18:45 +0000 | [diff] [blame] | 308 | }; |
| 309 | |
Akron | 19d97fe | 2016-09-06 20:47:05 +0200 | [diff] [blame] | 310 | |
Nils Diewald | 5814133 | 2015-04-07 16:18:45 +0000 | [diff] [blame] | 311 | /** |
| 312 | * Init Tutorial view |
| 313 | */ |
Akron | 0b489ad | 2018-02-02 16:49:32 +0100 | [diff] [blame] | 314 | if (d.getElementById('view-tutorial')) { |
Nils Diewald | fccfbcb | 2015-04-29 20:48:19 +0000 | [diff] [blame] | 315 | window.tutorial = tutClass.create( |
Akron | 0b489ad | 2018-02-02 16:49:32 +0100 | [diff] [blame] | 316 | d.getElementById('view-tutorial'), |
Akron | f803559 | 2018-05-24 20:40:51 +0200 | [diff] [blame] | 317 | KorAP.session |
Nils Diewald | fccfbcb | 2015-04-29 20:48:19 +0000 | [diff] [blame] | 318 | ); |
| 319 | obj.tutorial = window.tutorial; |
| 320 | } |
Nils Diewald | 5814133 | 2015-04-07 16:18:45 +0000 | [diff] [blame] | 321 | |
Nils Diewald | fccfbcb | 2015-04-29 20:48:19 +0000 | [diff] [blame] | 322 | // Tutorial is in parent |
| 323 | else if (window.parent) { |
| 324 | obj.tutorial = window.parent.tutorial; |
| 325 | }; |
| 326 | |
Akron | 0b489ad | 2018-02-02 16:49:32 +0100 | [diff] [blame] | 327 | // Initialize queries for d |
Akron | 6ed1399 | 2016-05-23 18:06:05 +0200 | [diff] [blame] | 328 | if (obj.tutorial) { |
Akron | 0b489ad | 2018-02-02 16:49:32 +0100 | [diff] [blame] | 329 | obj.tutorial.initQueries(d); |
Nils Diewald | fccfbcb | 2015-04-29 20:48:19 +0000 | [diff] [blame] | 330 | |
Akron | 6ed1399 | 2016-05-23 18:06:05 +0200 | [diff] [blame] | 331 | // Initialize documentation links |
Akron | 0b489ad | 2018-02-02 16:49:32 +0100 | [diff] [blame] | 332 | obj.tutorial.initDocLinks(d); |
Akron | 6ed1399 | 2016-05-23 18:06:05 +0200 | [diff] [blame] | 333 | }; |
Nils Diewald | 61e6ff5 | 2015-05-07 17:26:50 +0000 | [diff] [blame] | 334 | |
Nils Diewald | 845282c | 2015-05-14 07:53:03 +0000 | [diff] [blame] | 335 | |
Nils Diewald | 5814133 | 2015-04-07 16:18:45 +0000 | [diff] [blame] | 336 | /** |
Akron | c1457bf | 2015-06-11 19:24:00 +0200 | [diff] [blame] | 337 | * Add VC creation on submission. |
| 338 | */ |
Akron | 0b489ad | 2018-02-02 16:49:32 +0100 | [diff] [blame] | 339 | var form = d.getElementById('searchform'); |
Akron | 792f58b | 2015-07-08 18:59:36 +0200 | [diff] [blame] | 340 | if (form !== null) { |
Akron | c1457bf | 2015-06-11 19:24:00 +0200 | [diff] [blame] | 341 | form.addEventListener('submit', function (e) { |
Akron | 0b489ad | 2018-02-02 16:49:32 +0100 | [diff] [blame] | 342 | var qf = d.getElementById('q-field'); |
Akron | c1457bf | 2015-06-11 19:24:00 +0200 | [diff] [blame] | 343 | |
Akron | 19d97fe | 2016-09-06 20:47:05 +0200 | [diff] [blame] | 344 | // No query was defined |
| 345 | if (qf.value === undefined || qf.value === '') { |
| 346 | qf.focus(); |
| 347 | e.halt(); |
| 348 | KorAP.log(700, "No query given"); |
| 349 | return; |
| 350 | }; |
Akron | 7716f01 | 2015-07-01 20:38:32 +0200 | [diff] [blame] | 351 | |
Akron | 19d97fe | 2016-09-06 20:47:05 +0200 | [diff] [blame] | 352 | // Store session information |
Akron | f803559 | 2018-05-24 20:40:51 +0200 | [diff] [blame] | 353 | KorAP.session.set("show", show); |
Akron | 7716f01 | 2015-07-01 20:38:32 +0200 | [diff] [blame] | 354 | |
Akron | 19d97fe | 2016-09-06 20:47:05 +0200 | [diff] [blame] | 355 | if (vc !== undefined) { |
| 356 | input.value = vc.toQuery(); |
| 357 | } |
| 358 | else { |
| 359 | delete input['value']; |
| 360 | }; |
Akron | c1457bf | 2015-06-11 19:24:00 +0200 | [diff] [blame] | 361 | }); |
| 362 | }; |
hebasta | 5df796f | 2019-05-21 15:27:12 +0200 | [diff] [blame] | 363 | |
| 364 | |
| 365 | //Starts the guided tour at the next page |
| 366 | if(KorAP.session.get("tour")){ |
| 367 | tourClass.gTshowResults().start(); |
| 368 | } |
| 369 | |
Akron | c1457bf | 2015-06-11 19:24:00 +0200 | [diff] [blame] | 370 | /** |
Nils Diewald | 5814133 | 2015-04-07 16:18:45 +0000 | [diff] [blame] | 371 | * Init hint helper |
| 372 | * has to be final because of |
| 373 | * reposition |
| 374 | */ |
Nils Diewald | 0e6992a | 2015-04-14 20:13:52 +0000 | [diff] [blame] | 375 | // Todo: Pass an element, so this works with |
| 376 | // tutorial pages as well! |
Akron | 00cd4d1 | 2016-05-31 21:01:11 +0200 | [diff] [blame] | 377 | if (obj.hint === undefined) |
| 378 | obj.hint = hintClass.create(); |
Nils Diewald | 7148c6f | 2015-05-04 15:07:53 +0000 | [diff] [blame] | 379 | |
Akron | 99713ef | 2017-06-28 18:19:28 +0200 | [diff] [blame] | 380 | // Add the hinthelper to the KorAP object to make it manipulatable globally |
Akron | 72f7357 | 2017-12-05 12:31:09 +0100 | [diff] [blame] | 381 | KorAP.Hint = obj.hint; |
Akron | 99713ef | 2017-06-28 18:19:28 +0200 | [diff] [blame] | 382 | |
Akron | 2d0d96d | 2019-11-18 19:49:50 +0100 | [diff] [blame] | 383 | |
| 384 | /** |
| 385 | * Add query panel |
| 386 | */ |
| 387 | var queryPanel = queryPanelClass.create(); |
| 388 | |
| 389 | // Get input field |
| 390 | var sform = d.getElementById("searchform"); |
| 391 | var vcView = d.getElementById('vc-view') |
| 392 | if (sform && vcView) { |
| 393 | // The views are below the query bar |
| 394 | sform.insertBefore(queryPanel.element(), vcView); |
Akron | 2d0d96d | 2019-11-18 19:49:50 +0100 | [diff] [blame] | 395 | KorAP.Panel['query'] = queryPanel; |
| 396 | } |
| 397 | |
Nils Diewald | 5814133 | 2015-04-07 16:18:45 +0000 | [diff] [blame] | 398 | return obj; |
Nils Diewald | 0e6992a | 2015-04-14 20:13:52 +0000 | [diff] [blame] | 399 | }); |
hebasta | 75cfca5 | 2019-02-19 13:15:27 +0100 | [diff] [blame] | 400 | |
Nils Diewald | 0e6992a | 2015-04-14 20:13:52 +0000 | [diff] [blame] | 401 | }); |