-
Notifications
You must be signed in to change notification settings - Fork 0
/
.js
68 lines (44 loc) · 1.46 KB
/
.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
let getInput = (a) => {
let input = document.getElementById("input").value;
console.log(input);
getName(input);
};
document.querySelector(".input-search").addEventListener('keyup', (e) => {
let input = document.querySelector('input').value;
// If the key ENTER is pressed....
if (e.which === 13) {
getName(input);
}
});
// Interacting with the Giphy API
let getName = (item) => {
let query = item.split(' ').join('+')
//2. Do the data stuff with API
let url = "https://api.giphy.com/v1/gifs/search?q="+ query + "&api_key=ZZvgfdi4cOKxEu6jIapo44P94iVPpAj6";
// AJAX Request
var GiphyAJAXCall = new XMLHttpRequest();
GiphyAJAXCall.open('GET', url);
GiphyAJAXCall.send();
GiphyAJAXCall.addEventListener("load", (e) => {
let data = e.target.response;
// console.log(data);
pushToDom(data);
});
};
//3. Show the GIF's
let pushToDom = (input) => {
let response = JSON.parse(input);
let container = document.querySelector(".js-container");
let result = document.querySelector(".results");
// clear(container);
// clear(result);
let imageUrls = response.data;
imageUrls.forEach((image) => {
let src = image.images.fixed_height.url;
result.innerHTML = src.length + "gifs found";
container.innerHTML += "<img src=\"" + src + "\" class=\'container-image\'>";
});
let clear = (item) => {
item.innerHTML = "";
};
};