Move navhighlight closure to setup.js

Also limits the anchors manipulated to site-navigation
This commit is contained in:
Peter Dietrich
2012-07-19 16:04:19 +02:00
parent d425cde227
commit e85082d568
2 changed files with 30 additions and 28 deletions

View File

@@ -1,28 +0,0 @@
(function ($) {
$(window).scroll(function() {
//console.log("They see me scrollin, they hatin");
//clear highlighting
$('a').removeClass("active");
//calc current viewport
var viewTop = $(window).scrollTop();
var viewBottom = viewTop + $(window).height();
//for all h1 and h2 elements, check if they are visible
//performance tweak: stop each() after the first element is found to be behind view
$('h1, h2').each(function(i,e) {
//get element position;
var eTop = $(e).offset().top;
var eBottom = eTop + $(e).height();
if (eTop >= viewTop) {
if (eBottom <= viewBottom) {
$('a[href="#'+e.id+'"]').addClass("active");
} else {
//console.log("Start skipping test with "+e.id);
return false;
}
}
});
});
})(jQuery);

View File

@@ -24,3 +24,33 @@
}).fail(fail);
}
})(jQuery);
(function ($) {
//Add current view's highlighting to the navigation
$(window).scroll(function() {
//console.log("They see me scrollin, they hatin");
//clear highlighting
$('.site-navigation a').removeClass("active");
//calc current viewport
var viewTop = $(window).scrollTop();
var viewBottom = viewTop + $(window).height();
//for all h1 and h2 elements, check if they are visible
//performance tweak: stop each() after the first element is found to be behind view
$('h1, h2').each(function(i,e) {
//get element position;
var eTop = $(e).offset().top;
var eBottom = eTop + $(e).height();
if (eTop >= viewTop) {
if (eBottom <= viewBottom) {
$('.site-navigation a[href="/#'+e.id+'"]').addClass("active");
} else {
//console.log("Start skipping test with "+e.id);
return false;
}
}
});
});
})(jQuery);