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