Skip to content

Commit 6476d5d

Browse files
committed
fix scrolling to element on current page
1 parent a96b989 commit 6476d5d

File tree

1 file changed

+13
-7
lines changed

1 file changed

+13
-7
lines changed

src/ocamlorg_frontend/layouts/package_layout.eml

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -173,6 +173,8 @@ Layout.render
173173
a.appendChild(title);
174174
a.appendChild(comment);
175175

176+
a.addEventListener("click", () => scrollTo(a.href));
177+
176178
list_item.appendChild(a);
177179

178180
search_results.appendChild(list_item);
@@ -242,13 +244,7 @@ Layout.render
242244
console.log("going to", url);
243245
window.location = url;
244246

245-
if (url.indexOf("#") != -1) {
246-
let id = url.split("#")[1]
247-
let el = document.getElementById(id);
248-
console.log("id el", id, el);
249-
if (el) setTimeout(() => {
250-
console.log("scroll"); el.scrollIntoView();}, 10);
251-
}
247+
scrollTo(url);
252248

253249
document.getElementById("in-package-search-input").value = "";
254250
results = [];
@@ -266,6 +262,16 @@ Layout.render
266262
}
267263
}
268264

265+
function scrollTo(url) {
266+
if (url.indexOf("#") != -1) {
267+
let id = url.split("#")[1]
268+
let el = document.getElementById(id);
269+
console.log("id el", id, el);
270+
if (el) setTimeout(() => {
271+
console.log("scroll"); el.scrollIntoView();}, 10);
272+
}
273+
}
274+
269275
document.getElementById("in-package-search-input").addEventListener("keydown", keydown);
270276
}
271277
</script>

0 commit comments

Comments
 (0)