vivo/webapp/src/main/webapp/themes/iph/js/collapsible_elements.js

54 lines
1.6 KiB
JavaScript

document.addEventListener('DOMContentLoaded', addCollapsibleOnClick(), false);
document.addEventListener('DOMContentLoaded', expandAllCollapsedElements(), false);
function addCollapsibleOnClick() {
var coll = document.getElementsByClassName("collapsible");
var i;
for (i = 0; i < coll.length; i++) {
coll[i].addEventListener("click", function() {
this.classList.toggle("active");
var content = this.nextElementSibling;
if (content.style.display === "block") {
content.style.display = "none";
} else {
content.style.display = "block";
}
});
}
}
function expandAllCollapsedElements() {
if (localStorage.getItem('switchExpand') === true || localStorage.getItem('switchExpand') === 'true') {
var expandSwitchCB = document.getElementById("expandCB");
if ( expandSwitchCB != null ){
expandSwitchCB.checked = true;
}
var expandSwitchSettingsCB = document.getElementById("expandSettingsCB");
if ( expandSwitchSettingsCB != null ){
expandSwitchSettingsCB.checked = true;
}
$('.autoExpand').show();
} else {
$('.autoExpand').hide();
}
}
function switchExpand() {
var checkBox = document.getElementById("expandCB");
if (checkBox.checked == true) {
$('.autoExpand').show();
localStorage.setItem('switchExpand', true);
} else {
$('.autoExpand').hide();
localStorage.setItem('switchExpand', false);
}
}
function switchExpandSettings() {
var checkBox = document.getElementById("expandSettingsCB");
if (checkBox.checked == true) {
localStorage.setItem('switchExpand', true);
} else {
localStorage.setItem('switchExpand', false);
}
}