Akron | 7524be1 | 2016-06-01 17:31:33 +0200 | [diff] [blame] | 1 | /* |
| 2 | * TODO: Create lazy loading of objects including |
| 3 | * - obj.hint() |
| 4 | * - obj.alertify() |
| 5 | * - obj.session() |
| 6 | * - obj.tutorial() |
| 7 | * - obj.vc() // toggle |
| 8 | * - obj.matchCreate() (using webpack) |
| 9 | * - obj.koral() (show result, parse for errors ...) |
| 10 | * - obj.alignment() // toggle |
| 11 | */ |
| 12 | |
Nils Diewald | 0e6992a | 2015-04-14 20:13:52 +0000 | [diff] [blame] | 13 | define([ |
| 14 | 'match', |
| 15 | 'hint', |
| 16 | 'vc', |
| 17 | 'tutorial', |
| 18 | 'lib/domReady', |
Nils Diewald | 7148c6f | 2015-05-04 15:07:53 +0000 | [diff] [blame] | 19 | 'hint/array', |
Akron | 27ae9ec | 2015-06-23 00:43:21 +0200 | [diff] [blame] | 20 | 'vc/array', |
Nils Diewald | 7148c6f | 2015-05-04 15:07:53 +0000 | [diff] [blame] | 21 | 'lib/alertify', |
Akron | 7716f01 | 2015-07-01 20:38:32 +0200 | [diff] [blame] | 22 | 'session', |
Akron | be105b9 | 2016-01-04 14:13:20 +0100 | [diff] [blame] | 23 | 'tagger', |
Akron | 6bb7158 | 2016-06-10 20:41:08 +0200 | [diff] [blame] | 24 | 'selectMenu', |
Nils Diewald | 7148c6f | 2015-05-04 15:07:53 +0000 | [diff] [blame] | 25 | 'api', |
Nils Diewald | c46003b | 2015-05-07 15:55:35 +0000 | [diff] [blame] | 26 | 'mailToChiffre', |
Nils Diewald | 845282c | 2015-05-14 07:53:03 +0000 | [diff] [blame] | 27 | 'lib/highlight/highlight.pack', |
Nils Diewald | 0e6992a | 2015-04-14 20:13:52 +0000 | [diff] [blame] | 28 | 'util' |
| 29 | ], function (matchClass, |
Akron | 19d97fe | 2016-09-06 20:47:05 +0200 | [diff] [blame] | 30 | hintClass, |
| 31 | vcClass, |
| 32 | tutClass, |
| 33 | domReady, |
| 34 | hintArray, |
| 35 | vcArray, |
| 36 | alertifyClass, |
| 37 | sessionClass, |
| 38 | tagger, |
| 39 | selectMenuClass) { |
Nils Diewald | a0defc4 | 2015-05-07 23:54:17 +0000 | [diff] [blame] | 40 | |
| 41 | // Set hint array for hint helper |
| 42 | KorAP.hintArray = hintArray; |
| 43 | |
Akron | 9cc3eaf | 2015-06-10 22:15:52 +0200 | [diff] [blame] | 44 | // Localization values |
| 45 | var loc = KorAP.Locale; |
Akron | 7716f01 | 2015-07-01 20:38:32 +0200 | [diff] [blame] | 46 | loc.VC_allCorpora = loc.VC_allCorpora || 'all Corpora'; |
| 47 | loc.VC_oneCollection = loc.VC_oneCollection || 'one Collection'; |
| 48 | loc.TOGGLE_ALIGN = loc.TOGGLE_ALIGN || 'toggle Alignment'; |
| 49 | loc.SHOW_KQ = loc.SHOW_KQ || 'show KoralQuery'; |
Akron | 9a5b1e1 | 2016-12-06 18:18:23 +0100 | [diff] [blame] | 50 | loc.SHOW_META = loc.SHOW_META || 'show Metadata'; |
| 51 | |
Akron | 9cc3eaf | 2015-06-10 22:15:52 +0200 | [diff] [blame] | 52 | |
Nils Diewald | a0defc4 | 2015-05-07 23:54:17 +0000 | [diff] [blame] | 53 | // Override KorAP.log |
| 54 | window.alertify = alertifyClass; |
Akron | f55504a | 2015-06-18 16:42:55 +0200 | [diff] [blame] | 55 | KorAP.log = function (code, msg) { |
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 | |
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 | 7716f01 | 2015-07-01 20:38:32 +0200 | [diff] [blame] | 69 | var session = sessionClass.create('KalamarJS'); |
| 70 | |
| 71 | // What should be visible? |
| 72 | var show = 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 | 19d97fe | 2016-09-06 20:47:05 +0200 | [diff] [blame] | 80 | alertifyClass.log(n[i][1], n[i][0], 10000); |
Akron | f55504a | 2015-06-18 16:42:55 +0200 | [diff] [blame] | 81 | }; |
| 82 | }; |
| 83 | |
| 84 | /** |
Nils Diewald | 7148c6f | 2015-05-04 15:07:53 +0000 | [diff] [blame] | 85 | * Replace Virtual Collection field |
| 86 | */ |
| 87 | var vcname; |
Akron | c1457bf | 2015-06-11 19:24:00 +0200 | [diff] [blame] | 88 | var input = document.getElementById('collection'); |
Nils Diewald | 7148c6f | 2015-05-04 15:07:53 +0000 | [diff] [blame] | 89 | if (input) { |
| 90 | input.style.display = 'none'; |
| 91 | vcname = document.createElement('span'); |
| 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 | 27ae9ec | 2015-06-23 00:43:21 +0200 | [diff] [blame] | 95 | var currentVC = loc.VC_allCorpora; |
| 96 | if (KorAP.koralQuery !== undefined && KorAP.koralQuery["collection"]) { |
Akron | 19d97fe | 2016-09-06 20:47:05 +0200 | [diff] [blame] | 97 | currentVC = loc.VC_oneCollection; |
Akron | 27ae9ec | 2015-06-23 00:43:21 +0200 | [diff] [blame] | 98 | }; |
| 99 | |
Nils Diewald | 7148c6f | 2015-05-04 15:07:53 +0000 | [diff] [blame] | 100 | vcname.appendChild( |
Akron | 19d97fe | 2016-09-06 20:47:05 +0200 | [diff] [blame] | 101 | document.createTextNode( |
| 102 | document.getElementById('collection-name').value || currentVC |
| 103 | ) |
Nils Diewald | 7148c6f | 2015-05-04 15:07:53 +0000 | [diff] [blame] | 104 | ); |
Akron | 27ae9ec | 2015-06-23 00:43:21 +0200 | [diff] [blame] | 105 | |
Nils Diewald | 7148c6f | 2015-05-04 15:07:53 +0000 | [diff] [blame] | 106 | input.parentNode.insertBefore(vcname, input); |
| 107 | }; |
| 108 | |
Nils Diewald | 7148c6f | 2015-05-04 15:07:53 +0000 | [diff] [blame] | 109 | /** |
Nils Diewald | a297f06 | 2015-04-02 00:23:46 +0000 | [diff] [blame] | 110 | * Add actions to match entries |
| 111 | */ |
Nils Diewald | 5c5a747 | 2015-04-02 22:13:38 +0000 | [diff] [blame] | 112 | var inactiveLi = document.querySelectorAll( |
| 113 | '#search > ol > li:not(.active)' |
| 114 | ); |
Nils Diewald | a297f06 | 2015-04-02 00:23:46 +0000 | [diff] [blame] | 115 | var i = 0; |
Akron | 6a535d4 | 2015-08-26 20:16:58 +0200 | [diff] [blame] | 116 | |
Nils Diewald | a297f06 | 2015-04-02 00:23:46 +0000 | [diff] [blame] | 117 | for (i = 0; i < inactiveLi.length; i++) { |
Nils Diewald | 5c5a747 | 2015-04-02 22:13:38 +0000 | [diff] [blame] | 118 | inactiveLi[i].addEventListener('click', function (e) { |
Akron | 19d97fe | 2016-09-06 20:47:05 +0200 | [diff] [blame] | 119 | if (this._match !== undefined) |
| 120 | this._match.open(); |
| 121 | else { |
| 122 | // lazyLoad |
| 123 | matchClass.create(this).open(); |
| 124 | }; |
| 125 | e.halt(); |
Nils Diewald | a297f06 | 2015-04-02 00:23:46 +0000 | [diff] [blame] | 126 | }); |
Akron | 6a535d4 | 2015-08-26 20:16:58 +0200 | [diff] [blame] | 127 | inactiveLi[i].addEventListener('keydown', function (e) { |
Akron | 19d97fe | 2016-09-06 20:47:05 +0200 | [diff] [blame] | 128 | var code = _codeFromEvent(e); |
| 129 | |
| 130 | switch (code) { |
| 131 | case 32: |
| 132 | if (this._match !== undefined) |
| 133 | this._match.toggle(); |
| 134 | else { |
| 135 | // lazyLoad |
| 136 | matchClass.create(this).open(); |
| 137 | }; |
| 138 | e.halt(); |
| 139 | break; |
| 140 | }; |
Akron | 6a535d4 | 2015-08-26 20:16:58 +0200 | [diff] [blame] | 141 | }); |
Nils Diewald | a297f06 | 2015-04-02 00:23:46 +0000 | [diff] [blame] | 142 | }; |
| 143 | |
Akron | 6bb7158 | 2016-06-10 20:41:08 +0200 | [diff] [blame] | 144 | // Replace QL select menus with KorAP menus |
Akron | aba7a5a | 2016-08-15 21:58:33 +0200 | [diff] [blame] | 145 | var qlField = document.getElementById('ql-field'); |
| 146 | if (qlField !== null) { |
| 147 | selectMenuClass.create( |
| 148 | document.getElementById('ql-field').parentNode |
| 149 | ).limit(5); |
| 150 | }; |
Akron | 6bb7158 | 2016-06-10 20:41:08 +0200 | [diff] [blame] | 151 | |
Akron | 179c8ac | 2015-06-30 19:30:50 +0200 | [diff] [blame] | 152 | var result = document.getElementById('resultinfo'); |
Akron | 6ed1399 | 2016-05-23 18:06:05 +0200 | [diff] [blame] | 153 | var resultButton = null; |
Akron | 9a5b1e1 | 2016-12-06 18:18:23 +0100 | [diff] [blame] | 154 | var leftButton = null; |
Akron | 179c8ac | 2015-06-30 19:30:50 +0200 | [diff] [blame] | 155 | if (result != null) { |
Akron | 9a5b1e1 | 2016-12-06 18:18:23 +0100 | [diff] [blame] | 156 | |
| 157 | // Add right buttons |
Akron | 179c8ac | 2015-06-30 19:30:50 +0200 | [diff] [blame] | 158 | resultButton = result.appendChild(document.createElement('div')); |
Akron | 9a5b1e1 | 2016-12-06 18:18:23 +0100 | [diff] [blame] | 159 | resultButton.classList.add('result', 'button'); |
| 160 | |
| 161 | leftButton = result.appendChild(document.createElement('div')); |
| 162 | leftButton.classList.add('result', 'button', 'left'); |
Akron | 179c8ac | 2015-06-30 19:30:50 +0200 | [diff] [blame] | 163 | }; |
| 164 | |
| 165 | // There is a koralQuery |
Akron | 7716f01 | 2015-07-01 20:38:32 +0200 | [diff] [blame] | 166 | if (KorAP.koralQuery !== undefined) { |
Akron | 179c8ac | 2015-06-30 19:30:50 +0200 | [diff] [blame] | 167 | |
Akron | 7716f01 | 2015-07-01 20:38:32 +0200 | [diff] [blame] | 168 | if (resultButton !== null) { |
Akron | 19d97fe | 2016-09-06 20:47:05 +0200 | [diff] [blame] | 169 | var kq; |
| 170 | var toggle = document.createElement('a'); |
| 171 | toggle.setAttribute('title', loc.SHOW_KQ) |
| 172 | toggle.classList.add('show-kq', 'button'); |
| 173 | toggle.appendChild(document.createElement('span')) |
| 174 | .appendChild(document.createTextNode(loc.SHOW_KQ)); |
| 175 | resultButton.appendChild(toggle); |
Akron | 179c8ac | 2015-06-30 19:30:50 +0200 | [diff] [blame] | 176 | |
Akron | 19d97fe | 2016-09-06 20:47:05 +0200 | [diff] [blame] | 177 | var showKQ = function () { |
| 178 | if (kq === undefined) { |
| 179 | kq = document.createElement('div'); |
| 180 | kq.setAttribute('id', 'koralquery'); |
| 181 | kq.style.display = 'none'; |
| 182 | var kqInner = document.createElement('div'); |
| 183 | kq.appendChild(kqInner); |
| 184 | kqInner.innerHTML = JSON.stringify(KorAP.koralQuery, null, ' '); |
| 185 | hljs.highlightBlock(kqInner); |
| 186 | var sb = document.getElementById('search'); |
| 187 | sb.insertBefore(kq, sb.firstChild); |
| 188 | }; |
Akron | 7716f01 | 2015-07-01 20:38:32 +0200 | [diff] [blame] | 189 | |
Akron | 19d97fe | 2016-09-06 20:47:05 +0200 | [diff] [blame] | 190 | if (kq.style.display === 'none') { |
| 191 | kq.style.display = 'block'; |
| 192 | show['kq'] = true; |
| 193 | } |
| 194 | else { |
| 195 | kq.style.display = 'none'; |
| 196 | delete show['kq']; |
| 197 | }; |
| 198 | }; |
Akron | 7716f01 | 2015-07-01 20:38:32 +0200 | [diff] [blame] | 199 | |
Akron | 19d97fe | 2016-09-06 20:47:05 +0200 | [diff] [blame] | 200 | if (toggle !== undefined) { |
| 201 | |
| 202 | // Show koralquery |
| 203 | toggle.addEventListener('click', showKQ); |
| 204 | }; |
Akron | 179c8ac | 2015-06-30 19:30:50 +0200 | [diff] [blame] | 205 | }; |
Akron | 7716f01 | 2015-07-01 20:38:32 +0200 | [diff] [blame] | 206 | |
Akron | 00cd4d1 | 2016-05-31 21:01:11 +0200 | [diff] [blame] | 207 | if (KorAP.koralQuery["errors"]) { |
Akron | 19d97fe | 2016-09-06 20:47:05 +0200 | [diff] [blame] | 208 | var errors = KorAP.koralQuery["errors"]; |
| 209 | for (var i in errors) { |
Akron | f0c31ed | 2016-06-11 11:27:01 +0200 | [diff] [blame] | 210 | |
Akron | 19d97fe | 2016-09-06 20:47:05 +0200 | [diff] [blame] | 211 | // Malformed query |
| 212 | if (errors[i][0] === 302 && errors[i][2]) { |
| 213 | obj.hint = hintClass.create(); |
| 214 | obj.hint.alert(errors[i][2], errors[i][1]); |
| 215 | break; |
| 216 | } |
Akron | f0c31ed | 2016-06-11 11:27:01 +0200 | [diff] [blame] | 217 | |
Akron | 19d97fe | 2016-09-06 20:47:05 +0200 | [diff] [blame] | 218 | // no query |
| 219 | else if (errors[i][0] === 301) { |
| 220 | obj.hint = hintClass.create(); |
| 221 | obj.hint.alert(0, errors[i][1]); |
| 222 | } |
| 223 | } |
Akron | 00cd4d1 | 2016-05-31 21:01:11 +0200 | [diff] [blame] | 224 | }; |
| 225 | |
Akron | 7716f01 | 2015-07-01 20:38:32 +0200 | [diff] [blame] | 226 | // Session has KQ visibility stored |
| 227 | if (show["kq"]) |
Akron | 19d97fe | 2016-09-06 20:47:05 +0200 | [diff] [blame] | 228 | showKQ.apply(); |
Akron | 179c8ac | 2015-06-30 19:30:50 +0200 | [diff] [blame] | 229 | }; |
| 230 | |
Akron | 9a5b1e1 | 2016-12-06 18:18:23 +0100 | [diff] [blame] | 231 | // There is more than 0 matches and there is a resultButton |
| 232 | if (i > 0) { |
Nils Diewald | 7148c6f | 2015-05-04 15:07:53 +0000 | [diff] [blame] | 233 | |
Akron | 9a5b1e1 | 2016-12-06 18:18:23 +0100 | [diff] [blame] | 234 | if (resultButton !== null) { |
| 235 | |
| 236 | /** |
| 237 | * Toggle the alignment (left <=> right) |
| 238 | */ |
| 239 | // querySelector('div.button.right'); |
| 240 | |
| 241 | var toggle = document.createElement('a'); |
| 242 | toggle.setAttribute('title', loc.TOGGLE_ALIGN); |
| 243 | // Todo: Reuse old alignment from query |
| 244 | var cl = toggle.classList; |
| 245 | cl.add('align', 'right', 'button'); |
| 246 | toggle.addEventListener( |
| 247 | 'click', |
| 248 | function (e) { |
| 249 | var ol = document.querySelector('#search > ol'); |
| 250 | ol.toggleClass("align-left", "align-right"); |
| 251 | this.toggleClass("left", "right"); |
| 252 | }); |
| 253 | toggle.appendChild(document.createElement('span')) |
| 254 | .appendChild(document.createTextNode(loc.TOGGLE_ALIGN)); |
| 255 | resultButton.appendChild(toggle); |
| 256 | }; |
| 257 | |
| 258 | /* |
| 259 | // Not ready yet |
| 260 | if (leftButton !== null) { |
| 261 | var metaInfo = document.createElement('a'); |
| 262 | metaInfo.setAttribute('title', loc.SHOW_META) |
| 263 | |
| 264 | var cl = metaInfo.classList; |
| 265 | cl.add('show-meta', 'button'); |
| 266 | metaInfo.appendChild(document.createElement('span')) |
| 267 | .appendChild(document.createTextNode(loc.SHOW_META)); |
| 268 | leftButton.appendChild(metaInfo); |
| 269 | }; |
| 270 | */ |
Nils Diewald | a297f06 | 2015-04-02 00:23:46 +0000 | [diff] [blame] | 271 | }; |
Nils Diewald | 5c5a747 | 2015-04-02 22:13:38 +0000 | [diff] [blame] | 272 | |
Nils Diewald | 7148c6f | 2015-05-04 15:07:53 +0000 | [diff] [blame] | 273 | /** |
| 274 | * Toggle the Virtual Collection builder |
| 275 | */ |
| 276 | if (vcname) { |
Nils Diewald | 6283d69 | 2015-04-23 20:32:53 +0000 | [diff] [blame] | 277 | var vc; |
Akron | 179c8ac | 2015-06-30 19:30:50 +0200 | [diff] [blame] | 278 | var vcclick = function () { |
Akron | 19d97fe | 2016-09-06 20:47:05 +0200 | [diff] [blame] | 279 | var view = document.getElementById('vc-view'); |
Nils Diewald | 6283d69 | 2015-04-23 20:32:53 +0000 | [diff] [blame] | 280 | |
Akron | 19d97fe | 2016-09-06 20:47:05 +0200 | [diff] [blame] | 281 | // The vc is visible |
| 282 | if (vcname.classList.contains('active')) { |
| 283 | view.removeChild(vc.element()); |
| 284 | vcname.classList.remove('active'); |
| 285 | delete show['collection']; |
| 286 | } |
Nils Diewald | 6283d69 | 2015-04-23 20:32:53 +0000 | [diff] [blame] | 287 | |
Akron | 19d97fe | 2016-09-06 20:47:05 +0200 | [diff] [blame] | 288 | // The vc is not visible |
| 289 | else { |
| 290 | if (vc === undefined) |
| 291 | vc = _getCurrentVC(vcClass, vcArray); |
| 292 | view.appendChild(vc.element()); |
| 293 | vcname.classList.add('active'); |
| 294 | show['collection'] = true; |
| 295 | }; |
Nils Diewald | 5814133 | 2015-04-07 16:18:45 +0000 | [diff] [blame] | 296 | }; |
Akron | 179c8ac | 2015-06-30 19:30:50 +0200 | [diff] [blame] | 297 | vcname.onclick = vcclick; |
Akron | 7716f01 | 2015-07-01 20:38:32 +0200 | [diff] [blame] | 298 | if (show['collection']) { |
Akron | 19d97fe | 2016-09-06 20:47:05 +0200 | [diff] [blame] | 299 | vcclick.apply(); |
Akron | 179c8ac | 2015-06-30 19:30:50 +0200 | [diff] [blame] | 300 | }; |
Nils Diewald | 5814133 | 2015-04-07 16:18:45 +0000 | [diff] [blame] | 301 | }; |
| 302 | |
Akron | 19d97fe | 2016-09-06 20:47:05 +0200 | [diff] [blame] | 303 | |
Nils Diewald | 5814133 | 2015-04-07 16:18:45 +0000 | [diff] [blame] | 304 | /** |
| 305 | * Init Tutorial view |
| 306 | */ |
Nils Diewald | fccfbcb | 2015-04-29 20:48:19 +0000 | [diff] [blame] | 307 | if (document.getElementById('view-tutorial')) { |
| 308 | window.tutorial = tutClass.create( |
Akron | 19d97fe | 2016-09-06 20:47:05 +0200 | [diff] [blame] | 309 | document.getElementById('view-tutorial'), |
| 310 | session |
Nils Diewald | fccfbcb | 2015-04-29 20:48:19 +0000 | [diff] [blame] | 311 | ); |
| 312 | obj.tutorial = window.tutorial; |
| 313 | } |
Nils Diewald | 5814133 | 2015-04-07 16:18:45 +0000 | [diff] [blame] | 314 | |
Nils Diewald | fccfbcb | 2015-04-29 20:48:19 +0000 | [diff] [blame] | 315 | // Tutorial is in parent |
| 316 | else if (window.parent) { |
| 317 | obj.tutorial = window.parent.tutorial; |
| 318 | }; |
| 319 | |
| 320 | // Initialize queries for document |
Akron | 6ed1399 | 2016-05-23 18:06:05 +0200 | [diff] [blame] | 321 | if (obj.tutorial) { |
Nils Diewald | 4347ee9 | 2015-05-04 20:32:48 +0000 | [diff] [blame] | 322 | obj.tutorial.initQueries(document); |
Nils Diewald | fccfbcb | 2015-04-29 20:48:19 +0000 | [diff] [blame] | 323 | |
Akron | 6ed1399 | 2016-05-23 18:06:05 +0200 | [diff] [blame] | 324 | // Initialize documentation links |
| 325 | obj.tutorial.initDocLinks(document); |
| 326 | }; |
Nils Diewald | 61e6ff5 | 2015-05-07 17:26:50 +0000 | [diff] [blame] | 327 | |
Nils Diewald | 845282c | 2015-05-14 07:53:03 +0000 | [diff] [blame] | 328 | |
Nils Diewald | 5814133 | 2015-04-07 16:18:45 +0000 | [diff] [blame] | 329 | /** |
Akron | c1457bf | 2015-06-11 19:24:00 +0200 | [diff] [blame] | 330 | * Add VC creation on submission. |
| 331 | */ |
| 332 | var form = document.getElementById('searchform'); |
Akron | 792f58b | 2015-07-08 18:59:36 +0200 | [diff] [blame] | 333 | if (form !== null) { |
Akron | c1457bf | 2015-06-11 19:24:00 +0200 | [diff] [blame] | 334 | form.addEventListener('submit', function (e) { |
Akron | 19d97fe | 2016-09-06 20:47:05 +0200 | [diff] [blame] | 335 | var qf = document.getElementById('q-field'); |
Akron | c1457bf | 2015-06-11 19:24:00 +0200 | [diff] [blame] | 336 | |
Akron | 19d97fe | 2016-09-06 20:47:05 +0200 | [diff] [blame] | 337 | // No query was defined |
| 338 | if (qf.value === undefined || qf.value === '') { |
| 339 | qf.focus(); |
| 340 | e.halt(); |
| 341 | KorAP.log(700, "No query given"); |
| 342 | return; |
| 343 | }; |
Akron | 7716f01 | 2015-07-01 20:38:32 +0200 | [diff] [blame] | 344 | |
Akron | 19d97fe | 2016-09-06 20:47:05 +0200 | [diff] [blame] | 345 | // Store session information |
| 346 | session.set("show", show); |
Akron | 7716f01 | 2015-07-01 20:38:32 +0200 | [diff] [blame] | 347 | |
Akron | 19d97fe | 2016-09-06 20:47:05 +0200 | [diff] [blame] | 348 | // Set Virtual collection |
| 349 | if (vc === undefined) { |
| 350 | vc = _getCurrentVC(vcClass, vcArray); |
| 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 | if (vc !== undefined) { |
| 354 | input.value = vc.toQuery(); |
| 355 | } |
| 356 | else { |
| 357 | delete input['value']; |
| 358 | }; |
Akron | c1457bf | 2015-06-11 19:24:00 +0200 | [diff] [blame] | 359 | }); |
| 360 | }; |
| 361 | |
| 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 | |
Nils Diewald | 5814133 | 2015-04-07 16:18:45 +0000 | [diff] [blame] | 372 | return obj; |
Nils Diewald | 0e6992a | 2015-04-14 20:13:52 +0000 | [diff] [blame] | 373 | }); |
| 374 | }); |
Akron | c1457bf | 2015-06-11 19:24:00 +0200 | [diff] [blame] | 375 | |
| 376 | // Render Virtual collection |
Akron | 27ae9ec | 2015-06-23 00:43:21 +0200 | [diff] [blame] | 377 | function _getCurrentVC (vcClass, vcArray) { |
| 378 | var vc = vcClass.create(vcArray); |
| 379 | if (KorAP.koralQuery !== undefined && KorAP.koralQuery["collection"]) { |
| 380 | vc.fromJson(KorAP.koralQuery["collection"]); |
| 381 | }; |
Akron | c1457bf | 2015-06-11 19:24:00 +0200 | [diff] [blame] | 382 | return vc; |
| 383 | }; |