-
Notifications
You must be signed in to change notification settings - Fork 2
/
index.ts
149 lines (135 loc) · 5.43 KB
/
index.ts
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
// var gh = new GitHub({
// token: 'b4eff74db53c9f3279ab41df31aafc90a8fdc9cc'
// });
// const podcast = gh.getRepo('inidaname', 'podcast');
// podcast.getContributors()
// console.log(podcast.getCollaborators())
let broadcast: Array<string>;
let frequency: Array<string>;
const myRequest = new Request('./data/people.json');
let categories: Promise<Array<any>> = new Promise((resolve: any, reject:any) => {
fetch(myRequest)
.then(function (response:Response) {
return response.json();
})
.then(function (response: any[]) {
let newCategory: any = [];
let finalCategory: any = [];
response.map((obj: any) => {
let cat = obj.stack.split(',').map((v: string) => v.trim().toLowerCase());
newCategory.push(...cat);
});
newCategory.map((v:string) => {
if (v.length !== 0 && finalCategory.indexOf(v) < 0){
finalCategory.push(v);
}
});
let podCastList: Array<any> = [finalCategory];
if(podCastList){
return resolve({podCastList, response});
} else {
return reject('Empty Pod cast')
}
});
});
categories.then((res: any) => {
let re = res.podCastList;
//pupolating categories
let category: Node = document.createElement('ul')
re[0].map((v: any, i: number) => {
let theChildren = document.createElement('li')
theChildren.appendChild(document.createTextNode(v.toUpperCase()));
theChildren.setAttribute('class', 'subMenu');
theChildren.addEventListener('click', (event) => {
console.log(event)
})
return category.appendChild(theChildren);
}).join(' ')
let cat: any = document.getElementById('category');
cat.appendChild(category);
const contents: Array<object> = res.response;
let podcastEl: HTMLUListElement = document.createElement('ul');
podcastEl.classList.add('podcast')
contents.map((v: any, i: number) => {
let mainURL = (v.url !== undefined && v.url.substring(0, 4) !== 'http')? `http://${v.url}` : v.url;
let listBe = `
<a href="${mainURL}" target="_blank">
<li class="podList">
<div>
<h3> ${v.name} </h3>
<img src="${v.logo}" alt="${v.name}">
<ul>
<li>
<strong>Country of Resident:</strong> <br> ${v.country}
</li>
<li>
<strong>Origin Country:</strong> <br> ${v.resident}
</li>
<li>
<span><strong>Gender:</strong>${v.gender}</span>
</li>
<li>
<strong>Stack:</strong> <br> ${v.stack}
</li>
<li>
<strong>Profession:</strong> <br> ${v.profession}
</li>
</ul>
</div>
</li>
</a>
`
return podcastEl.append(document.createRange().createContextualFragment(listBe));
}).join(' ');
let mainList: any = document.getElementById('mainList');
mainList.appendChild(podcastEl);
})
const listMenu: NodeListOf<Element> = document.querySelectorAll('#sideContent li');
let nullMe: boolean;
let listTrig: boolean;
listMenu.forEach((el: Element) => {
el.addEventListener('click', (ev: any) => {
listMenu.forEach((e: any) => {
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';
}
}
})
})
})
// open nav effect
function openNav(): void {
console.log();
// if (!document.body.classList.contains('menuMoved')) {
// document.body.classList.add('menuMoved');
// let sideBar: any = document.getElementById('sideBar');
// sideBar.style.width = "300px";
// let main: any = document.getElementById('main');
// main.style.marginLeft = "300px";
// main.style.width = "calc(100% - 300px)"
// } else {
// let sideBar: any = document.getElementById('sideBar');
// sideBar.style.width = "0px";
// let main: any = document.getElementById('main');
// main.style.marginLeft = "0px";
// main.style.width = "100%";
// document.body.classList.remove('menuMoved');
// }
}