-
Notifications
You must be signed in to change notification settings - Fork 0
/
BangXepHang.js
110 lines (77 loc) · 3.11 KB
/
BangXepHang.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
getTrending();
function getTrending(t) {
let xhr = new XMLHttpRequest();
let url = "https://www.googleapis.com/youtube/v3/videos?part=snippet&chart=mostPopular&maxResults=40®ionCode=vn&key=AIzaSyCepC9SX6DixNi4cvc81jr266aaFxQfS2w"
xhr.open("GET", url);
xhr.onreadystatechange = function() {
if (this.readyState === 4 && this.status === 200) {
showTrend(this.responseText);
}
}
xhr.send();
}
function showTrend(json) {
let trend = JSON.parse(json);
let item = trend.items;
let bxh = document.getElementById("BangXepHang");
let s = ''
for (let i = 0; i < item.length; i++) {
let bai = item[i];
let snippet = bai.snippet;
let title = snippet.title;
let thumbnails = snippet.thumbnails;
let defthumb = thumbnails.high;
let url = defthumb.url;
s += `<!-- video thumbnail -->
<div class="videothumbnail">
<!-- add tooltip -->
<span data-toggle="tooltip" data-placement="top" title="Click to listen on youtube">
<!-- an vao toggle ra modal -->
<!-- them id vao the img -->
<img class="thumbnail vungChon" data-toggle="modal" data-target="#myModal" src="${url}" alt="${title}" data-id="${bai.id}">
</span>
<!-- thay description cua thumbnail -->
<span class="desc vungChon" target="_top" data-toggle="modal" data-target="#myModal" data-id="${bai.id}" title="${title}">${title}</span>
</div>`
}
bxh.innerHTML = s;
$('[data-toggle="tooltip"]').tooltip();
}
//Play youtube in modal style
$(window).on("load", function() {
let $videoSrc;
$(document).on('click', '.vungChon', (function() {
$videoSrc = $(this).data("id");
}));
// when the modal is opened autoplay it
$('#myModal').on('shown.bs.modal', function() {
// set the video src to autoplay and not to show related video. Youtube related video is like a box of chocolates... you never know what you're gonna get
$("#video").attr('src', "https://www.youtube.com/embed/" + $videoSrc + "?autoplay=1&modestbranding=1&showinfo=0");
})
// stop playing the youtube video when I close the modal
$('#myModal').on('hide.bs.modal', function() {
// a poor man's stop video
$("#video").attr('src', $videoSrc);
})
});
// function cua button to top
//Get the button:
mybutton = document.getElementById("myBtn");
// When the user scrolls down 20px from the top of the document, show the button
window.onscroll = function() { scrollFunction() };
function scrollFunction() {
if (document.body.scrollTop > 20 || document.documentElement.scrollTop > 20) {
mybutton.style.display = "block";
} else {
mybutton.style.display = "none";
}
}
// When the user clicks on the button, scroll to the top of the document
function topFunction() {
document.body.scrollTop = 0; // For Safari
document.documentElement.scrollTop = 0; // For Chrome, Firefox, IE and Opera
}
//function back
function goBack() {
window.history.back();
}