-
Notifications
You must be signed in to change notification settings - Fork 33
/
Copy pathindex.ts
224 lines (207 loc) · 8.63 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
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
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
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/podcasts.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 = [];
let lanCat: any = [];
let langFinal: any = [];
let dayCat: any = [];
let dayFinal: any = [];
let freqCat: any = [];
let freqFinal: any = [];
response.map((obj: any) => {
let cat = obj.category.split(',').map((v: string) => v.trim().toLowerCase());
let lang = obj.languages.split(',').map((v: string) => v.trim().toLowerCase());
let days = obj.broadcast.split(',').map((v: string) => v.trim().toLowerCase());
let freq = obj.updates.split(',').map((v: string) => v.trim().toLowerCase());
newCategory.push(...cat);
lanCat.push(...lang)
freqCat.push(...freq)
dayCat.push(...days)
});
newCategory.map((v:string) => {
if (v.length !== 0 && finalCategory.indexOf(v) < 0){
finalCategory.push(v);
}
});
lanCat.map((v:string)=> {
if (v.length !== 0 && langFinal.indexOf(v) < 0) {
langFinal.push(v)
}
})
dayCat.map((v:string)=> {
if (v.length !== 0 && dayFinal.indexOf(v) < 0) {
dayFinal.push(v)
}
})
freqCat.map((v:string)=> {
if (v.length !== 0 && freqFinal.indexOf(v) < 0) {
freqFinal.push(v)
}
})
let podCastList: Array<any> = [finalCategory, langFinal, dayFinal, freqFinal];
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);
// pupolating laguages
let languages: Node = document.createElement('ul')
re[1].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 languages.appendChild(theChildren);
}).join(' ')
let lang: any = document.getElementById('language');
lang.appendChild(languages);
// pupolating release days
let releaseDays: Node = document.createElement('ul')
re[3].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 releaseDays.appendChild(theChildren);
}).join(' ')
let day: any = document.getElementById('broadcast');
day.appendChild(releaseDays);
// pupolating frequencies
let frquencies: HTMLUListElement = document.createElement('ul')
re[2].map((v: any, i: number) => {
let theChildren: HTMLLIElement = document.createElement('li');
theChildren.appendChild(document.createTextNode(v.toUpperCase()))
theChildren.setAttribute('class', 'subMenu');
theChildren.addEventListener('click', (event: MouseEvent) => {
let events: any = event.target;
console.log(re[2][i])
})
return frquencies.appendChild(theChildren);
}).join(' ')
let freq: any = document.getElementById('frequency');
freq.appendChild(frquencies);
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>Host Name:</strong> <br> ${v.host}
</li>
<li>
<strong>Description:</strong> <br> ${v.description}
</li>
<li>
<span><strong>Updates:</strong>${v.updates}</span>
<span><strong>Release:</strong>
${v.broadcast}</span>
</li>
<li>
<strong>Category:</strong> <br> ${v.category}
</li>
<li>
<strong>Language:</strong> <br> ${v.languages}
</li>
</ul>
</div>
</li>
</a>
`
return podcastEl.append(document.createRange().createContextualFragment(listBe));
}).join(' ');
let mainList: any = document.getElementById('mainList');
mainList.appendChild(podcastEl);
})
.catch((reason: any) => {
console.log(reason);
});
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');
// }
}