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