Created
July 2, 2019 05:29
-
-
Save shoito/e7823e3d213013a77f04c1d5048d7ec1 to your computer and use it in GitHub Desktop.
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
(() => { | |
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