diff --git a/javascripts/discourse/components/table-of-contents.js b/javascripts/discourse/components/table-of-contents.js index f3fa26c..b9401b7 100644 --- a/javascripts/discourse/components/table-of-contents.js +++ b/javascripts/discourse/components/table-of-contents.js @@ -1,7 +1,21 @@ import Component from "@glimmer/component"; import { action } from "@ember/object"; +import { headerOffset } from "discourse/lib/offset-calculator"; 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 closeOverlay(e) { e.preventDefault(); diff --git a/javascripts/discourse/initializers/disco-toc-main.js b/javascripts/discourse/initializers/disco-toc-main.js index 5e48a9d..8c9d5e7 100644 --- a/javascripts/discourse/initializers/disco-toc-main.js +++ b/javascripts/discourse/initializers/disco-toc-main.js @@ -192,23 +192,6 @@ export default { 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")) { return; } diff --git a/javascripts/discourse/templates/components/table-of-contents.hbs b/javascripts/discourse/templates/components/table-of-contents.hbs index 830d1e3..c938ccb 100644 --- a/javascripts/discourse/templates/components/table-of-contents.hbs +++ b/javascripts/discourse/templates/components/table-of-contents.hbs @@ -1,9 +1,10 @@
{{d-icon "downward"}}