blob: cd0adfc19c0312d6f7e620eec12e8dfc5975c5c8 [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);
Nils Diewald6283d692015-04-23 20:32:53 +000073
74 /**
75 * Toggle the Virtual Collection builder
76 */
77 var vc;
Nils Diewald58141332015-04-07 16:18:45 +000078 vcname.onclick = function () {
Nils Diewald58141332015-04-07 16:18:45 +000079 var view = document.getElementById('vc-view');
Nils Diewald6283d692015-04-23 20:32:53 +000080
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 Diewald58141332015-04-07 16:18:45 +0000104 };
105 };
106
Nils Diewald0e6992a2015-04-14 20:13:52 +0000107
Nils Diewald58141332015-04-07 16:18:45 +0000108 /**
109 * Init Tutorial view
110 */
Nils Diewald0e6992a2015-04-14 20:13:52 +0000111 obj.tutorial = tutClass.create(
Nils Diewald58141332015-04-07 16:18:45 +0000112 document.getElementById('view-tutorial')
113 );
114
Nils Diewald0e6992a2015-04-14 20:13:52 +0000115
Nils Diewald58141332015-04-07 16:18:45 +0000116 /**
117 * Init hint helper
118 * has to be final because of
119 * reposition
120 */
Nils Diewald0e6992a2015-04-14 20:13:52 +0000121 // Todo: Pass an element, so this works with
122 // tutorial pages as well!
123 obj.hint = hintClass.create();
Nils Diewald58141332015-04-07 16:18:45 +0000124 return obj;
Nils Diewald0e6992a2015-04-14 20:13:52 +0000125 });
126});