mirror of
https://github.com/stan220/godot-docs.git
synced 2026-09-08 17:28:58 +00:00
Fix ethical banner appearing in steps (#3394)
This commit is contained in:
+62
-17
@@ -89,8 +89,10 @@ const registerOnScrollEvent = (function(){
|
|||||||
|
|
||||||
// Near the bottom we start moving the sidebar banner into view.
|
// Near the bottom we start moving the sidebar banner into view.
|
||||||
if (menuScrollBottom < ethicalOffsetBottom) {
|
if (menuScrollBottom < ethicalOffsetBottom) {
|
||||||
|
$ethical.css('display', 'block');
|
||||||
$ethical.css('margin-top', `-${ethicalOffsetBottom - menuScrollBottom}px`);
|
$ethical.css('margin-top', `-${ethicalOffsetBottom - menuScrollBottom}px`);
|
||||||
} else {
|
} else {
|
||||||
|
$ethical.css('display', 'none');
|
||||||
$ethical.css('margin-top', '0px');
|
$ethical.css('margin-top', '0px');
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
@@ -131,29 +133,72 @@ const registerOnScrollEvent = (function(){
|
|||||||
$menu.css('max-height', 'initial');
|
$menu.css('max-height', 'initial');
|
||||||
$menuPadding.css('height', `0px`);
|
$menuPadding.css('height', `0px`);
|
||||||
$ethical.css('margin-top', '0px');
|
$ethical.css('margin-top', '0px');
|
||||||
|
$ethical.css('display', 'block');
|
||||||
}
|
}
|
||||||
}
|
};
|
||||||
|
})();
|
||||||
|
|
||||||
|
// Subscribe to DOM changes in the sidebar container, because there is a
|
||||||
|
// banner that gets added at a later point, that we might not catch otherwise.
|
||||||
|
const registerSidebarObserver = (function(){
|
||||||
|
return function(callback) {
|
||||||
|
const sidebarContainer = document.querySelector('.wy-side-scroll');
|
||||||
|
|
||||||
|
let sidebarEthical = null;
|
||||||
|
const registerEthicalObserver = () => {
|
||||||
|
if (sidebarEthical) {
|
||||||
|
// Do it only once.
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
sidebarEthical = sidebarContainer.querySelector('.ethical-rtd');
|
||||||
|
if (!sidebarEthical) {
|
||||||
|
// Do it only after we have the element there.
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// This observer watches over the ethical block in sidebar, and all of its subtree.
|
||||||
|
const ethicalObserverConfig = { childList: true, subtree: true };
|
||||||
|
const ethicalObserverCallback = (mutationsList, observer) => {
|
||||||
|
for (let mutation of mutationsList) {
|
||||||
|
if (mutation.type !== 'childList') {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
callback();
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
const ethicalObserver = new MutationObserver(ethicalObserverCallback);
|
||||||
|
ethicalObserver.observe(sidebarEthical, ethicalObserverConfig);
|
||||||
|
};
|
||||||
|
registerEthicalObserver();
|
||||||
|
|
||||||
|
// This observer watches over direct children of the main sidebar container.
|
||||||
|
const observerConfig = { childList: true };
|
||||||
|
const observerCallback = (mutationsList, observer) => {
|
||||||
|
for (let mutation of mutationsList) {
|
||||||
|
if (mutation.type !== 'childList') {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
callback();
|
||||||
|
registerEthicalObserver();
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
const observer = new MutationObserver(observerCallback);
|
||||||
|
observer.observe(sidebarContainer, observerConfig);
|
||||||
|
};
|
||||||
})();
|
})();
|
||||||
|
|
||||||
$(document).ready(() => {
|
$(document).ready(() => {
|
||||||
const sidebarContainer = document.querySelector('.wy-side-scroll');
|
|
||||||
const mediaQuery = window.matchMedia('only screen and (min-width: 769px)');
|
const mediaQuery = window.matchMedia('only screen and (min-width: 769px)');
|
||||||
|
|
||||||
// Subscribe to DOM changes in the sidebar container, because there is a
|
|
||||||
// banner that gets added at a later point, that we might not catch otherwise.
|
|
||||||
const observerConfig = { childList: true };
|
|
||||||
const observerCallback = (mutationsList, observer) => {
|
|
||||||
for (let mutation of mutationsList) {
|
|
||||||
if (mutation.type !== 'childList') {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
registerOnScrollEvent(mediaQuery);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
const observer = new MutationObserver(observerCallback);
|
|
||||||
observer.observe(sidebarContainer, observerConfig);
|
|
||||||
|
|
||||||
registerOnScrollEvent(mediaQuery);
|
registerOnScrollEvent(mediaQuery);
|
||||||
mediaQuery.addListener(registerOnScrollEvent);
|
mediaQuery.addListener(registerOnScrollEvent);
|
||||||
|
|
||||||
|
registerSidebarObserver(() => {
|
||||||
|
registerOnScrollEvent(mediaQuery);
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
Reference in New Issue
Block a user