From a75b84b73324dc40fce9afb3f400939914a9e8f2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20Ad=C3=A1mek?= Date: Thu, 28 Nov 2024 13:09:55 +0100 Subject: [PATCH] use redocusaurus on raw specs so we dont run decorators twice --- apify-docs-theme/static/js/custom.js | 21 +++++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) diff --git a/apify-docs-theme/static/js/custom.js b/apify-docs-theme/static/js/custom.js index 0ad86801f..efb566d28 100644 --- a/apify-docs-theme/static/js/custom.js +++ b/apify-docs-theme/static/js/custom.js @@ -61,6 +61,20 @@ function scrollSidebarItemIntoView() { } } +// handles automatic scrolling of the API reference sidebar (openapi-docs) +function scrollOpenApiSidebarItemIntoView() { + const $li = document.querySelector(`li > a.menu__link--active[href]`); + + if (!$li) { + return; + } + + $li.scrollIntoView({ + block: 'nearest', + inline: 'center', + }); +} + let ticking = false; document.addEventListener('scroll', () => { @@ -75,7 +89,10 @@ document.addEventListener('scroll', () => { } }); -document.addEventListener('DOMContentLoaded', () => { +window.addEventListener('load', () => { // we need to wait a bit more, since the event fires too soon, and a lot of hydration is done after it - setTimeout(() => scrollSidebarItemIntoView(), 3000); + setTimeout(() => scrollSidebarItemIntoView(), 1000); + + // docusaurus-openapi-docs plugin: scroll sidebar into viewport, no need for a large timeout here + setTimeout(() => scrollOpenApiSidebarItemIntoView(), 100); });