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