-
Notifications
You must be signed in to change notification settings - Fork 2
/
CJMvc.js
44 lines (36 loc) · 1.47 KB
/
CJMvc.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
// Place to store videos
var videos = [];
// string for the api key
var searchString = '';
// This sets the right url for our api call
var apiCall = 'https://www.googleapis.com/youtube/v3/search?part=snippet&q=' + searchString + '&key=AIzaSyAUcyyoRT0BzGf2oDK17-BWlw4HJjQ5lNw';
// The MVC!
var video = {
// A key that holds all of our click handlers.
init: function() {
$('#search').on('click', this.getVideos);
},
$el: $('<div class="videoSearched">').appendTo($('.content')),
// the event handler for our Search button.
getVideos: function() {
var searchInput = $('#searchInput').val(); //Gets value of input box
var searchArr = searchInput.split(" "); //Seperates individual words of input box into an array
for (var i = 0; i < searchArr.length - 1; i++) {
searchString += searchArr[i] + "+";
}
searchString += searchArr[searchArr.length - 1];
apiCall = 'https://www.googleapis.com/youtube/v3/search?part=snippet&q=' + searchString + '&key=AIzaSyAUcyyoRT0BzGf2oDK17-BWlw4HJjQ5lNw'; //creates the api call
//Submits the api call to the server
$.get(apiCall, function(item){
// Logs the objects we need
console.log(item);
for(var i = 0; i < item.items.length; i++){
console.log(item.items[i].id.videoId);
}
});
searchString = ''; //resets searchString
},
};
$(document).ready(function() {
video.init();
});