forked from barryclark/jekyll-now
-
Notifications
You must be signed in to change notification settings - Fork 9
/
mi-2017.js
178 lines (125 loc) · 4.45 KB
/
mi-2017.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
document.querySelector('.nav-toggle').addEventListener('click', function() {
var activeClass = 'is-active';
document.querySelector('.nav-menu').classList.toggle(activeClass);
});
var tabs = {};
tabs.elements = {};
tabs.func = (function(){
var exports = {};
exports.init = function(){
// Content ausblenden
tabs.elements.content = {};
var tabWraps = document.querySelectorAll('.is-tab-wrap');
//if(tabWraps.length <= 1){ return false; }
for(i=0; i<tabWraps.length; i++){
var tabWrap = tabWraps[i];
tabContents = tabWrap.querySelectorAll('.is-tab-content');
tabContents[1].classList.add('is-hidden');
}
// Tab Navi aktivieren
var tabNavigations = document.querySelectorAll('.is-tab-navigation');
for(i=0; i<tabNavigations.length; i++){
var tabNavigation = tabNavigations[i];
var htmltabs = tabNavigation.querySelectorAll('.tab-item');
htmltabs[0].classList.add('is-active');
for(i=0; i<htmltabs.length; i++){
var htmltab = htmltabs[i];
htmltab.onclick = function() {
var target_id = this.getAttribute('data-tab');
var target = document.getElementById(target_id);
// Content ausblenden
var elements = target.parentElement.querySelectorAll('.is-tab-content');
for(i=0; i<elements.length; i++){
var element = elements[i];
element.classList.add('is-hidden');
}
// gewählten Content einblenden
target.classList.remove('is-hidden');
// Aktiven Navipunkt markieren
var elements = this.parentElement.querySelectorAll('.tab-item');
for(i=0; i<elements.length; i++){
var element = elements[i];
element.classList.remove('is-active');
}
this.classList.add('is-active');
};
}
}
}
return exports;
})();
var more = {};
more.elements = {};
more.func = (function(){
var exports = {};
exports.init = function(){
var elements = document.querySelectorAll('[data-target]');
for(i=0; i<elements.length; i++){
var ele = elements[i];
var item = document.createElement("i");
item.classList.add("fa");
item.classList.add("fa-angle-down");
item.classList.add("fa-lg");
item.classList.add("more-button");
item.onclick = function(){
if(this.classList.contains("active")){
var target = this.parentElement.getAttribute("data-target");
this.classList.remove("active");
document.getElementById(target).classList.add('is-hidden');
}else{
var target = this.parentElement.getAttribute("data-target");
this.classList.add("active");
document.getElementById(target).classList.remove('is-hidden');
}
}
ele.appendChild(item);
}
}
return exports;
})();
var urlParams = new URLSearchParams(window.location.search);
if(!urlParams.has('media')){
more.func.init();
tabs.func.init();
}
/* Insert Email Adresses
############################################################################ */
const insertEmailAdresses = (target, term)=>{
if(!window.location.href.match(/127\.0\.0\.1/)) return;
const emailDataNodes = document.querySelectorAll('[data-verantwortlich]');
const splitAdresses = (adresses) => {
if(adresses.match(/, /)) return adresses.split(/, /);
if(adresses.match(/,/)) return adresses.split(/,/);
return [adresses];
};
const addButton = (adresses)=>{
const link = document.createElement("a");
const { program } = pageData;
link.innerHTML = "Mail an die Dozenten";
link.href = `mailto: ${Object.keys(emailAdresses).join(',')}?subject=Modulbeschreibungen und Prüfungen im ${program} `;
target.appendChild(link);
}
const emailAdresses = {};
emailDataNodes.forEach((node, currentIndex, listObj) => {
if(!node.dataset.verantwortlich.match(/@/)) return;
const adresses = splitAdresses(node.dataset.verantwortlich);
adresses.forEach(adress => {
if(!emailAdresses[adress]) emailAdresses[adress] = 0;
if(adress.match(/[a-z]/)){
emailAdresses[adress]++;
}
});
}
);
addButton(emailAdresses);
};
/* Mail
############################################################################ */
document.addEventListener('DOMContentLoaded', (event) => {
const insertEmailsJSws = document.querySelector('[data-js=insert-emails-ws]');
if(insertEmailsJSws === null) return false;
insertEmailAdresses(insertEmailsJSws, 'ws');
const insertEmailsJSss = document.querySelector('[data-js=insert-emails-ss]');
if(insertEmailsJSss === null) return false;
insertEmailAdresses(insertEmailsJSss, 'ss');
});