Team:Freiburg/Templates/html/js.html
From 2014.igem.org
(Difference between revisions)
Line 174: | Line 174: | ||
<script> | <script> | ||
- | |||
// remove url in front of anchor links so scroll spy behaves correctly | // remove url in front of anchor links so scroll spy behaves correctly | ||
var navLinks = $('#content-nav .nav a'); | var navLinks = $('#content-nav .nav a'); | ||
Line 180: | Line 179: | ||
// check all links' href attributes for equality with url | // check all links' href attributes for equality with url | ||
var currentPath = location.pathname; | var currentPath = location.pathname; | ||
- | |||
for (var i=0;i<navLinks.length;i++) { | for (var i=0;i<navLinks.length;i++) { | ||
var href = navLinks[i].getAttribute('href') | var href = navLinks[i].getAttribute('href') | ||
- | |||
var indexOfPath = href.indexOf(currentPath); | var indexOfPath = href.indexOf(currentPath); | ||
- | |||
if (indexOfPath === -1) continue; | if (indexOfPath === -1) continue; | ||
if (indexOfPath > 2) continue; | if (indexOfPath > 2) continue; | ||
+ | |||
var indexOfSharp = href.indexOf('#'); | var indexOfSharp = href.indexOf('#'); | ||
// check if the url part of the href ends with our location | // check if the url part of the href ends with our location | ||
var hreflength = href.length; | var hreflength = href.length; | ||
- | if (indexOfSharp | + | if (indexOfSharp !== -1) hreflength = indexOfSharp; |
- | if (indexOfPath >= | + | if (indexOfPath >= hreflength - currentPath.length - 1){ |
if (indexOfSharp === -1) { | if (indexOfSharp === -1) { | ||
navLinks[i].setAttribute('href', '#'); | navLinks[i].setAttribute('href', '#'); |
Latest revision as of 22:56, 17 October 2014