-
Notifications
You must be signed in to change notification settings - Fork 33
/
Copy pathindex.js
163 lines (163 loc) · 7.36 KB
/
index.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
"use strict";
var gh = new GitHub({
token: 'b4eff74db53c9f3279ab41df31aafc90a8fdc9cc'
});
var podcast = gh.getRepo('inidaname', 'podcast');
podcast.getContributors();
console.log(podcast.getCollaborators());
var broadcast;
var frequency;
var myRequest = new Request('./data/podcasts.json');
var categories = new Promise(function (resolve, reject) {
fetch(myRequest)
.then(function (response) {
return response.json();
})
.then(function (response) {
var newCategory = [];
var finalCategory = [];
var lanCat = [];
var langFinal = [];
var dayCat = [];
var dayFinal = [];
var freqCat = [];
var freqFinal = [];
response.map(function (obj) {
var cat = obj.category.split(',').map(function (v) { return v.trim().toLowerCase(); });
var lang = obj.languages.split(',').map(function (v) { return v.trim().toLowerCase(); });
var days = obj.broadcast.split(',').map(function (v) { return v.trim().toLowerCase(); });
var freq = obj.updates.split(',').map(function (v) { return v.trim().toLowerCase(); });
newCategory.push.apply(newCategory, cat);
lanCat.push.apply(lanCat, lang);
freqCat.push.apply(freqCat, freq);
dayCat.push.apply(dayCat, days);
});
newCategory.map(function (v) {
if (v.length !== 0 && finalCategory.indexOf(v) < 0) {
finalCategory.push(v);
}
});
lanCat.map(function (v) {
if (v.length !== 0 && langFinal.indexOf(v) < 0) {
langFinal.push(v);
}
});
dayCat.map(function (v) {
if (v.length !== 0 && dayFinal.indexOf(v) < 0) {
dayFinal.push(v);
}
});
freqCat.map(function (v) {
if (v.length !== 0 && freqFinal.indexOf(v) < 0) {
freqFinal.push(v);
}
});
var podCastList = [finalCategory, langFinal, dayFinal, freqFinal];
if (podCastList) {
return resolve({ podCastList: podCastList, response: response });
}
else {
return reject('Empty Pod cast');
}
});
});
categories.then(function (res) {
var re = res.podCastList;
var category = document.createElement('ul');
re[0].map(function (v, i) {
var theChildren = document.createElement('li');
theChildren.appendChild(document.createTextNode(v.toUpperCase()));
theChildren.setAttribute('class', 'subMenu');
theChildren.addEventListener('click', function (event) {
console.log(event);
});
return category.appendChild(theChildren);
}).join(' ');
var cat = document.getElementById('category');
cat.appendChild(category);
var languages = document.createElement('ul');
re[1].map(function (v, i) {
var theChildren = document.createElement('li');
theChildren.appendChild(document.createTextNode(v.toUpperCase()));
theChildren.setAttribute('class', 'subMenu');
theChildren.addEventListener('click', function (event) {
console.log(event);
});
return languages.appendChild(theChildren);
}).join(' ');
var lang = document.getElementById('language');
lang.appendChild(languages);
var releaseDays = document.createElement('ul');
re[3].map(function (v, i) {
var theChildren = document.createElement('li');
theChildren.appendChild(document.createTextNode(v.toUpperCase()));
theChildren.setAttribute('class', 'subMenu');
theChildren.addEventListener('click', function (event) {
console.log(event);
});
return releaseDays.appendChild(theChildren);
}).join(' ');
var day = document.getElementById('broadcast');
day.appendChild(releaseDays);
var frquencies = document.createElement('ul');
re[2].map(function (v, i) {
var theChildren = document.createElement('li');
theChildren.appendChild(document.createTextNode(v.toUpperCase()));
theChildren.setAttribute('class', 'subMenu');
theChildren.addEventListener('click', function (event) {
var events = event.target;
console.log(re[2][i]);
});
return frquencies.appendChild(theChildren);
}).join(' ');
var freq = document.getElementById('frequency');
freq.appendChild(frquencies);
var contents = res.response;
var podcastEl = document.createElement('ul');
podcastEl.classList.add('podcast');
contents.map(function (v, i) {
var mainURL = (v.url !== undefined && v.url.substring(0, 4) !== 'http') ? "http://" + v.url : v.url;
var listBe = "\n <a href=\"" + mainURL + "\" target=\"_blank\">\n <li class=\"podList\">\n <div>\n <h3> " + v.name + " </h3>\n <img src=\"" + v.logo + "\" alt=\"" + v.name + "\">\n <ul>\n <li>\n <strong>Host Name:</strong> <br> " + v.host + "\n </li>\n <li>\n <strong>Description:</strong> <br> " + v.description + "\n </li>\n <li>\n <span><strong>Updates:</strong>" + v.updates + "</span>\n <span><strong>Release:</strong>\n " + v.broadcast + "</span>\n </li>\n <li>\n <strong>Category:</strong> <br> " + v.category + "\n </li>\n <li>\n <strong>Language:</strong> <br> " + v.languages + "\n </li>\n </ul>\n </div>\n </li>\n </a>\n ";
return podcastEl.append(document.createRange().createContextualFragment(listBe));
}).join(' ');
var mainList = document.getElementById('mainList');
mainList.appendChild(podcastEl);
})
.catch(function (reason) {
console.log(reason);
});
var listMenu = document.querySelectorAll('#sideContent li');
var nullMe;
var listTrig;
listMenu.forEach(function (el) {
el.addEventListener('click', function (ev) {
listMenu.forEach(function (e) {
if (e.getAttribute('id') !== ev.target.attributes.getNamedItem('id').value) {
e.style.opacity = '0';
e.children[0].style.opacity = '0';
e.children[0].style.height = '0px';
e.children[0].style.overFlow = 'none';
e.classList.remove('checkMe');
}
else {
if (e.classList.contains('checkMe')) {
e.classList.remove('checkMe');
el.style.opacity = '1';
e.children[0].style.opacity = '0';
e.children[0].style.overFlow = 'none';
e.children[0].style.height = '0px';
}
else {
e.classList.add('checkMe');
e.style.opacity = '1';
e.children[0].style.opacity = '1';
e.children[0].style.height = '400px';
e.children[0].style.overFlow = 'block';
}
}
});
});
});
function openNav() {
console.log();
}