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