-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: introduce occurence param and jump to occurence
- Loading branch information
Showing
2 changed files
with
21 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,20 @@ | ||
const markInstance = new Mark(document.querySelector("#textcontent")); | ||
const contentElement = document.querySelector("#textcontent"); | ||
const headerElm = document.querySelector("wpn-header"); | ||
const markInstance = new Mark(contentElement); | ||
const url = new URL(window.location.href); | ||
const urlParam = new URLSearchParams(url.search); | ||
if (urlParam.get("mark")) { | ||
markInstance.mark(urlParam.get("mark")); | ||
} | ||
const markValue = urlParam.get("mark"); | ||
const occurence = urlParam.get("occurence"); | ||
if (markValue) { | ||
markInstance.mark(markValue,{ | ||
done: () => { | ||
const marks = contentElement.querySelectorAll("mark"); | ||
let matchNr = 0; | ||
if (occurence && (/\d+/g).test(occurence)) { | ||
matchNr = Number(occurence) - 1; | ||
} | ||
const position = marks[matchNr].offsetTop - headerElm.clientHeight; | ||
window.scrollTo(0, position); | ||
} | ||
}) | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters