function addListenersToSections()

in _includes/index/index.js [72:114]


function addListenersToSections()
{
  var coll = document.getElementsByClassName("section-toggle");
  var i;

  // Apply exapandable (arrows) to all menuitems with a sibling
  for (i = 0; i < coll.length; i++) {
    var sibling = coll[i].nextElementSibling;

    if(sibling!==null){
      if(sibling.classList.contains("section-toggle-start-open")){
        coll[i].style.backgroundImage = "url('../images/elements/circle-minus.png')";
        sibling.style.display = "block";
      } else if (sibling.classList.contains("section-toggle-start-closed")){
        coll[i].style.backgroundImage = "url('../images/elements/circle-plus.png')";
        sibling.style.display = "none";
      } else {
        //console.log( "addListenersToSections(): No Toggle style found; default to open");
        coll[i].style.backgroundImage = "url('../images/elements/circle-minus.png')";
        sibling.style.display = "block";
      }
    }

    // Set "click" event listener on all menuitems
    coll[i].addEventListener("click", function() {
      var sibling = this.nextElementSibling;
      // toggle menu open/close states
      if(sibling!==null){
        //console.log("sibling.style.display: ["+sibling.style.display+"]");
        if (sibling.style.display !== "none") {
          //console.log("collapsing");
          sibling.style.display = "none";
          this.style.backgroundImage = "url('../images/elements/circle-plus.png')";
        } else {
          //console.log("expanding");
          sibling.style.display = "block";
          this.style.backgroundImage = "url('../images/elements/circle-minus.png')";
        }
      }

    });
  }
}