From 552143c875d4bd037ae9bbd73440dfc77c6e6dee Mon Sep 17 00:00:00 2001 From: Guillaume Gomez Date: Fri, 15 Dec 2023 12:26:09 +0100 Subject: Simplify `src-script.js` code --- src/librustdoc/html/static/js/src-script.js | 15 +++------------ 1 file changed, 3 insertions(+), 12 deletions(-) (limited to 'src') diff --git a/src/librustdoc/html/static/js/src-script.js b/src/librustdoc/html/static/js/src-script.js index 27b5cf1e2ae..8b7a9161d71 100644 --- a/src/librustdoc/html/static/js/src-script.js +++ b/src/librustdoc/html/static/js/src-script.js @@ -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); -- cgit 1.4.1-3-g733a5 From 028a3135c82cc72b38a7be44a86da2563959044e Mon Sep 17 00:00:00 2001 From: Guillaume Gomez Date: Fri, 15 Dec 2023 16:56:11 +0100 Subject: Simplify JS code a little bit --- src/librustdoc/html/render/write_shared.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'src') diff --git a/src/librustdoc/html/render/write_shared.rs b/src/librustdoc/html/render/write_shared.rs index c4a6e920031..6408e97df50 100644 --- a/src/librustdoc/html/render/write_shared.rs +++ b/src/librustdoc/html/render/write_shared.rs @@ -328,8 +328,8 @@ pub(super) fn write_shared( v.push_str( r#"\ ]')); -if (typeof window !== 'undefined' && window.initSearch) {window.initSearch(searchIndex)}; -if (typeof exports !== 'undefined') {exports.searchIndex = searchIndex}; +if (typeof exports !== 'undefined') exports.searchIndex = searchIndex; +else if (window.initSearch) window.initSearch(searchIndex); "#, ); Ok(v.into_bytes()) -- cgit 1.4.1-3-g733a5