Commit 5cc9188e authored by Robert Lord's avatar Robert Lord

Fix tocify to reset cache on browser window resize

parent 9e84ebf2
......@@ -591,6 +591,14 @@
}
});
// Reset height cache on scroll
$(window).on('resize', function() {
console.log("resizing" + self.cachedHeights);
self.calculateHeights();
console.log("done" + self.cachedHeights);
});
// Window scroll event handler
$(window).on("scroll.tocify", function() {
......@@ -668,7 +676,10 @@
closestAnchorIdx = null,
anchorText;
// if never calculated before, calculate and cache the heights
if (self.cachedHeights.length == 0) {
self.calculateHeights();
}
// Determines the index of the closest anchor
self.cachedAnchors.each(function(idx) {
......@@ -725,7 +736,6 @@
// ADDED BY ROBERT
calculateHeights: function() {
var self = this;
if (self.cachedHeights.length == 0) {
self.cachedHeights = [];
self.cachedAnchors = [];
var anchors = $(self.options.context).find("div[data-unique]");
......@@ -734,7 +744,6 @@
self.cachedHeights[idx] = distance;
});
self.cachedAnchors = anchors;
}
},
// Show
......
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