Team:Freiburg/Templates/html/js.html
From 2014.igem.org
(Difference between revisions)
Line 1: | Line 1: | ||
<html> | <html> | ||
+ | <script> | ||
+ | (function(){ | ||
+ | var DEBUG = false; | ||
+ | // grab navigation links | ||
+ | var navLinks = document.getElementsByTagName('nav'); | ||
+ | if (navLinks.length > 0) navLinks = navLinks[0]; | ||
+ | navLinks = navLinks.getElementsByTagName('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); | ||
+ | if (href.indexOf(currentPath) !== -1){ | ||
+ | // set active state | ||
+ | if (DEBUG) console.log('Setting active state for: ' + href); | ||
+ | var parent = navLinks[i].parentNode; | ||
+ | while (parent.tagName != 'NAV') { | ||
+ | // set active class for all ancestral list items | ||
+ | if (parent.tagName == 'LI') { | ||
+ | parent.setAttribute('class', 'active'); | ||
+ | } | ||
+ | parent = parent.parentNode; | ||
+ | } | ||
+ | } | ||
+ | } | ||
+ | })(); | ||
+ | </script> | ||
+ | |||
+ | |||
<script src="/Team:Freiburg/js/jquery-2.1.1.min.js?action=raw"></script> | <script src="/Team:Freiburg/js/jquery-2.1.1.min.js?action=raw"></script> | ||
<script src="/Team:Freiburg/js/bootstrap.3.2.0.min.js?action=raw"></script> | <script src="/Team:Freiburg/js/bootstrap.3.2.0.min.js?action=raw"></script> |
Revision as of 17:51, 7 October 2014