@apify/docs-theme 1.0.140 → 1.0.141
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +1 -1
- package/static/js/custom.js +42 -0
package/package.json
CHANGED
package/static/js/custom.js
CHANGED
|
@@ -32,3 +32,45 @@
|
|
|
32
32
|
// load();
|
|
33
33
|
// }
|
|
34
34
|
// }, 500);
|
|
35
|
+
|
|
36
|
+
let lastKnownScrollHash = '';
|
|
37
|
+
|
|
38
|
+
// handles automatic scrolling of the API reference sidebar (redoc)
|
|
39
|
+
function scrollSidebarItemIntoView() {
|
|
40
|
+
const hash = window.location.hash.substring(1);
|
|
41
|
+
|
|
42
|
+
if (hash !== lastKnownScrollHash) {
|
|
43
|
+
const $li = document.querySelector(`li[data-item-id="${hash}"]`);
|
|
44
|
+
|
|
45
|
+
if (!$li) {
|
|
46
|
+
return;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
// not visible, click on the parent <li> first
|
|
50
|
+
if (!$li.offsetParent) {
|
|
51
|
+
$li.parentElement?.parentElement?.click();
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
$li.scrollIntoView({
|
|
55
|
+
// smooth would be nice, but it's not working in some case
|
|
56
|
+
// behavior: 'smooth',
|
|
57
|
+
block: 'nearest',
|
|
58
|
+
inline: 'center',
|
|
59
|
+
});
|
|
60
|
+
lastKnownScrollHash = hash;
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
let ticking = false;
|
|
65
|
+
|
|
66
|
+
document.addEventListener('scroll', () => {
|
|
67
|
+
if (!ticking) {
|
|
68
|
+
// throttling based on current frame rate
|
|
69
|
+
window.requestAnimationFrame(() => {
|
|
70
|
+
scrollSidebarItemIntoView();
|
|
71
|
+
ticking = false;
|
|
72
|
+
});
|
|
73
|
+
|
|
74
|
+
ticking = true;
|
|
75
|
+
}
|
|
76
|
+
});
|