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