From e85082d5687710d699be27cc36cbf13ea7c3a66a Mon Sep 17 00:00:00 2001 From: Peter Dietrich Date: Thu, 19 Jul 2012 16:04:19 +0200 Subject: [PATCH] Move navhighlight closure to setup.js Also limits the anchors manipulated to site-navigation --- scripts/navhighlight.js | 28 ---------------------------- scripts/setup.js | 30 ++++++++++++++++++++++++++++++ 2 files changed, 30 insertions(+), 28 deletions(-) delete mode 100644 scripts/navhighlight.js diff --git a/scripts/navhighlight.js b/scripts/navhighlight.js deleted file mode 100644 index 8ad8d24..0000000 --- a/scripts/navhighlight.js +++ /dev/null @@ -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); diff --git a/scripts/setup.js b/scripts/setup.js index cbab838..1f6c6fb 100644 --- a/scripts/setup.js +++ b/scripts/setup.js @@ -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);