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); |
| 73 | |
| 74 | vcname.onclick = function () { |
Nils Diewald | 0e6992a | 2015-04-14 20:13:52 +0000 | [diff] [blame] | 75 | var vc = vcClass.render(vcExample); |
Nils Diewald | 5814133 | 2015-04-07 16:18:45 +0000 | [diff] [blame] | 76 | var view = document.getElementById('vc-view'); |
| 77 | view.appendChild(vc.element()); |
| 78 | }; |
| 79 | }; |
| 80 | |
Nils Diewald | 0e6992a | 2015-04-14 20:13:52 +0000 | [diff] [blame] | 81 | |
Nils Diewald | 5814133 | 2015-04-07 16:18:45 +0000 | [diff] [blame] | 82 | /** |
| 83 | * Init Tutorial view |
| 84 | */ |
Nils Diewald | 0e6992a | 2015-04-14 20:13:52 +0000 | [diff] [blame] | 85 | obj.tutorial = tutClass.create( |
Nils Diewald | 5814133 | 2015-04-07 16:18:45 +0000 | [diff] [blame] | 86 | document.getElementById('view-tutorial') |
| 87 | ); |
| 88 | |
Nils Diewald | 0e6992a | 2015-04-14 20:13:52 +0000 | [diff] [blame] | 89 | |
Nils Diewald | 5814133 | 2015-04-07 16:18:45 +0000 | [diff] [blame] | 90 | /** |
| 91 | * Init hint helper |
| 92 | * has to be final because of |
| 93 | * reposition |
| 94 | */ |
Nils Diewald | 0e6992a | 2015-04-14 20:13:52 +0000 | [diff] [blame] | 95 | // Todo: Pass an element, so this works with |
| 96 | // tutorial pages as well! |
| 97 | obj.hint = hintClass.create(); |
Nils Diewald | 5814133 | 2015-04-07 16:18:45 +0000 | [diff] [blame] | 98 | return obj; |
Nils Diewald | 0e6992a | 2015-04-14 20:13:52 +0000 | [diff] [blame] | 99 | }); |
| 100 | }); |