Commit b147e6a2 authored by Robert Lord's avatar Robert Lord

Update toc javascript to hopefully be more performant

parent 200a871f
...@@ -681,9 +681,11 @@ ...@@ -681,9 +681,11 @@
self.calculateHeights(); self.calculateHeights();
} }
var scrollTop = $(window).scrollTop();
// Determines the index of the closest anchor // Determines the index of the closest anchor
self.cachedAnchors.each(function(idx) { self.cachedAnchors.each(function(idx) {
if (self.cachedHeights[idx] - $(window).scrollTop() < 0) { if (self.cachedHeights[idx] - scrollTop < 0) {
closestAnchorIdx = idx; closestAnchorIdx = idx;
} else { } else {
return false; return false;
...@@ -696,7 +698,7 @@ ...@@ -696,7 +698,7 @@
elem = $('li[data-unique="' + anchorText + '"]'); elem = $('li[data-unique="' + anchorText + '"]');
// If the `highlightOnScroll` option is true and a next element is found // 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 // Removes highlighting from all of the list item's
self.element.find("." + self.focusClass).removeClass(self.focusClass); self.element.find("." + self.focusClass).removeClass(self.focusClass);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment