Team:Freiburg/Templates/html/js.html

From 2014.igem.org

(Difference between revisions)
Line 112: Line 112:
           type: 'iframe'
           type: 'iframe'
         });
         });
-
      });
 
-
 
-
      $('body').scrollspy({
 
-
        target: '#content-nav',
 
-
        offset: $(window).height()/4
 
       });
       });
Line 177: Line 172:
     });
     });
</script>
</script>
 +
 +
<script>
 +
    var DEBUG = true;
 +
    // remove url in front of anchor links so scroll spy behaves correctly
 +
    var navLinks = $('#content-nav .nav a');
 +
 +
    // check all links' href attributes for equality with url
 +
    var currentPath = location.pathname;
 +
    if (DEBUG) console.log("Current Path: " + currentPath);
 +
    for (var i=0;i<navLinks.length;i++) {
 +
      var href = navLinks[i].getAttribute('href')
 +
      if (DEBUG) console.log(href);
 +
      var indexOfPath = href.indexOf(currentPath);
 +
      if (DEBUG) console.log("indexofPath: " + indexOfPath);
 +
      if (indexOfPath === -1) continue;
 +
      var indexOfSharp = href.indexOf('#');
 +
      if (indexOfSharp === -1) {
 +
        navLinks[i].setAttribute('href', '#');
 +
        navLinks[i].setAttribute('class', 'active');
 +
      } else {
 +
        navLinks[i].setAttribute('href', href.slice(indexOfSharp));
 +
      }
 +
    }
 +
 +
    // initialize scrollspy
 +
    $('body').scrollspy({
 +
      target: '#content-nav',
 +
      offset: $(window).height()/4
 +
    });
 +
 +
    // different click navigation for first link
 +
    $('#content-nav .nav > li > a ').click(function(e){
 +
      var $parent = $(this.parentNode);
 +
      var children = $parent.children('ul');
 +
      // prevent redirect if we have children
 +
      if (children.length == 0) return;
 +
      e.preventDefault();
 +
 +
      // open up the nav otherwise
 +
      $parent.toggleClass('active');
 +
    });
 +
  </script>
<script src="/Team:Freiburg/js/jquery.qtip.min.js?action=raw&ctype=text/javascript"></script>
<script src="/Team:Freiburg/js/jquery.qtip.min.js?action=raw&ctype=text/javascript"></script>

Revision as of 21:50, 17 October 2014