From 91cbd28fa450b66116f13144ba1f944e09b9054a Mon Sep 17 00:00:00 2001 From: Jeff Wong Date: Wed, 2 Mar 2022 15:36:24 -1000 Subject: [PATCH] FIX: calculate docking - include offset of main (#16079) Include a calculation of offset in main - this allows docking to be calculated (again) using global offsets, in case there is a custom header outside of Discourse that pushes forum content down. --- .../javascripts/discourse/app/components/site-header.js | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/app/assets/javascripts/discourse/app/components/site-header.js b/app/assets/javascripts/discourse/app/components/site-header.js index 6035a5b5830..d541ad74da9 100644 --- a/app/assets/javascripts/discourse/app/components/site-header.js +++ b/app/assets/javascripts/discourse/app/components/site-header.js @@ -196,7 +196,10 @@ const SiteHeaderComponent = MountWidget.extend( document.documentElement.style.setProperty("--header-offset", newValue); } - if (window.pageYOffset >= this.docAt) { + const main = document.querySelector("#main"); + const offsetTop = main ? main.offsetTop : 0; + const offset = window.pageYOffset - offsetTop; + if (offset >= this.docAt) { if (!this.dockedHeader) { document.body.classList.add("docked"); this.dockedHeader = true;