Woo Category Widget Toggles
{
let parentItems = document.querySelectorAll(".product-categories li.cat-parent");
// console.dir(parentItems);
let buttonToggle = () => {
let buttons = document.querySelectorAll(".wooToggle");
buttons.forEach((button) => {
button.addEventListener("click", function (e) {
this.parentElement.classList.toggle("toggled");
});
});
return buttons;
};
let insertButtons = (elements) => {
elements.forEach((item) => {
let newElement = document.createElement("button");
newElement.className = "wooToggle";
let newContent = document.createTextNode("");
newElement.appendChild(newContent);
item.insertBefore(newElement, item.firstChild);
});
return elements;
};
if (parentItems.length > 0) {
Promise
.resolve(parentItems)
.then(insertButtons)
.then(buttonToggle)
.catch();
}
}
.wooToggle,
.wooToggle:before,
.wooToggle:after {
height: 15px;
width: 15px;
}
.wooToggle {
font-size: 11px;
color: white;
position: relative;
background: transparent;
border: none;
z-index: 2;
&:hover {
cursor: pointer;
}
&:after {
content: " ";
display: block;
position: absolute;
border-radius: 100%;
background: red;
background: linear-gradient(to bottom, red 0%, #250f25 100%) !important;
box-shadow: 0 0 4px rgba(0, 0, 0, .50) !important;
z-index: 1;
}
&:before, &:after {
position: absolute;
top: 0;
left: 0;
right: 0;
bottom: 0;
}
&:before {
font-size: 15px;
z-index: 3;
}
}
.wooToggle {
&:before, &:after {
font-family: "FontAwesome";
font-size: 10px;
}
&:before {
margin-top: 2px;
margin-left: .5px;
content: "\f067";
}
}
.current-cat-parent .wooToggle,
.toggled .wooToggle {
&:before {
content: "\f068";
}
}
.woocommerce .product-categories {
.children {
display: none;
}
.toggled > .children,
.current-cat-parent > .children,
.current-cat.children {
display: block;
}
}
.woocommerce .product-categories .current-cat-parent.toggled {
.wooToggle {
&:before {
content: "\f067";
}
}
> .children {
display: none;
}
}
.current-cat {
font-weight: 600;
}
// For sidebar
.product-categories {
li {
padding-left: .5em;
position: relative;
margin: .5em 0 .25em;
}
.wooToggle {
position: absolute;
left: -1em;
top: .5em;
}
}
.product-tax-meta {
margin-bottom: 1em;
p {
margin: .1em 0 .5em;
}
}