mirror of
https://github.com/danbulant/api_docs
synced 2026-06-14 20:01:14 +00:00
Fix tocify to reset cache on browser window resize
This commit is contained in:
parent
9e84ebf28c
commit
5cc9188e3c
1 changed files with 20 additions and 11 deletions
|
|
@ -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;
|
||||
|
||||
self.calculateHeights();
|
||||
// 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,16 +736,14 @@
|
|||
// 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]");
|
||||
anchors.each(function(idx) {
|
||||
var distance = (($(this).next().length ? $(this).next() : $(this)).offset().top - self.options.highlightOffset);
|
||||
self.cachedHeights[idx] = distance;
|
||||
});
|
||||
self.cachedAnchors = anchors;
|
||||
}
|
||||
self.cachedHeights = [];
|
||||
self.cachedAnchors = [];
|
||||
var anchors = $(self.options.context).find("div[data-unique]");
|
||||
anchors.each(function(idx) {
|
||||
var distance = (($(this).next().length ? $(this).next() : $(this)).offset().top - self.options.highlightOffset);
|
||||
self.cachedHeights[idx] = distance;
|
||||
});
|
||||
self.cachedAnchors = anchors;
|
||||
},
|
||||
|
||||
// Show
|
||||
|
|
|
|||
Loading…
Reference in a new issue