Rollup merge of #118977 - GuillaumeGomez:simplifysrc-script, r=notriddle
Simplify `src-script.js` code Instead of keeping this value in the global scope and still use it in the function in case it wasn't used outside, let's just use it inside the function. r? ``@notriddle``
This commit is contained in:
commit
ae9e08e65e
1 changed files with 3 additions and 12 deletions
|
@ -146,12 +146,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;
|
||||||
}
|
}
|
||||||
|
@ -233,12 +229,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…
Add table
Add a link
Reference in a new issue