mirror of
https://github.com/danbulant/api_docs
synced 2026-06-24 17:12:01 +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 scroll event handler
|
||||||
$(window).on("scroll.tocify", function() {
|
$(window).on("scroll.tocify", function() {
|
||||||
|
|
||||||
|
|
@ -668,7 +676,10 @@
|
||||||
closestAnchorIdx = null,
|
closestAnchorIdx = null,
|
||||||
anchorText;
|
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
|
// Determines the index of the closest anchor
|
||||||
self.cachedAnchors.each(function(idx) {
|
self.cachedAnchors.each(function(idx) {
|
||||||
|
|
@ -725,16 +736,14 @@
|
||||||
// ADDED BY ROBERT
|
// ADDED BY ROBERT
|
||||||
calculateHeights: function() {
|
calculateHeights: function() {
|
||||||
var self = this;
|
var self = this;
|
||||||
if (self.cachedHeights.length == 0) {
|
self.cachedHeights = [];
|
||||||
self.cachedHeights = [];
|
self.cachedAnchors = [];
|
||||||
self.cachedAnchors = [];
|
var anchors = $(self.options.context).find("div[data-unique]");
|
||||||
var anchors = $(self.options.context).find("div[data-unique]");
|
anchors.each(function(idx) {
|
||||||
anchors.each(function(idx) {
|
var distance = (($(this).next().length ? $(this).next() : $(this)).offset().top - self.options.highlightOffset);
|
||||||
var distance = (($(this).next().length ? $(this).next() : $(this)).offset().top - self.options.highlightOffset);
|
self.cachedHeights[idx] = distance;
|
||||||
self.cachedHeights[idx] = distance;
|
});
|
||||||
});
|
self.cachedAnchors = anchors;
|
||||||
self.cachedAnchors = anchors;
|
|
||||||
}
|
|
||||||
},
|
},
|
||||||
|
|
||||||
// Show
|
// Show
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue