Console: Refactor the configstats js

Don't toggle the full stats box with toggle-all
This commit is contained in:
zzz
2020-01-03 13:31:10 +00:00
parent e865f451ca
commit ecdccac37e
2 changed files with 70 additions and 56 deletions

View File

@ -0,0 +1,65 @@
function init()
{
checkAll = false;
var buttons = document.getElementsByClassName("script");
for(index = 0; index < buttons.length; index++)
{
var button = buttons[index];
// toggle-foo
var group = button.id.substring(7);
addClickHandler(button, group);
}
}
function addClickHandler(elem, category)
{
elem.addEventListener("click", function(){toggleAll(category); event.preventDefault(); return false;});
}
function toggleAll(category)
{
var inputs = document.getElementsByTagName("input");
for(index = 0; index < inputs.length; index++)
{
var classes = inputs[index].className.split(' ');
for (var idx = 0; idx < classes.length; idx++)
{
if(classes[idx] == category)
{
if(inputs[index].checked == 0)
{
inputs[index].checked = 1;
}
else if(inputs[index].checked == 1)
{
inputs[index].checked = 0;
}
}
}
if(category == '*')
{
if (inputs[index].id == 'enableFull') {
// don't toggle this one
continue;
}
if (checkAll == false)
{
inputs[index].checked = 1;
}
else if (checkAll == true)
{
inputs[index].checked = 0;
}
}
}
if(category == '*')
{
if (checkAll == false)
{
checkAll = true;
}
else if (checkAll == true)
{
checkAll = false;
}
}
}
window.addEventListener("load", init);