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