Skip to content

Instantly share code, notes, and snippets.

@SniperSister
Last active December 25, 2018 11:07
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save SniperSister/72647eb3782d14cb10debbf585bf6b19 to your computer and use it in GitHub Desktop.
Save SniperSister/72647eb3782d14cb10debbf585bf6b19 to your computer and use it in GitHub Desktop.
PhocaFilterScript Vanilla JS
document.addEventListener("DOMContentLoaded", () => {
function phFilterQuote(str) {
return str.replace(/[-\[\]{}()*+!<=:?.\/\\^$|#\s,]/g, "\\$&");
};
document.getElementById("phFilterOptions").addEventListener("input", (event) => {
let tV = event.currentTarget.value;
if (tV.length > 0) {
document.querySelectorAll('#configTabs li, #configContent div.tab-pane').forEach((elem) => {elem.classList.add('active')});
document.querySelectorAll('.field-spacer, .tab-description').forEach((elem) => {elem.style.display = "none";});
document.querySelectorAll('.control-group .control-label label').forEach((elem) => {
let tPP = elem.parentElement.parentElement;
let item = elem.getAttribute("data-original-title");
tPP.style.display = "none";
if (item && typeof item == "string") {
let re = new RegExp(phFilterQuote(tV), "i");
let res = item.match(re);
if (res) {
tPP.style.display = "block";
}
}
});
return;
}
document.querySelectorAll('#configTabs li.active, #configContent div.tab-pane.active').forEach((elem) => {elem.classList.remove('active')});
if(document.querySelector('#configTabs li')) {
document.querySelector('#configTabs li').classList.add('active');
}
if(document.querySelector('#configContent div.tab-pane')) {
document.querySelector('#configTabs div.tab-pane').classList.add('active');
}
document.querySelectorAll('.field-spacer, .tab-description, .control-group').forEach((elem) => {elem.style.display = "block";});
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment