blob: bf7c20618b63545ba0de9bd449faa982ca8e36bd [file] [log] [blame]
Nils Diewald0e6992a2015-04-14 20:13:52 +00001define([
2 'match',
3 'hint',
4 'vc',
5 'tutorial',
6 'lib/domReady',
Nils Diewald7148c6f2015-05-04 15:07:53 +00007 'hint/array',
8 'lib/alertify',
9 'api',
Nils Diewaldc46003b2015-05-07 15:55:35 +000010 'mailToChiffre',
Nils Diewald0e6992a2015-04-14 20:13:52 +000011 'util'
12], function (matchClass,
13 hintClass,
14 vcClass,
15 tutClass,
Nils Diewald7148c6f2015-05-04 15:07:53 +000016 domReady,
Nils Diewald4347ee92015-05-04 20:32:48 +000017 hintArray,
18 alertifyClass) {
Nils Diewald0e6992a2015-04-14 20:13:52 +000019 domReady(function (event) {
20 var obj = {};
Nils Diewalda297f062015-04-02 00:23:46 +000021
22 /**
Nils Diewald7148c6f2015-05-04 15:07:53 +000023 * Replace Virtual Collection field
24 */
25 var vcname;
26 var input = document.getElementById('vc');
27 if (input) {
28 input.style.display = 'none';
29 vcname = document.createElement('span');
30 vcname.setAttribute('id', 'vc-choose');
31 vcname.appendChild(
32 document.createTextNode(
33 document.getElementById('vc-name').value
34 )
35 );
36 input.parentNode.insertBefore(vcname, input);
37 };
38
39
40 /**
Nils Diewalda297f062015-04-02 00:23:46 +000041 * Add actions to match entries
42 */
Nils Diewald5c5a7472015-04-02 22:13:38 +000043 var inactiveLi = document.querySelectorAll(
44 '#search > ol > li:not(.active)'
45 );
Nils Diewalda297f062015-04-02 00:23:46 +000046 var i = 0;
47 for (i = 0; i < inactiveLi.length; i++) {
Nils Diewald5c5a7472015-04-02 22:13:38 +000048 inactiveLi[i].addEventListener('click', function (e) {
49 if (this._match !== undefined)
Nils Diewalda297f062015-04-02 00:23:46 +000050 this._match.open();
Nils Diewald0e6992a2015-04-14 20:13:52 +000051 else {
52 matchClass.create(this).open();
53 };
Nils Diewald5c5a7472015-04-02 22:13:38 +000054 e.halt();
Nils Diewalda297f062015-04-02 00:23:46 +000055 });
56 };
57
Nils Diewald7148c6f2015-05-04 15:07:53 +000058
Nils Diewalda297f062015-04-02 00:23:46 +000059 /**
60 * Toggle the alignment (left <=> right)
61 */
62 if (i > 0) {
63 var br = document.getElementById('button-right');
Nils Diewald5c5a7472015-04-02 22:13:38 +000064 if (br !== null) {
Nils Diewalda297f062015-04-02 00:23:46 +000065 var toggle = document.createElement('a');
66 toggle.setAttribute('title', 'toggle Alignment');
67 // Todo: Reuse old alignment from cookie!
68 var cl = toggle.classList;
Nils Diewald7148c6f2015-05-04 15:07:53 +000069 cl.add('align', 'right');
Nils Diewalda297f062015-04-02 00:23:46 +000070 toggle.addEventListener(
71 'click',
72 function (e) {
73 var ol = document.querySelector('#search > ol');
74 ol.toggleClass("align-left", "align-right");
75 this.toggleClass("left", "right");
76 });
77 toggle.appendChild(document.createElement('span'))
78 .appendChild(document.createTextNode('Alignment'));
79 br.appendChild(toggle);
80 };
81 };
Nils Diewald5c5a7472015-04-02 22:13:38 +000082
Nils Diewald6283d692015-04-23 20:32:53 +000083
Nils Diewald7148c6f2015-05-04 15:07:53 +000084 /**
85 * Toggle the Virtual Collection builder
86 */
87 if (vcname) {
Nils Diewald6283d692015-04-23 20:32:53 +000088 var vc;
Nils Diewald58141332015-04-07 16:18:45 +000089 vcname.onclick = function () {
Nils Diewald58141332015-04-07 16:18:45 +000090 var view = document.getElementById('vc-view');
Nils Diewald6283d692015-04-23 20:32:53 +000091
92 // The vc is visible
93 if (this.classList.contains('active')) {
94 view.removeChild(vc.element());
95 this.classList.remove('active');
96 }
97
98 // The vc is not visible
99 else {
100 // The vc is not rendered yet
101 if (vc === undefined) {
102 vc = vcClass.create([
103 ['title', 'string'],
104 ['subTitle', 'string'],
105 ['pubDate', 'date'],
106 ['author', 'string']
107 ]);
108
109 if (KorAP.currentVC !== undefined)
110 vc.fromJson(KorAP.currentVC);
111 };
112 view.appendChild(vc.element());
113 this.classList.add('active');
114 };
Nils Diewald58141332015-04-07 16:18:45 +0000115 };
116 };
117
Nils Diewald0e6992a2015-04-14 20:13:52 +0000118
Nils Diewald58141332015-04-07 16:18:45 +0000119 /**
120 * Init Tutorial view
121 */
Nils Diewaldfccfbcb2015-04-29 20:48:19 +0000122 if (document.getElementById('view-tutorial')) {
123 window.tutorial = tutClass.create(
124 document.getElementById('view-tutorial')
125 );
126 obj.tutorial = window.tutorial;
127 }
Nils Diewald58141332015-04-07 16:18:45 +0000128
Nils Diewaldfccfbcb2015-04-29 20:48:19 +0000129 // Tutorial is in parent
130 else if (window.parent) {
131 obj.tutorial = window.parent.tutorial;
132 };
133
134 // Initialize queries for document
Nils Diewald4347ee92015-05-04 20:32:48 +0000135 if (obj.tutorial)
136 obj.tutorial.initQueries(document);
Nils Diewaldfccfbcb2015-04-29 20:48:19 +0000137
Nils Diewald61e6ff52015-05-07 17:26:50 +0000138 // Initialize documentation links
139 obj.tutorial.initDocLinks(document);
140
Nils Diewald58141332015-04-07 16:18:45 +0000141 /**
142 * Init hint helper
143 * has to be final because of
144 * reposition
145 */
Nils Diewald0e6992a2015-04-14 20:13:52 +0000146 // Todo: Pass an element, so this works with
147 // tutorial pages as well!
148 obj.hint = hintClass.create();
Nils Diewald7148c6f2015-05-04 15:07:53 +0000149
150 // Set hint array for hint helper
151 KorAP.hintArray = hintArray;
152
153 // Override KorAP.log
154 KorAP.log = function (type, msg) {
155
156 // Use alertify to log errors
Nils Diewald4347ee92015-05-04 20:32:48 +0000157 alertifyClass.log(
Nils Diewald7148c6f2015-05-04 15:07:53 +0000158 (type === 0 ? '' : type + ': ') +
159 msg,
Nils Diewald4347ee92015-05-04 20:32:48 +0000160 'error',
Nils Diewald7148c6f2015-05-04 15:07:53 +0000161 5000
162 );
163 };
164
Nils Diewald58141332015-04-07 16:18:45 +0000165 return obj;
Nils Diewald0e6992a2015-04-14 20:13:52 +0000166 });
167});