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