Simplify src-script.js
code
This commit is contained in:
parent
fc7221689e
commit
552143c875
@ -131,12 +131,8 @@ function createSrcSidebar() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const lineNumbersRegex = /^#?(\d+)(?:-(\d+))?$/;
|
function highlightSrcLines() {
|
||||||
|
const match = window.location.hash.match(/^#?(\d+)(?:-(\d+))?$/);
|
||||||
function highlightSrcLines(match) {
|
|
||||||
if (typeof match === "undefined") {
|
|
||||||
match = window.location.hash.match(lineNumbersRegex);
|
|
||||||
}
|
|
||||||
if (!match) {
|
if (!match) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -218,12 +214,7 @@ const handleSrcHighlight = (function() {
|
|||||||
};
|
};
|
||||||
}());
|
}());
|
||||||
|
|
||||||
window.addEventListener("hashchange", () => {
|
window.addEventListener("hashchange", highlightSrcLines);
|
||||||
const match = window.location.hash.match(lineNumbersRegex);
|
|
||||||
if (match) {
|
|
||||||
return highlightSrcLines(match);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
onEachLazy(document.getElementsByClassName("src-line-numbers"), el => {
|
onEachLazy(document.getElementsByClassName("src-line-numbers"), el => {
|
||||||
el.addEventListener("click", handleSrcHighlight);
|
el.addEventListener("click", handleSrcHighlight);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user