DEV: Small refactor to header offset (#15421)

Centralizes calculations in a helper under the site header component.

This also reverts a small CSS change to the composer: since ac79c5ef,
the composer height was not including the grippie, which means that the
composer height was off by 11 pixels, and the topic progress widget was
sometimes being displayed cut off by 11 pixels.
This commit is contained in:
Penar Musaraj
2021-12-29 11:03:21 -05:00
committed by GitHub
parent 108c8302fb
commit 879e35195a
6 changed files with 24 additions and 40 deletions

View File

@ -1,5 +1,6 @@
import { ajax } from "discourse/lib/ajax";
import discourseDebounce from "discourse-common/lib/debounce";
import { headerOffset } from "discourse/components/site-header";
import isElementInViewport from "discourse/lib/is-element-in-viewport";
import { withPluginApi } from "discourse/lib/plugin-api";
@ -85,17 +86,10 @@ function initialize(api) {
return;
}
const headerOffset =
parseInt(
getComputedStyle(document.body).getPropertyValue(
"--header-offset"
),
10
) || 0;
const viewportOffset = post.getBoundingClientRect();
window.scrollTo({
top: window.scrollY + viewportOffset.top - headerOffset,
top: window.scrollY + viewportOffset.top - headerOffset(),
behavior: "smooth",
});
},