Difference between revisions of "Template:TU Darmstadt/JS"

 
(11 intermediate revisions by the same user not shown)
Line 16: Line 16:
 
       nav.classList.remove('show-menu');
 
       nav.classList.remove('show-menu');
 
     }, 300);
 
     }, 300);
 +
  }
 +
 +
  document.getElementsByClassName('burger-inner')[0].addEventListener('click', function () {
 +
    document.body.classList.toggle('nav-in');
 +
  });
 +
 +
  var mul = ul.getElementsByClassName('multiple');
 +
  for (var i = 0; i < mul.length; i++) {
 +
    var m = mul[i];
 +
    m.addEventListener('click', function () {
 +
      for (var j = 0; j < mul.length; j++) {
 +
        var r = mul[j];
 +
        r.classList.remove('clicked');
 +
      }
 +
 +
      this.classList.add('clicked');
 +
    });
 
   }
 
   }
  
 
   ul.addEventListener('mouseover', over);
 
   ul.addEventListener('mouseover', over);
 
   ul.addEventListener('mouseout', out);
 
   ul.addEventListener('mouseout', out);
 
  var crumbs = document.getElementById('breadcrumbs').innerHTML;
 
  document.getElementById('breadcrumb-target').innerHTML = crumbs;
 
  
 
   var as = document.getElementById('toc').getElementsByTagName('a');
 
   var as = document.getElementById('toc').getElementsByTagName('a');
   for (var a of as) {
+
   for (var i = 0; i < as.length; i++) {
 +
    var a = as[i];
 
     a.addEventListener('click', function () {
 
     a.addEventListener('click', function () {
       for (var oa of as) {
+
       for (var j = 0; j < as.length; j++) {
 +
        var oa = as[j];
 
         oa.classList.remove('active');
 
         oa.classList.remove('active');
 
       }
 
       }
Line 35: Line 51:
 
   }
 
   }
  
 +
  // thanks to wikimedia replacing two ampersands with &amp;&amp;
 +
  function and(a, b) {
 +
    if (a == true) {
 +
      if (b == true) {
 +
        return true;
 +
      }
 +
    }
 +
    return false;
 +
  }
  
   document.addEventListener('scroll', function () {
+
   function setScrollyThing() {
 
     var activeA = null;
 
     var activeA = null;
     for (var a of as) {
+
    var nextIsActive = false;
 +
     for (var i = 0; i < as.length; i++) {
 +
      var a = as[i];
 
       a.classList.remove('active');
 
       a.classList.remove('active');
 +
 +
      if (nextIsActive || and(!a.parentElement.classList.contains('toclevel-1'), !activeA)) {
 +
        activeA = a;
 +
        nextIsActive = false;
 +
        continue;
 +
      }
  
 
       var id = a.href.replace(/.+?#/, '');
 
       var id = a.href.replace(/.+?#/, '');
Line 49: Line 82:
  
 
       var y = element.getBoundingClientRect().top;
 
       var y = element.getBoundingClientRect().top;
       var active = y < 50;
+
       var active = y < 200;
 
       if (active) {
 
       if (active) {
 +
        if (a.parentElement.classList.contains('toclevel-1')) nextIsActive = true;
 
         activeA = a;
 
         activeA = a;
 
       }
 
       }
 
     }
 
     }
  
    console.log(activeA);
 
 
     activeA.classList.add('active');
 
     activeA.classList.add('active');
   });
+
   }
 +
 
 +
  document.addEventListener('scroll', setScrollyThing);
 +
  setScrollyThing();
 
    
 
    
 
});
 
});
 
</script>
 
</script>
 
</html>
 
</html>

Latest revision as of 17:18, 17 October 2018