|
|
|
@ -160,55 +160,49 @@ function getGif(searchTerm) {
|
|
|
|
|
|
|
|
|
|
cancelBtn.innerHTML = '<button class="btn btn-link pl-3 pr-0" id="gifs-cancel-btn" onclick="getGif();"><i class="fas fa-times text-muted"></i></button>';
|
|
|
|
|
|
|
|
|
|
$.ajax({
|
|
|
|
|
url: "/giphy?searchTerm=" + searchTerm + "&limit=48",
|
|
|
|
|
type: "GET",
|
|
|
|
|
success: function(response) {
|
|
|
|
|
var max = response.data.length - 1 //length of response, minus 1 (cuz array starts at index 0)
|
|
|
|
|
var randomNumber = Math.round(Math.random() * 6) //random number between 0 and max -1
|
|
|
|
|
// GIF array
|
|
|
|
|
var gifURL = [];
|
|
|
|
|
|
|
|
|
|
// loop for fetching mutliple GIFs and creating the card divs
|
|
|
|
|
if (max < 48 && max > 0) {
|
|
|
|
|
for (var i = 0; i <= max; i++) {
|
|
|
|
|
gifURL[i] = "https://media.giphy.com/media/" + response.data[i].id + "/200w_d.webp";
|
|
|
|
|
if (response.data[i].username==''){
|
|
|
|
|
container.innerHTML += ('<div class="card bg-white" style="overflow: hidden" data-dismiss="modal" aria-label="Close" onclick="insertGIF(\'' + 'https://media.giphy.com/media/' + response.data[i].id + '/100w.webp' + '\',\'' + commentFormID + '\')"><div class="gif-cat-overlay"></div><img loading="lazy" class="img-fluid" src="' + gifURL[i] + '"></div>');
|
|
|
|
|
fetch("/giphy?searchTerm=" + searchTerm + "&limit=48")
|
|
|
|
|
.then(response => {
|
|
|
|
|
var max = response.data.length - 1 //length of response, minus 1 (cuz array starts at index 0)
|
|
|
|
|
var randomNumber = Math.round(Math.random() * 6) //random number between 0 and max -1
|
|
|
|
|
// GIF array
|
|
|
|
|
var gifURL = [];
|
|
|
|
|
|
|
|
|
|
// loop for fetching mutliple GIFs and creating the card divs
|
|
|
|
|
if (max < 48 && max > 0) {
|
|
|
|
|
for (var i = 0; i <= max; i++) {
|
|
|
|
|
gifURL[i] = "https://media.giphy.com/media/" + response.data[i].id + "/200w_d.webp";
|
|
|
|
|
if (response.data[i].username==''){
|
|
|
|
|
container.innerHTML += ('<div class="card bg-white" style="overflow: hidden" data-dismiss="modal" aria-label="Close" onclick="insertGIF(\'' + 'https://media.giphy.com/media/' + response.data[i].id + '/100w.webp' + '\',\'' + commentFormID + '\')"><div class="gif-cat-overlay"></div><img loading="lazy" class="img-fluid" src="' + gifURL[i] + '"></div>');
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
container.innerHTML += ('<div class="card bg-white" style="overflow: hidden" data-dismiss="modal" aria-label="Close" title="by '+response.data[i].username+' on GIPHY" onclick="insertGIF(\'' + 'https://media.giphy.com/media/' + response.data[i].id + '/100w.webp' + '\',\'' + commentFormID + '\')"><div class="gif-cat-overlay"></div><img loading="lazy" class="img-fluid" src="' + gifURL[i] + '"></div>');
|
|
|
|
|
}
|
|
|
|
|
noGIFs.innerHTML = null;
|
|
|
|
|
loadGIFs.innerHTML = '<div class="text-center py-3"><div class="mb-3"><i class="fad fa-grin-beam-sweat text-gray-500" style="font-size: 3.5rem;"></i></div><p class="font-weight-bold text-gray-500 mb-0">Thou've reached the end of the list!</p></div>';
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else if (max <= 0) {
|
|
|
|
|
noGIFs.innerHTML = '<div class="text-center py-3 mt-3"><div class="mb-3"><i class="fad fa-frown text-gray-500" style="font-size: 3.5rem;"></i></div><p class="font-weight-bold text-gray-500 mb-0">Aw shucks. No GIFs found...</p></div>';
|
|
|
|
|
container.innerHTML = null;
|
|
|
|
|
loadGIFs.innerHTML = null;
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
container.innerHTML += ('<div class="card bg-white" style="overflow: hidden" data-dismiss="modal" aria-label="Close" title="by '+response.data[i].username+' on GIPHY" onclick="insertGIF(\'' + 'https://media.giphy.com/media/' + response.data[i].id + '/100w.webp' + '\',\'' + commentFormID + '\')"><div class="gif-cat-overlay"></div><img loading="lazy" class="img-fluid" src="' + gifURL[i] + '"></div>');
|
|
|
|
|
for (var i = 0; i <= 48; i++) {
|
|
|
|
|
gifURL[i] = "https://media.giphy.com/media/" + response.data[i].id + "/200w_d.webp";
|
|
|
|
|
if (response.data[i].username==''){
|
|
|
|
|
container.innerHTML += ('<div class="card bg-white" style="overflow: hidden" data-dismiss="modal" aria-label="Close" onclick="insertGIF(\'' + 'https://media.giphy.com/media/' + response.data[i].id + '/100w.webp' + '\',\'' + commentFormID + '\')"><div class="gif-cat-overlay"></div><img loading="lazy" class="img-fluid" src="' + gifURL[i] + '"></div>');
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
container.innerHTML += ('<div class="card bg-white" style="overflow: hidden" data-dismiss="modal" aria-label="Close" title="by '+response.data[i].username+' on GIPHY" onclick="insertGIF(\'' + 'https://media.giphy.com/media/' + response.data[i].id + '/100w.webp' + '\',\'' + commentFormID + '\')"><div class="gif-cat-overlay"></div><img loading="lazy" class="img-fluid" src="' + gifURL[i] + '"></div>');
|
|
|
|
|
}
|
|
|
|
|
noGIFs.innerHTML = null;
|
|
|
|
|
loadGIFs.innerHTML = '<div class="text-center py-3"><div class="mb-3"><i class="fad fa-grin-beam-sweat text-gray-500" style="font-size: 3.5rem;"></i></div><p class="font-weight-bold text-gray-500 mb-0">Thou've reached the end of the list!</p></div>';
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
noGIFs.innerHTML = null;
|
|
|
|
|
loadGIFs.innerHTML = '<div class="text-center py-3"><div class="mb-3"><i class="fad fa-grin-beam-sweat text-gray-500" style="font-size: 3.5rem;"></i></div><p class="font-weight-bold text-gray-500 mb-0">Thou've reached the end of the list!</p></div>';
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else if (max <= 0) {
|
|
|
|
|
noGIFs.innerHTML = '<div class="text-center py-3 mt-3"><div class="mb-3"><i class="fad fa-frown text-gray-500" style="font-size: 3.5rem;"></i></div><p class="font-weight-bold text-gray-500 mb-0">Aw shucks. No GIFs found...</p></div>';
|
|
|
|
|
container.innerHTML = null;
|
|
|
|
|
loadGIFs.innerHTML = null;
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
for (var i = 0; i <= 48; i++) {
|
|
|
|
|
gifURL[i] = "https://media.giphy.com/media/" + response.data[i].id + "/200w_d.webp";
|
|
|
|
|
if (response.data[i].username==''){
|
|
|
|
|
container.innerHTML += ('<div class="card bg-white" style="overflow: hidden" data-dismiss="modal" aria-label="Close" onclick="insertGIF(\'' + 'https://media.giphy.com/media/' + response.data[i].id + '/100w.webp' + '\',\'' + commentFormID + '\')"><div class="gif-cat-overlay"></div><img loading="lazy" class="img-fluid" src="' + gifURL[i] + '"></div>');
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
container.innerHTML += ('<div class="card bg-white" style="overflow: hidden" data-dismiss="modal" aria-label="Close" title="by '+response.data[i].username+' on GIPHY" onclick="insertGIF(\'' + 'https://media.giphy.com/media/' + response.data[i].id + '/100w.webp' + '\',\'' + commentFormID + '\')"><div class="gif-cat-overlay"></div><img loading="lazy" class="img-fluid" src="' + gifURL[i] + '"></div>');
|
|
|
|
|
}
|
|
|
|
|
noGIFs.innerHTML = null;
|
|
|
|
|
loadGIFs.innerHTML = '<div class="text-center py-3"><div class="mb-3"><i class="fad fa-grin-beam-sweat text-gray-500" style="font-size: 3.5rem;"></i></div><p class="font-weight-bold text-gray-500 mb-0">Thou've reached the end of the list!</p></div>';
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
error: function(e) {
|
|
|
|
|
alert(e);
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
};
|
|
|
|
|
})
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function insertGIF(url,form) {
|
|
|
|
|
|