MediaWiki:Common.js: Difference between revisions

no edit summary
No edit summary
No edit summary
Line 117: Line 117:
for (i = 1; i < 100; i++) {
for (i = 1; i < 100; i++) {
if (document.getElementById('drawer-button-'+i)) {
if (document.getElementById('drawer-button-'+i)) {
document.getElementById('drawer-button-'+i).addEventListener('click', function(){ drawerExpand(i); } );
document.getElementById('drawer-button-'+i).addEventListener('click', function(){  
var content = document.getElementById("drawer-"+i); //outputs something like document.getElementById("drawer-1")
var button = document.getElementById("drawer-button-"+i); //outputs something like document.getElementById("drawer-button-1")
if (content.style.display == "block") {
    content.style.display = "none";
button.innerHTML = "Expand";
} else {
    content.style.display = "block";
    button.innerHTML = "Collapse";
}
} );
console.log("aggiunto eventListener per drawer-button-"+i);
console.log("aggiunto eventListener per drawer-button-"+i);
}
}
}
function drawerExpand(x) {
console.log("variabile x: "+x);
  var y = "drawer-"+x; //outputs something like "drawer-1"
  console.log("variabile y: "+y);
  var z = document.getElementById(y); //outputs something like document.getElementById("drawer-1")
  var a = "drawer-button-"+x; //outputs something like "drawer-button-1"
  console.log("variabile a: "+a);
  var b = document.getElementById(a); //outputs something like document.getElementById("drawer-button-1")
  if (z.style.display == "block") {
    z.style.display = "none";
b.innerHTML = "Expand";
  } else {
    z.style.display = "block";
    b.innerHTML = "Collapse";
  }
}
}