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