Skip to content
Snippets Groups Projects
Verified Commit 7f4affff authored by Volker Schukai's avatar Volker Schukai :alien:
Browse files

fix(table-of-content): fix scroll down

parent 3702f1a7
Branches
Tags
No related merge requests found
...@@ -162,7 +162,7 @@ class TableOfContent extends CustomElement { ...@@ -162,7 +162,7 @@ class TableOfContent extends CustomElement {
if (this[scrollableParentSymbol] === getWindow()) { if (this[scrollableParentSymbol] === getWindow()) {
if ( if (
["absolute", "relative", "fixed", "sticky"].indexOf( ["absolute", "relative", "fixed", "sticky"].indexOf(
this[scrollableParentSymbol].style.position, this[scrollableParentSymbol]?.style?.position,
) === -1 ) === -1
) { ) {
this.style.position = "relative"; this.style.position = "relative";
...@@ -176,7 +176,7 @@ class TableOfContent extends CustomElement { ...@@ -176,7 +176,7 @@ class TableOfContent extends CustomElement {
} else { } else {
if ( if (
["absolute", "relative", "fixed", "sticky"].indexOf( ["absolute", "relative", "fixed", "sticky"].indexOf(
this[scrollableParentSymbol].style.position, this[scrollableParentSymbol]?.style?.position,
) === -1 ) === -1
) { ) {
this[scrollableParentSymbol].style.position = "relative"; this[scrollableParentSymbol].style.position = "relative";
...@@ -229,6 +229,25 @@ class TableOfContent extends CustomElement { ...@@ -229,6 +229,25 @@ class TableOfContent extends CustomElement {
} }
} }
/**
* @private
* @param element
* @returns {number|number|*|number}
*/
function getScrollHeight(element) {
if (element instanceof ShadowRoot) {
return element.host.scrollHeight;
}
if (element === getWindow()) {
return element.document.documentElement.scrollHeight;
}
return element.scrollHeight;
}
/** /**
* @private * @private
* @return {void} * @return {void}
...@@ -339,7 +358,7 @@ function initNavigation() { ...@@ -339,7 +358,7 @@ function initNavigation() {
this[scrollableParentSymbol].scrollTo( this[scrollableParentSymbol].scrollTo(
0, 0,
this[scrollableParentSymbol].scrollHeight, getScrollHeight(this[scrollableParentSymbol]),
); );
}); });
footer.appendChild(scrollToBottom); footer.appendChild(scrollToBottom);
...@@ -428,7 +447,6 @@ function getHeadings() { ...@@ -428,7 +447,6 @@ function getHeadings() {
const headings = element.querySelectorAll("h1, h2, h3, h4, h5, h6"); const headings = element.querySelectorAll("h1, h2, h3, h4, h5, h6");
let nodeList = Array.from(headings); let nodeList = Array.from(headings);
// remove all with attribute data-monster-table-of-content-omit
nodeList = nodeList.filter((node) => { nodeList = nodeList.filter((node) => {
return !node.hasAttribute("data-monster-table-of-content-omit"); return !node.hasAttribute("data-monster-table-of-content-omit");
}); });
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment