-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfunctions.js
88 lines (75 loc) · 2.5 KB
/
functions.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
const modalContainer = document.getElementsByClassName('modal-container')[0];
const openModalBtn = document.getElementById('open-modal-button');
const closeModalBtn = document.getElementById('closeBtn');
const image = document.querySelector('img');
const apiKey = 'yBv3YNIipZW808qJEvsoaHf7DmjtWVdW';
let randomGif;
const oneLanguage = document.getElementById('one');
const twoFiveLanguages = document.getElementById('two-five');
const sixTenLanguages = document.getElementById('six-ten');
const moreThanTenLanguages = document.getElementById('more-than-ten');
const spanish = document.getElementById('ES');
const portuguese = document.getElementById('PT');
const french = document.getElementById('FR');
const german = document.getElementById('DE');
const chinese = document.getElementById('ZH');
const artur = document.getElementById('Artur');
const japanese = document.getElementById('JA');
const other = document.getElementById('other');
openModalBtn.addEventListener('click', openModal)
function openModal(e) {
if (oneLanguage.checked) {
if (artur.checked) {
randomGif = 'relaxed';
} else if (japanese.checked || other.checked) {
randomGif = 'screwed';
} else {
randomGif = 'giggles';
}
} else if (twoFiveLanguages.checked) {
if (artur.checked) {
randomGif = 'cold-shoulder';
} else if (japanese.checked || other.checked) {
randomGif = 'bleed';
} else {
randomGif = 'excited';
}
} else if (sixTenLanguages.checked) {
if (artur.checked) {
randomGif = 'coffee';
} else if (japanese.checked || other.checked) {
randomGif = 'torment';
} else {
randomGif = 'worried';
}
} else if (moreThanTenLanguages.checked) {
if (artur.checked) {
randomGif = 'cowboy';
} else if (japanese.checked || other.checked) {
randomGif = 'crying';
} else {
randomGif = 'terrified';
}
}
const url = `http://api.giphy.com/v1/gifs/random?api_key=${apiKey}&tag=${randomGif}&limit=1`
const GifSelected = fetch(url)
.then(res => res.json())
.then(finalGif => {
image.src = finalGif.data.image_url;
});
e.preventDefault();
modalContainer.style.display = 'block';
GifSelected
}
closeModalBtn.addEventListener('click', closeModal)
function closeModal() {
modalContainer.style.display = 'none';
console.log(123);
}
window.addEventListener('click', clickOutsideModal)
function clickOutsideModal(e) {
if (e.target === modalContainer) {
modalContainer.style.display = 'none';
console.log(123);
}
}