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