-
Notifications
You must be signed in to change notification settings - Fork 0
/
HomeApplication.js
130 lines (120 loc) · 3.72 KB
/
HomeApplication.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
class HomeApplication extends Application {
constructor(el){
super(el);
this.id = getParameterByName("id");
this.channelId = getParameterByName("channelId");
}
onLoad(){
super.onLoad();
this.popularVideosContainer = this.element.querySelector(".popular-container");
this.popularVideosContainer.innerHTML = "";
this.autosAndVehiclesContainer = this.element.querySelector(".autos-vehicles");
this.autosAndVehiclesContainer.innerHTML = "";
this.gamingContainer = this.element.querySelector(".gaming");
this.gamingContainer.innerHTML = "";
this.channelContainer = this.element.querySelector(".channel-container");
this.channelContainer.innerHTML = "";
}
//After Data API is loaded, run these functions
onApiLoaded(e){
super.onApiLoaded();
this.onGetPopularVideos();
this.onGetAutosandVehiclesVideos();
this.onGetGamingVideos();
this.onSearchChannelsList();
}
// Videos list API call to get the most trending latest videos and create them followed by this.onCreatePopularVideos();
onGetPopularVideos(){
const request = gapi.client.youtube.videos.list({
chart: "mostPopular",
regionCode: "US",
part: "snippet,contentDetails,statistics",
videoCategoryId: "",
maxResults: 12
});
request.execute(response => {
const results = response.result;
console.log(results);
this.onCreatePopularVideos(results.items);
});
}
onCreatePopularVideos(items){
for(let item of items){
let video = new VideoItem(item);
video.setViewCount(item);
video.onLinkRedirect(item);
video.id = item.id;
this.popularVideosContainer.appendChild(video.element);
}
}
// Videos list API call to get the most trending latest videos related to Autos and Vehicles and create them - this.onCreateAutosandVehiclesVideos();
onGetAutosandVehiclesVideos(){
const request = gapi.client.youtube.videos.list({
chart: "mostPopular",
regionCode: "US",
part: "snippet,contentDetails,statistics",
videoCategoryId: "2",
maxResults: 12
});
request.execute(response => {
const results = response.result;
console.log(results);
this.onCreateAutosandVehiclesVideos(results.items);
});
}
onCreateAutosandVehiclesVideos(items){
for(let item of items){
let video = new VideoItem(item);
video.setViewCount(item);
video.onLinkRedirect(item);
video.id = item.id;
this.autosAndVehiclesContainer.appendChild(video.element);
}
}
// Videos list API call to get the most trending latest videos related to Gaming and create them - this.onCreateGamingVideos();
onGetGamingVideos(){
const request = gapi.client.youtube.videos.list({
chart: "mostPopular",
regionCode: "US",
part: "snippet,contentDetails,statistics",
videoCategoryId: "20",
maxResults: 12
});
request.execute(response => {
const results = response.result;
console.log(results);
this.onCreateGamingVideos(results.items);
});
}
onCreateGamingVideos(items){
for(let item of items){
let video = new VideoItem(item);
video.setViewCount(item);
video.onLinkRedirect(item);
video.id = item.id;
this.gamingContainer.appendChild(video.element);
}
}
// Search list API call to get channels upon rating and inject them into the specified HTML element container - this.onCreateChannels();
onSearchChannelsList(){
const request = gapi.client.youtube.search.list({
part: "snippet",
type: "channel",
maxResults: 48,
regionCode: "US",
order: "rating"
});
request.execute(response => {
const results = response.result;
console.log(results);
this.onCreateChannels(results.items);
});
}
onCreateChannels(items){
for(let item of items){
let channel = new ChannelItem(item);
channel.id = item.id.channelId;
this.channelContainer.appendChild(channel.element);
}
}
}