blob: 66bc0817f24b13bda17206b53fe4a3e71e87c526 [file] [log] [blame]
Nils Diewald0e6992a2015-04-14 20:13:52 +00001define([
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 Diewalda297f062015-04-02 00:23:46 +000015
16 /**
17 * Add actions to match entries
18 */
Nils Diewald5c5a7472015-04-02 22:13:38 +000019 var inactiveLi = document.querySelectorAll(
20 '#search > ol > li:not(.active)'
21 );
Nils Diewalda297f062015-04-02 00:23:46 +000022 var i = 0;
23 for (i = 0; i < inactiveLi.length; i++) {
Nils Diewald5c5a7472015-04-02 22:13:38 +000024 inactiveLi[i].addEventListener('click', function (e) {
25 if (this._match !== undefined)
Nils Diewalda297f062015-04-02 00:23:46 +000026 this._match.open();
Nils Diewald0e6992a2015-04-14 20:13:52 +000027 else {
28 matchClass.create(this).open();
29 };
Nils Diewald5c5a7472015-04-02 22:13:38 +000030 e.halt();
Nils Diewalda297f062015-04-02 00:23:46 +000031 });
32 };
33
34 /**
35 * Toggle the alignment (left <=> right)
36 */
37 if (i > 0) {
38 var br = document.getElementById('button-right');
Nils Diewald5c5a7472015-04-02 22:13:38 +000039 if (br !== null) {
Nils Diewalda297f062015-04-02 00:23:46 +000040 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 Diewald5c5a7472015-04-02 22:13:38 +000058
59 /**
Nils Diewald58141332015-04-07 16:18:45 +000060 * Init vc
Nils Diewald5c5a7472015-04-02 22:13:38 +000061 */
Nils Diewald58141332015-04-07 16:18:45 +000062 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 Diewald0e6992a2015-04-14 20:13:52 +000075 var vc = vcClass.render(vcExample);
Nils Diewald58141332015-04-07 16:18:45 +000076 var view = document.getElementById('vc-view');
77 view.appendChild(vc.element());
78 };
79 };
80
Nils Diewald0e6992a2015-04-14 20:13:52 +000081
Nils Diewald58141332015-04-07 16:18:45 +000082 /**
83 * Init Tutorial view
84 */
Nils Diewald0e6992a2015-04-14 20:13:52 +000085 obj.tutorial = tutClass.create(
Nils Diewald58141332015-04-07 16:18:45 +000086 document.getElementById('view-tutorial')
87 );
88
Nils Diewald0e6992a2015-04-14 20:13:52 +000089
Nils Diewald58141332015-04-07 16:18:45 +000090 /**
91 * Init hint helper
92 * has to be final because of
93 * reposition
94 */
Nils Diewald0e6992a2015-04-14 20:13:52 +000095 // Todo: Pass an element, so this works with
96 // tutorial pages as well!
97 obj.hint = hintClass.create();
Nils Diewald58141332015-04-07 16:18:45 +000098 return obj;
Nils Diewald0e6992a2015-04-14 20:13:52 +000099 });
100});