[PATCH v2] cgit.js: line range highlight: always hook hashchange in case hash added
Andy Green
andy at warmcat.com
Sat Jun 23 09:45:06 CEST 2018
Since the user might add a # to a URL that didn't initially have one,
eg by clicking the line numbers, always register the hashchange listener.
Signed-off-by: Andy Green <andy at warmcat.com>
---
cgit.js | 4 ----
ui-shared.c | 5 ++++-
2 files changed, 4 insertions(+), 5 deletions(-)
diff --git a/cgit.js b/cgit.js
index d905634..a3ddf81 100644
--- a/cgit.js
+++ b/cgit.js
@@ -61,10 +61,6 @@ function cgit_line_range_highlight(depth)
e1.style.backgroundColor = "yellow";
}
- window.addEventListener("hashchange", function() {
- cgit_line_range_highlight(cgit_line_range_depth);
- }, false);
-
hl = (window.innerHeight / (e.offsetHeight + 1));
v = (l1 + ((l2 - l1) / 2)) - (hl / 2);
if (v > l1)
diff --git a/ui-shared.c b/ui-shared.c
index 7fd6bad..3417919 100644
--- a/ui-shared.c
+++ b/ui-shared.c
@@ -1245,9 +1245,12 @@ void cgit_set_title_from_path(const char *path)
void cgit_emit_line_range_highlight_script(int parent_level)
{
htmlf("<script>\n"
- "document.addEventListener(\"DOMContentLoaded\", function() {"
+ "document.addEventListener(\"DOMContentLoaded\", function() {\n"
" cgit_line_range_highlight(%d);\n"
"}, false);\n"
+ "window.addEventListener(\"hashchange\", function() {\n"
+ " cgit_line_range_highlight(%d);\n"
+ "}, false);\n"
"</script>\n", parent_level);
}
More information about the CGit
mailing list