Update toc javascript to hopefully be more performant

This commit is contained in:
Robert Lord 2014-06-22 02:33:55 -07:00
parent 200a871f85
commit b147e6a2d7

View file

@ -681,9 +681,11 @@
self.calculateHeights();
}
var scrollTop = $(window).scrollTop();
// Determines the index of the closest anchor
self.cachedAnchors.each(function(idx) {
if (self.cachedHeights[idx] - $(window).scrollTop() < 0) {
if (self.cachedHeights[idx] - scrollTop < 0) {
closestAnchorIdx = idx;
} else {
return false;
@ -696,7 +698,7 @@
elem = $('li[data-unique="' + anchorText + '"]');
// If the `highlightOnScroll` option is true and a next element is found
if(self.options.highlightOnScroll && elem.length) {
if(self.options.highlightOnScroll && elem.length && !elem.hasClass(self.focusClass)) {
// Removes highlighting from all of the list item's
self.element.find("." + self.focusClass).removeClass(self.focusClass);