From a33542b47c827ab706b430442faf697710279d43 Mon Sep 17 00:00:00 2001 From: Peter Dietrich Date: Thu, 19 Jul 2012 16:14:40 +0200 Subject: [PATCH] Cache navLinks and filter for performance --- scripts/setup.js | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/scripts/setup.js b/scripts/setup.js index 1f6c6fb..23ef869 100644 --- a/scripts/setup.js +++ b/scripts/setup.js @@ -31,7 +31,8 @@ //console.log("They see me scrollin, they hatin"); //clear highlighting - $('.site-navigation a').removeClass("active"); + var navLinks=$('.site-navigation a') + navLinks.removeClass("active"); //calc current viewport var viewTop = $(window).scrollTop(); @@ -45,7 +46,8 @@ var eBottom = eTop + $(e).height(); if (eTop >= viewTop) { if (eBottom <= viewBottom) { - $('.site-navigation a[href="/#'+e.id+'"]').addClass("active"); + //filter cached navLinks + navLinks.filter('[href="/#'+e.id+'"]').addClass("active"); } else { //console.log("Start skipping test with "+e.id); return false;