-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathindex.js
90 lines (90 loc) · 4.32 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
"use strict";
var broadcast;
var frequency;
var myRequest = new Request('./data/people.json');
var categories = new Promise(function (resolve, reject) {
fetch(myRequest)
.then(function (response) {
return response.json();
})
.then(function (response) {
var newCategory = [];
var finalCategory = [];
response.map(function (obj) {
var cat = obj.stack.split(',').map(function (v) { return v.trim().toLowerCase(); });
newCategory.push.apply(newCategory, cat);
});
newCategory.map(function (v) {
if (v.length !== 0 && finalCategory.indexOf(v) < 0) {
finalCategory.push(v);
}
});
var podCastList = [finalCategory];
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 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>Country of Resident:</strong> <br> " + v.country + "\n </li>\n <li>\n <strong>Origin Country:</strong> <br> " + v.resident + "\n </li>\n <li>\n <span><strong>Gender:</strong>" + v.gender + "</span>\n </li>\n <li>\n <strong>Stack:</strong> <br> " + v.stack + "\n </li>\n <li>\n <strong>Profession:</strong> <br> " + v.profession + "\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);
});
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();
}