Simplify src-script.js code

This commit is contained in:
Guillaume Gomez 2023-12-15 12:26:09 +01:00
parent fc7221689e
commit 552143c875

View File

@ -131,12 +131,8 @@ function createSrcSidebar() {
}
}
const lineNumbersRegex = /^#?(\d+)(?:-(\d+))?$/;
function highlightSrcLines(match) {
if (typeof match === "undefined") {
match = window.location.hash.match(lineNumbersRegex);
}
function highlightSrcLines() {
const match = window.location.hash.match(/^#?(\d+)(?:-(\d+))?$/);
if (!match) {
return;
}
@ -218,12 +214,7 @@ const handleSrcHighlight = (function() {
};
}());
window.addEventListener("hashchange", () => {
const match = window.location.hash.match(lineNumbersRegex);
if (match) {
return highlightSrcLines(match);
}
});
window.addEventListener("hashchange", highlightSrcLines);
onEachLazy(document.getElementsByClassName("src-line-numbers"), el => {
el.addEventListener("click", handleSrcHighlight);