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