mirror of
https://github.com/discourse/discourse.git
synced 2026-09-05 04:40:41 -05:00
We've been using basic type-checking via JSDoc for some time. This commit allows us to author proper `.ts`/`.gts` files, and use the full typescript syntax. Initially, only d-button and a single chat file are migrated, as proof of functionality. In future, we may migrate more files, and consider making our tsconfig more strict.
23 lines
639 B
TypeScript
23 lines
639 B
TypeScript
const BOTTOM_VISIBILITY_SLACK = 10;
|
|
|
|
export function checkMessageBottomVisibility(
|
|
list: Element,
|
|
message: Element
|
|
): boolean {
|
|
const distanceToTop = window.pageYOffset + list.getBoundingClientRect().top;
|
|
const bounding = message.getBoundingClientRect();
|
|
return (
|
|
bounding.bottom - distanceToTop <=
|
|
list.clientHeight + BOTTOM_VISIBILITY_SLACK
|
|
);
|
|
}
|
|
|
|
export function checkMessageTopVisibility(
|
|
list: Element,
|
|
message: Element
|
|
): boolean {
|
|
const distanceToTop = window.pageYOffset + list.getBoundingClientRect().top;
|
|
const bounding = message.getBoundingClientRect();
|
|
return bounding.top - distanceToTop >= -1;
|
|
}
|