From 4dce2173da9ace695fb56b0204d8e38f34a88f15 Mon Sep 17 00:00:00 2001 From: "Allan L. Bazinet" Date: Sat, 12 Jan 2013 16:47:03 -0800 Subject: [PATCH] Minor jQuery tuning Reduce scope of DOM traveral to find $prev by filtering result of $trigger. Optimistically cache and reuse result of DOM traversal to locate visibleClass. --- responsiveslides.js | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/responsiveslides.js b/responsiveslides.js index 44a33a0..fa7337a 100644 --- a/responsiveslides.js +++ b/responsiveslides.js @@ -319,14 +319,16 @@ } var $trigger = $("." + namespaceIdx + "_nav"), - $prev = $("." + namespaceIdx + "_nav.prev"); + $prev = $trigger.filter(".prev"); // Click event handler $trigger.bind("click", function (e) { e.preventDefault(); + var $visibleClass = $("." + visibleClass); + // Prevent clicking if currently animated - if ($("." + visibleClass).queue('fx').length) { + if ($visibleClass.queue('fx').length) { return; } @@ -340,7 +342,7 @@ // }); // Determine where to slide - var idx = $slide.index($("." + visibleClass)), + var idx = $slide.index($visibleClass), prevIdx = idx - 1, nextIdx = idx + 1 < length ? index + 1 : 0;