Nils Diewald | 0e6992a | 2015-04-14 20:13:52 +0000 | [diff] [blame] | 1 | define([ |
| 2 | 'match', |
| 3 | 'hint', |
| 4 | 'vc', |
| 5 | 'tutorial', |
| 6 | 'lib/domReady', |
Nils Diewald | 7148c6f | 2015-05-04 15:07:53 +0000 | [diff] [blame] | 7 | 'hint/array', |
| 8 | 'lib/alertify', |
| 9 | 'api', |
Nils Diewald | c46003b | 2015-05-07 15:55:35 +0000 | [diff] [blame] | 10 | 'mailToChiffre', |
Nils Diewald | 845282c | 2015-05-14 07:53:03 +0000 | [diff] [blame] | 11 | 'lib/highlight/highlight.pack', |
Nils Diewald | 0e6992a | 2015-04-14 20:13:52 +0000 | [diff] [blame] | 12 | 'util' |
| 13 | ], function (matchClass, |
| 14 | hintClass, |
| 15 | vcClass, |
| 16 | tutClass, |
Nils Diewald | 7148c6f | 2015-05-04 15:07:53 +0000 | [diff] [blame] | 17 | domReady, |
Nils Diewald | 4347ee9 | 2015-05-04 20:32:48 +0000 | [diff] [blame] | 18 | hintArray, |
| 19 | alertifyClass) { |
Nils Diewald | a0defc4 | 2015-05-07 23:54:17 +0000 | [diff] [blame] | 20 | |
| 21 | // Set hint array for hint helper |
| 22 | KorAP.hintArray = hintArray; |
| 23 | |
Akron | 9cc3eaf | 2015-06-10 22:15:52 +0200 | [diff] [blame^] | 24 | // Localization values |
| 25 | var loc = KorAP.Locale; |
| 26 | loc.VC_allCorpora = loc.VC_allCorpora || 'all Corpora'; |
| 27 | |
Nils Diewald | a0defc4 | 2015-05-07 23:54:17 +0000 | [diff] [blame] | 28 | // Override KorAP.log |
| 29 | window.alertify = alertifyClass; |
| 30 | KorAP.log = function (type, msg) { |
| 31 | |
| 32 | // Use alertify to log errors |
| 33 | alertifyClass.log( |
| 34 | (type === 0 ? '' : type + ': ') + |
| 35 | msg, |
| 36 | 'error', |
| 37 | 5000 |
| 38 | ); |
| 39 | }; |
| 40 | |
Nils Diewald | 0e6992a | 2015-04-14 20:13:52 +0000 | [diff] [blame] | 41 | domReady(function (event) { |
| 42 | var obj = {}; |
Nils Diewald | a297f06 | 2015-04-02 00:23:46 +0000 | [diff] [blame] | 43 | |
| 44 | /** |
Nils Diewald | 7148c6f | 2015-05-04 15:07:53 +0000 | [diff] [blame] | 45 | * Replace Virtual Collection field |
| 46 | */ |
| 47 | var vcname; |
| 48 | var input = document.getElementById('vc'); |
| 49 | if (input) { |
| 50 | input.style.display = 'none'; |
| 51 | vcname = document.createElement('span'); |
| 52 | vcname.setAttribute('id', 'vc-choose'); |
| 53 | vcname.appendChild( |
| 54 | document.createTextNode( |
Akron | 9cc3eaf | 2015-06-10 22:15:52 +0200 | [diff] [blame^] | 55 | document.getElementById('vc-name').value || loc.VC_allCorpora |
Nils Diewald | 7148c6f | 2015-05-04 15:07:53 +0000 | [diff] [blame] | 56 | ) |
| 57 | ); |
| 58 | input.parentNode.insertBefore(vcname, input); |
| 59 | }; |
| 60 | |
| 61 | |
| 62 | /** |
Nils Diewald | a297f06 | 2015-04-02 00:23:46 +0000 | [diff] [blame] | 63 | * Add actions to match entries |
| 64 | */ |
Nils Diewald | 5c5a747 | 2015-04-02 22:13:38 +0000 | [diff] [blame] | 65 | var inactiveLi = document.querySelectorAll( |
| 66 | '#search > ol > li:not(.active)' |
| 67 | ); |
Nils Diewald | a297f06 | 2015-04-02 00:23:46 +0000 | [diff] [blame] | 68 | var i = 0; |
| 69 | for (i = 0; i < inactiveLi.length; i++) { |
Nils Diewald | 5c5a747 | 2015-04-02 22:13:38 +0000 | [diff] [blame] | 70 | inactiveLi[i].addEventListener('click', function (e) { |
| 71 | if (this._match !== undefined) |
Nils Diewald | a297f06 | 2015-04-02 00:23:46 +0000 | [diff] [blame] | 72 | this._match.open(); |
Nils Diewald | 0e6992a | 2015-04-14 20:13:52 +0000 | [diff] [blame] | 73 | else { |
| 74 | matchClass.create(this).open(); |
| 75 | }; |
Nils Diewald | 5c5a747 | 2015-04-02 22:13:38 +0000 | [diff] [blame] | 76 | e.halt(); |
Nils Diewald | a297f06 | 2015-04-02 00:23:46 +0000 | [diff] [blame] | 77 | }); |
| 78 | }; |
| 79 | |
Nils Diewald | 7148c6f | 2015-05-04 15:07:53 +0000 | [diff] [blame] | 80 | |
Nils Diewald | a297f06 | 2015-04-02 00:23:46 +0000 | [diff] [blame] | 81 | /** |
| 82 | * Toggle the alignment (left <=> right) |
| 83 | */ |
| 84 | if (i > 0) { |
Nils Diewald | d0711ca | 2015-05-19 22:25:12 +0000 | [diff] [blame] | 85 | var br = document.querySelector('div.button.right'); |
Nils Diewald | 5c5a747 | 2015-04-02 22:13:38 +0000 | [diff] [blame] | 86 | if (br !== null) { |
Nils Diewald | a297f06 | 2015-04-02 00:23:46 +0000 | [diff] [blame] | 87 | var toggle = document.createElement('a'); |
| 88 | toggle.setAttribute('title', 'toggle Alignment'); |
| 89 | // Todo: Reuse old alignment from cookie! |
| 90 | var cl = toggle.classList; |
Nils Diewald | 7148c6f | 2015-05-04 15:07:53 +0000 | [diff] [blame] | 91 | cl.add('align', 'right'); |
Nils Diewald | a297f06 | 2015-04-02 00:23:46 +0000 | [diff] [blame] | 92 | toggle.addEventListener( |
| 93 | 'click', |
| 94 | function (e) { |
| 95 | var ol = document.querySelector('#search > ol'); |
| 96 | ol.toggleClass("align-left", "align-right"); |
| 97 | this.toggleClass("left", "right"); |
| 98 | }); |
| 99 | toggle.appendChild(document.createElement('span')) |
| 100 | .appendChild(document.createTextNode('Alignment')); |
| 101 | br.appendChild(toggle); |
| 102 | }; |
| 103 | }; |
Nils Diewald | 5c5a747 | 2015-04-02 22:13:38 +0000 | [diff] [blame] | 104 | |
Nils Diewald | 6283d69 | 2015-04-23 20:32:53 +0000 | [diff] [blame] | 105 | |
Nils Diewald | 7148c6f | 2015-05-04 15:07:53 +0000 | [diff] [blame] | 106 | /** |
| 107 | * Toggle the Virtual Collection builder |
| 108 | */ |
| 109 | if (vcname) { |
Nils Diewald | 6283d69 | 2015-04-23 20:32:53 +0000 | [diff] [blame] | 110 | var vc; |
Nils Diewald | 5814133 | 2015-04-07 16:18:45 +0000 | [diff] [blame] | 111 | vcname.onclick = function () { |
Nils Diewald | 5814133 | 2015-04-07 16:18:45 +0000 | [diff] [blame] | 112 | var view = document.getElementById('vc-view'); |
Nils Diewald | 6283d69 | 2015-04-23 20:32:53 +0000 | [diff] [blame] | 113 | |
| 114 | // The vc is visible |
| 115 | if (this.classList.contains('active')) { |
| 116 | view.removeChild(vc.element()); |
| 117 | this.classList.remove('active'); |
| 118 | } |
| 119 | |
| 120 | // The vc is not visible |
| 121 | else { |
| 122 | // The vc is not rendered yet |
| 123 | if (vc === undefined) { |
| 124 | vc = vcClass.create([ |
| 125 | ['title', 'string'], |
| 126 | ['subTitle', 'string'], |
| 127 | ['pubDate', 'date'], |
| 128 | ['author', 'string'] |
| 129 | ]); |
| 130 | |
| 131 | if (KorAP.currentVC !== undefined) |
| 132 | vc.fromJson(KorAP.currentVC); |
| 133 | }; |
| 134 | view.appendChild(vc.element()); |
| 135 | this.classList.add('active'); |
| 136 | }; |
Nils Diewald | 5814133 | 2015-04-07 16:18:45 +0000 | [diff] [blame] | 137 | }; |
| 138 | }; |
| 139 | |
Nils Diewald | 0e6992a | 2015-04-14 20:13:52 +0000 | [diff] [blame] | 140 | |
Nils Diewald | 5814133 | 2015-04-07 16:18:45 +0000 | [diff] [blame] | 141 | /** |
| 142 | * Init Tutorial view |
| 143 | */ |
Nils Diewald | fccfbcb | 2015-04-29 20:48:19 +0000 | [diff] [blame] | 144 | if (document.getElementById('view-tutorial')) { |
| 145 | window.tutorial = tutClass.create( |
| 146 | document.getElementById('view-tutorial') |
| 147 | ); |
| 148 | obj.tutorial = window.tutorial; |
| 149 | } |
Nils Diewald | 5814133 | 2015-04-07 16:18:45 +0000 | [diff] [blame] | 150 | |
Nils Diewald | fccfbcb | 2015-04-29 20:48:19 +0000 | [diff] [blame] | 151 | // Tutorial is in parent |
| 152 | else if (window.parent) { |
| 153 | obj.tutorial = window.parent.tutorial; |
| 154 | }; |
| 155 | |
| 156 | // Initialize queries for document |
Nils Diewald | 4347ee9 | 2015-05-04 20:32:48 +0000 | [diff] [blame] | 157 | if (obj.tutorial) |
| 158 | obj.tutorial.initQueries(document); |
Nils Diewald | fccfbcb | 2015-04-29 20:48:19 +0000 | [diff] [blame] | 159 | |
Nils Diewald | 61e6ff5 | 2015-05-07 17:26:50 +0000 | [diff] [blame] | 160 | // Initialize documentation links |
| 161 | obj.tutorial.initDocLinks(document); |
| 162 | |
Nils Diewald | d0711ca | 2015-05-19 22:25:12 +0000 | [diff] [blame] | 163 | /* |
Nils Diewald | 845282c | 2015-05-14 07:53:03 +0000 | [diff] [blame] | 164 | if (KorAP.currentQuery !== undefined) { |
| 165 | var sb = document.getElementById('searchbar'); |
| 166 | var kq = document.createElement('div'); |
| 167 | kq.setAttribute('id', 'koralquery'); |
| 168 | sb.parentNode.insertBefore(kq, sb.nextSibling); |
| 169 | kq.innerHTML = JSON.stringify(KorAP.currentQuery, null, ' '); |
| 170 | hljs.highlightBlock(kq); |
| 171 | }; |
Nils Diewald | d0711ca | 2015-05-19 22:25:12 +0000 | [diff] [blame] | 172 | */ |
Nils Diewald | 845282c | 2015-05-14 07:53:03 +0000 | [diff] [blame] | 173 | |
Nils Diewald | 5814133 | 2015-04-07 16:18:45 +0000 | [diff] [blame] | 174 | /** |
| 175 | * Init hint helper |
| 176 | * has to be final because of |
| 177 | * reposition |
| 178 | */ |
Nils Diewald | 0e6992a | 2015-04-14 20:13:52 +0000 | [diff] [blame] | 179 | // Todo: Pass an element, so this works with |
| 180 | // tutorial pages as well! |
| 181 | obj.hint = hintClass.create(); |
Nils Diewald | 7148c6f | 2015-05-04 15:07:53 +0000 | [diff] [blame] | 182 | |
Nils Diewald | 5814133 | 2015-04-07 16:18:45 +0000 | [diff] [blame] | 183 | return obj; |
Nils Diewald | 0e6992a | 2015-04-14 20:13:52 +0000 | [diff] [blame] | 184 | }); |
| 185 | }); |