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