mirror of
https://github.com/discourse/discourse.git
synced 2025-03-09 14:34:35 +00:00
This reverts commit af912b4b0efc9a8182c5b70a323f593b14e7ca38.
This commit is contained in:
parent
6c13d82630
commit
8cd1340170
@ -12,8 +12,6 @@ export default class Sidebar extends Component {
|
||||
if (this.site.mobileView) {
|
||||
document.addEventListener("click", this.collapseSidebar);
|
||||
}
|
||||
// This appEvent handler is experimental and should not be relied on as an extension point yet.
|
||||
this.appEvents.on("sidebar:scroll-to-element", this, this.#scrollToElement);
|
||||
}
|
||||
|
||||
@bind
|
||||
@ -37,68 +35,9 @@ export default class Sidebar extends Component {
|
||||
}
|
||||
}
|
||||
|
||||
#scrollToElement(destinationElement) {
|
||||
const topPadding = 10;
|
||||
|
||||
const sidebarContainerElement =
|
||||
document.querySelector(".sidebar-container");
|
||||
|
||||
const distanceFromTop =
|
||||
document.getElementsByClassName(destinationElement)[0].offsetTop -
|
||||
topPadding;
|
||||
|
||||
this.#setMissingHeightForScroll(sidebarContainerElement, distanceFromTop);
|
||||
|
||||
sidebarContainerElement.scrollTop = distanceFromTop;
|
||||
}
|
||||
|
||||
#setMissingHeightForScroll(sidebarContainerElement, distanceFromTop) {
|
||||
const allSections = document.getElementsByClassName(
|
||||
"sidebar-section-wrapper"
|
||||
);
|
||||
|
||||
const lastSectionElement = allSections[allSections.length - 1];
|
||||
|
||||
const lastSectionBottomPadding = parseInt(
|
||||
lastSectionElement.style.paddingBottom?.replace("px", "") || 0,
|
||||
10
|
||||
);
|
||||
|
||||
const headerOffset = parseInt(
|
||||
document.documentElement.style.getPropertyValue("--header-offset"),
|
||||
10
|
||||
);
|
||||
|
||||
let allSectionsHeight = 0;
|
||||
|
||||
for (const section of allSections) {
|
||||
allSectionsHeight +=
|
||||
section.clientHeight +
|
||||
parseInt(
|
||||
window.getComputedStyle(section).marginBottom.replace("px", ""),
|
||||
10
|
||||
);
|
||||
}
|
||||
|
||||
const missingHeight =
|
||||
sidebarContainerElement.clientHeight -
|
||||
headerOffset +
|
||||
lastSectionBottomPadding -
|
||||
(allSectionsHeight - distanceFromTop);
|
||||
|
||||
lastSectionElement.style.paddingBottom =
|
||||
missingHeight > 0 ? `${missingHeight}px` : null;
|
||||
}
|
||||
|
||||
willDestroy() {
|
||||
if (this.site.mobileView) {
|
||||
document.removeEventListener("click", this.collapseSidebar);
|
||||
}
|
||||
|
||||
this.appEvents.off(
|
||||
"sidebar:scroll-to-element",
|
||||
this,
|
||||
this.#scrollToElement
|
||||
);
|
||||
}
|
||||
}
|
||||
|
@ -38,7 +38,6 @@
|
||||
scrollbar-color: transparent var(--scrollbarBg);
|
||||
transition: scrollbar-color 0.25s ease-in-out;
|
||||
transition-delay: 0.5s;
|
||||
scroll-behavior: smooth;
|
||||
|
||||
&::-webkit-scrollbar-thumb {
|
||||
background-color: transparent;
|
||||
|
Loading…
x
Reference in New Issue
Block a user