Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save shoito/e7823e3d213013a77f04c1d5048d7ec1 to your computer and use it in GitHub Desktop.
Save shoito/e7823e3d213013a77f04c1d5048d7ec1 to your computer and use it in GitHub Desktop.
(() => {
const appendFilter = (taxonomyId, listId) => {
const input = document.createElement("input")
input.setAttribute("type", "text")
input.setAttribute("placeholder", "filter")
input.addEventListener("input", (event) => filterItem(listId, event.target.value))
const taxonomyDiv = document.getElementById(taxonomyId)
taxonomyDiv.insertBefore(input, taxonomyDiv.firstChild)
}
const filterItem = (listId, keyword) => {
document.querySelectorAll("#" + listId + " li").forEach((item, i, items) => {
if (!item.innerText.toLowerCase().includes(keyword.toLowerCase())) {
item.style = "display:none"
} else {
item.style = "display:list-item"
}
})
}
appendFilter("taxonomy-category", "categorychecklist")
appendFilter("taxonomy-referencecat", "referencecatchecklist")
})()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment