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 | fccfbcb | 2015-04-29 20:48:19 +0000 | [diff] [blame^] | 111 | if (document.getElementById('view-tutorial')) { |
| 112 | window.tutorial = tutClass.create( |
| 113 | document.getElementById('view-tutorial') |
| 114 | ); |
| 115 | obj.tutorial = window.tutorial; |
| 116 | } |
Nils Diewald | 5814133 | 2015-04-07 16:18:45 +0000 | [diff] [blame] | 117 | |
Nils Diewald | fccfbcb | 2015-04-29 20:48:19 +0000 | [diff] [blame^] | 118 | // Tutorial is in parent |
| 119 | else if (window.parent) { |
| 120 | obj.tutorial = window.parent.tutorial; |
| 121 | }; |
| 122 | |
| 123 | // Initialize queries for document |
| 124 | obj.tutorial.initQueries(document); |
| 125 | |
Nils Diewald | 5814133 | 2015-04-07 16:18:45 +0000 | [diff] [blame] | 126 | /** |
| 127 | * Init hint helper |
| 128 | * has to be final because of |
| 129 | * reposition |
| 130 | */ |
Nils Diewald | 0e6992a | 2015-04-14 20:13:52 +0000 | [diff] [blame] | 131 | // Todo: Pass an element, so this works with |
| 132 | // tutorial pages as well! |
| 133 | obj.hint = hintClass.create(); |
Nils Diewald | 5814133 | 2015-04-07 16:18:45 +0000 | [diff] [blame] | 134 | return obj; |
Nils Diewald | 0e6992a | 2015-04-14 20:13:52 +0000 | [diff] [blame] | 135 | }); |
| 136 | }); |