2023-08-15 22:50:13 +02:00
|
|
|
import NoteContextAwareWidget from "./note_context_aware_widget.js";
|
|
|
|
|
2025-04-01 23:24:21 +03:00
|
|
|
const TPL = /*html*/`<div class="scroll-padding-widget"></div>`;
|
2023-08-15 22:50:13 +02:00
|
|
|
|
|
|
|
export default class ScrollPaddingWidget extends NoteContextAwareWidget {
|
2025-02-11 19:04:27 +02:00
|
|
|
|
|
|
|
private $scrollingContainer!: JQuery<HTMLElement>;
|
|
|
|
|
2023-11-06 22:26:17 +01:00
|
|
|
isEnabled() {
|
2025-02-11 19:04:27 +02:00
|
|
|
return super.isEnabled() && ["text", "code"].includes(this.note?.type ?? "");
|
2023-11-06 22:26:17 +01:00
|
|
|
}
|
|
|
|
|
2023-08-15 22:50:13 +02:00
|
|
|
doRender() {
|
|
|
|
this.$widget = $(TPL);
|
|
|
|
this.contentSized();
|
|
|
|
|
2025-01-09 18:07:02 +02:00
|
|
|
this.$widget.on("click", () => this.triggerCommand("scrollToEnd", { ntxId: this.ntxId }));
|
2023-08-15 22:50:13 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
initialRenderCompleteEvent() {
|
|
|
|
this.$scrollingContainer = this.$widget.closest(".scrolling-container");
|
|
|
|
|
|
|
|
new ResizeObserver(() => this.refreshHeight()).observe(this.$scrollingContainer[0]);
|
|
|
|
|
|
|
|
this.refreshHeight();
|
|
|
|
}
|
|
|
|
|
|
|
|
refreshHeight() {
|
|
|
|
const containerHeight = this.$scrollingContainer.height();
|
|
|
|
|
2025-02-11 19:04:27 +02:00
|
|
|
this.$widget.css("height", Math.round((containerHeight ?? 0) / 2));
|
2023-08-15 22:50:13 +02:00
|
|
|
}
|
|
|
|
}
|