DEV: Move scrollToBottom action

This commit is contained in:
Jarek Radosz 2022-10-02 18:59:20 +02:00
parent fd9c23b2dc
commit 3a174ab765
No known key found for this signature in database
GPG Key ID: 62D0FBAE5BF9B953
3 changed files with 16 additions and 18 deletions

View File

@ -1,7 +1,21 @@
import Component from "@glimmer/component"; import Component from "@glimmer/component";
import { action } from "@ember/object"; import { action } from "@ember/object";
import { headerOffset } from "discourse/lib/offset-calculator";
export default class TableOfContents extends Component { export default class TableOfContents extends Component {
@action
scrollToBottom(e) {
e.preventDefault();
const rect = document
.querySelector(".d-toc-cooked")
.getBoundingClientRect();
window.scrollTo({
top: rect.bottom + window.scrollY - headerOffset() - 10,
behavior: "smooth",
});
}
@action @action
closeOverlay(e) { closeOverlay(e) {
e.preventDefault(); e.preventDefault();

View File

@ -192,23 +192,6 @@ export default {
return false; return false;
} }
if (e.target.closest("a")) {
// link to first post bottom
if (e.target.closest("a").classList.contains("scroll-to-bottom")) {
const rect = document
.querySelector(".d-toc-cooked")
.getBoundingClientRect();
window.scrollTo({
top: rect.bottom + window.scrollY - headerOffset() - 10,
behavior: "smooth",
});
e.preventDefault();
return false;
}
}
if (!document.querySelector(".d-toc-wrapper.overlay")) { if (!document.querySelector(".d-toc-wrapper.overlay")) {
return; return;
} }

View File

@ -1,9 +1,10 @@
<div class="d-toc-main"> <div class="d-toc-main">
<div class="d-toc-icons"> <div class="d-toc-icons">
<a <a
href="#" href
class="scroll-to-bottom" class="scroll-to-bottom"
title={{i18n (theme-prefix "post_bottom_tooltip")}} title={{i18n (theme-prefix "post_bottom_tooltip")}}
{{on "click" this.scrollToBottom}}
> >
{{d-icon "downward"}} {{d-icon "downward"}}
</a> </a>