let commentFormID; function commentForm(form) { commentFormID = form; }; const gifSearchBar = document.getElementById('gifSearch') async function getGif(searchTerm) { if (searchTerm !== undefined) { gifSearchBar.value = searchTerm; } else { gifSearchBar.value = null; } const loadGIFs = document.getElementById('gifs-load-more'); const noGIFs = document.getElementById('no-gifs-found'); const container = document.getElementById('GIFs'); const backBtn = document.getElementById('gifs-back-btn'); const cancelBtn = document.getElementById('gifs-cancel-btn'); container.innerHTML = ''; if (searchTerm == undefined) { container.innerHTML = '
Agree
Laugh
Confused
Sad
Happy
Awesome
Yes
No
Love
Please
Scared
Angry
Awkward
Cringe
OMG
Why
Gross
Meh
' backBtn.innerHTML = null; cancelBtn.innerHTML = null; noGIFs.innerHTML = null; loadGIFs.innerHTML = null; } else { backBtn.innerHTML = ''; cancelBtn.innerHTML = ''; let response = await fetch("/giphy?searchTerm=" + searchTerm + "&limit=48"); let data = await response.json() const max = data.length - 1 data = data.data const gifURL = []; if (max <= 0) { noGIFs.innerHTML = '

Aw shucks. No GIFs found...

'; container.innerHTML = null; loadGIFs.innerHTML = null; } else { for (let i = 0; i < 48; i++) { gifURL[i] = "https://media.giphy.com/media/" + data[i].id + "/giphy.webp"; if (data[i].username==''){ const insert = '
' container.insertAdjacentHTML('beforeend', insert); } else { const insert = '
' container.insertAdjacentHTML('beforeend', insert); } noGIFs.innerHTML = null; loadGIFs.innerHTML = '

Thou've reached the end of the list!

'; } } } } function insertGIF(url,form) { const commentBox = document.getElementById(form); const old = commentBox.value; if (old) commentBox.value = `${old}\n${url}`; else commentBox.value = url if (typeof checkForRequired === "function") checkForRequired(); } document.getElementById('gifModal').addEventListener('shown.bs.modal', function () { gifSearchBar.focus(); setTimeout(() => { gifSearchBar.focus(); }, 200); setTimeout(() => { gifSearchBar.focus(); }, 1000); });