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