Created
March 3, 2022 22:19
-
-
Save sneakers-the-rat/4a127ecc6af67a80a0a6779d5e8de4c0 to your computer and use it in GitHub Desktop.
Override Academic Theme Filter
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function multiFilter(e){ | |
// get isotope instance and filter buttons | |
let iso = Isotope.data('.projects-container'); | |
let filterButtons = document.querySelectorAll('.project-filters a'); | |
// iterate through buttons... | |
filterButtons.forEach((button) => { | |
// remove existing event listeners | |
let buttonClone = button.cloneNode(true); | |
button.parentNode.replaceChild(buttonClone, button); | |
// add new event listener to do the filtering | |
buttonClone.addEventListener('click', (e) => { | |
// prevent the page from jumping back up to the top on click | |
e.preventDefault(); | |
// toggle active state of this button | |
e.target.classList.toggle('active'); | |
// get all active buttons | |
let activeButtons = document.querySelectorAll('.project-filters a.active'); | |
// if a button besides 'all' is active, make sure 'all' isnt | |
if (activeButtons.length > 1){ | |
activeButtons.forEach((b) => { | |
if (b.getAttribute('data-filter') === '*'){ | |
b.classList.remove('active') | |
} | |
}) | |
// refresh activeButton list | |
activeButtons = document.querySelectorAll('.project-filters a.active'); | |
} | |
// get data filters of active buttons | |
let filters = Array.from(activeButtons).map(a => a.getAttribute('data-filter')); | |
// join filters to single string | |
let filterstring = filters.join(''); | |
console.log('filtering with filter string', filterstring) | |
// filter isotope elements | |
iso.arrange({filter:filterstring}) | |
}) | |
}) | |
} | |
window.addEventListener('load', multiFilter) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment