diff --git a/assets/js/burger.ts b/assets/js/burger.ts index 58c416bb..177fde22 100644 --- a/assets/js/burger.ts +++ b/assets/js/burger.ts @@ -53,20 +53,27 @@ export function setupBurgerMenu() { copyUserLinksTo(burger); - toggle.addEventListener('click', event => { - event.stopPropagation(); - event.preventDefault(); - - if (content.classList.contains('open')) { - close(burger, content, body, root); - } else { - open(burger, content, body, root); + document.addEventListener('click', event => { + if (!(event.target instanceof Node)) { + return; } - }); - content.addEventListener('click', () => { - if (content.classList.contains('open')) { - close(burger, content, body, root); + if (toggle.contains(event.target)) { + event.preventDefault(); + + if (content.classList.contains('open')) { + close(burger, content, body, root); + } else { + open(burger, content, body, root); + } + + return; + } + + if (content.contains(event.target)) { + if (content.classList.contains('open')) { + close(burger, content, body, root); + } } }); } diff --git a/assets/js/interactions.js b/assets/js/interactions.js index c9e05ef1..d40a90ae 100644 --- a/assets/js/interactions.js +++ b/assets/js/interactions.js @@ -19,7 +19,13 @@ const endpoints = { const spoilerDownvoteMsg = 'Neigh! - Remove spoilered tags from your filters to downvote from thumbnails'; -/* Quick helper function to less verbosely iterate a QSA */ +/** + * Quick helper function to less verbosely iterate a QSA + * + * @param {string} id + * @param {string} selector + * @param {(node: HTMLElement) => void} cb + */ function onImage(id, selector, cb) { [].forEach.call(document.querySelectorAll(`${selector}[data-image-id="${id}"]`), cb); } @@ -145,14 +151,6 @@ function loadInteractions() { icon.setAttribute('title', spoilerDownvoteMsg); a.classList.add('disabled'); - a.addEventListener( - 'click', - event => { - event.stopPropagation(); - event.preventDefault(); - }, - true, - ); }); }); } @@ -163,6 +161,10 @@ const targets = { interact('vote', imageId, 'DELETE').then(() => resetVoted(imageId)); }, '.interaction--downvote.active'(imageId) { + if (window.booru.imagesWithDownvotingDisabled.includes(imageId)) { + return; + } + interact('vote', imageId, 'DELETE').then(() => resetVoted(imageId)); }, '.interaction--fave.active'(imageId) { @@ -180,6 +182,10 @@ const targets = { }); }, '.interaction--downvote:not(.active)'(imageId) { + if (window.booru.imagesWithDownvotingDisabled.includes(imageId)) { + return; + } + interact('vote', imageId, 'POST', { up: false }).then(() => { resetVoted(imageId); showDownvoted(imageId);