mirror of
https://github.com/bitburner-official/bitburner-src.git
synced 2025-03-11 04:42:34 +01:00
31 lines
1.0 KiB
JavaScript
31 lines
1.0 KiB
JavaScript
//Creates both the header and panel element of an accordion and sets the click handler
|
|
function createAccordionElement(params) {
|
|
var li = document.createElement("li"),
|
|
hdr = document.createElement("button"),
|
|
panel = document.createElement("div");
|
|
hdr.classList.add("accordion-header");
|
|
panel.classList.add("accordion-panel");
|
|
|
|
if (params.id) {
|
|
hdr.id = params.id + "-hdr";
|
|
panel.id = params.id + "-panel";
|
|
}
|
|
if (params.hdrText) {hdr.innerHTML = params.hdrText;}
|
|
if (params.panelText) {panel.innerHTML = params.panelText;}
|
|
li.appendChild(hdr);
|
|
li.appendChild(panel);
|
|
//Click handler
|
|
hdr.onclick = function() {
|
|
this.classList.toggle("active");
|
|
var tmpPanel = this.nextElementSibling;
|
|
if (tmpPanel.style.display === "block") {
|
|
tmpPanel.style.display = "none";
|
|
} else {
|
|
tmpPanel.style.display = "block";
|
|
}
|
|
}
|
|
return [li, hdr, panel];
|
|
}
|
|
|
|
export {createAccordionElement};
|