DEV: Move scrollToBottom action
This commit is contained in:
parent
fd9c23b2dc
commit
3a174ab765
|
@ -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();
|
||||||
|
|
|
@ -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;
|
||||||
}
|
}
|
||||||
|
|
|
@ -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>
|
||||||
|
|
Loading…
Reference in New Issue