-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
35 lines (30 loc) · 916 Bytes
/
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
const YouTube_URL = 'https://www.googleapis.com/youtube/v3/search';
function displaySearchData(data, status){
data.items.forEach(item => {
let videoURL = `http://www.youtube.com/watch?v=${item.id.videoId}`;
let thumbnailURL = item.snippet.thumbnails.medium.url;
$('.results').append(`<a href="${videoURL}"><img src="${thumbnailURL}" class="col-1 col-m-3"></a>`);
});
}
function getAPIData(searchTerm){
let query = {
q: searchTerm,
part: 'snippet',
key: 'AIzaSyBhE83ZVWzf_-bL1_DS38AUyV4m1Ib5ltw',
type: 'video',
maxResults: 6
};
$.getJSON(YouTube_URL, query, displaySearchData);
}
function submitFormListener(){
$('.js-search-bar').submit(function(){
event.preventDefault();
$('.results').contents().hide();
let searchTerm = $(this).find('.js-query').val();
getAPIData(searchTerm);
});
}
function pageStart(){
$(submitFormListener);
}
$(pageStart);