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