MediaWiki:Common.js: Difference between revisions

no edit summary
No edit summary
No edit summary
Line 115: Line 115:


/* ======================================= Template:Drawer ======================================= */
/* ======================================= Template:Drawer ======================================= */
var drawerButtonsArray = document.querySelectorAll(".drawer-button");
for (let i = 1; i < 100; i++) {
 
if (document.getElementById('drawer-button-'+i)) {
drawerButtonsArray.forEach(function(x){
document.getElementById('drawer-button-'+i).addEventListener('click', function(){  
var i = 1;
var content = document.getElementById("drawer-content-"+i); //outputs something like document.getElementById("drawer-content-1")
x.addEventListener("click", function(){
var button = document.getElementById("drawer-button-"+i); //outputs something like document.getElementById("drawer-button-1")
drawerShowHide(i);
if (content.style.display == "block") {
});
    content.style.display = "none";
i++;
button.innerHTML = "Expand";
});
} else {
 
    content.style.display = "block";
function drawerShowHide(x) {
    button.innerHTML = "Collapse";
var content = document.getElementById("drawer-"+x); //outputs something like document.getElementById("drawer-1")
}
var button = document.getElementById("drawer-button-"+x); //outputs something like document.getElementById("drawer-button-1")
} );
if (content.style.display == "block") {
console.log("aggiunto eventListener per drawer-button-"+i);
    content.style.display = "none";
button.innerHTML = "Expand";
} else {
    content.style.display = "block";
    button.innerHTML = "Collapse";
}
}
}
}