Skip to content

Commit 20f83af

Browse files
authored
Merge pull request #4003 from vespa-engine/vadim/rank-features-ref-list-scroll-fix
Rank Feature Reference: add scroll to an anchor after the list has been generated
2 parents fa1eb6a + 23e0fb1 commit 20f83af

File tree

1 file changed

+37
-20
lines changed

1 file changed

+37
-20
lines changed

js/table-list-converter.js

Lines changed: 37 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,18 @@
11
/* Table to list converter wit JQuery */
2+
3+
function scrollToAnchor(hash) {
4+
if (hash) {
5+
setTimeout(() => {
6+
const $target = $(hash);
7+
if ($target.length) {
8+
$('html, body').scrollTop($target.offset().top);
9+
}
10+
}, 0);
11+
}
12+
}
13+
214
$(window).on('load', function() {
15+
const anchor = window.location.hash;
316
let $table = $('#rank-feature-table');
417
let $list = $('<ul id="feature-list"></ul>');
518

@@ -39,33 +52,36 @@ $(window).on('load', function() {
3952
});
4053

4154
$table.replaceWith($list);
55+
scrollToAnchor(anchor);
4256
});
4357

4458
/* Natve Ranking Tables */
4559
$(window).on('load', function() {
46-
let $table = $('#nativerank-variables-table');
47-
let $list = $('<ul id="variable-list"></ul>');
48-
49-
$table.find('tbody tr').each(function() {
50-
let $row = $(this);
51-
let $tds = $row.find('td');
52-
53-
if ($tds.length >= 2) {
54-
let variable = $tds.eq(0).html().trim(); // Keep HTML (e.g., <em>, <sub>)
55-
let description = $tds.eq(1).html().trim(); // Keep inner HTML
56-
57-
let $li = $('<li style="margin-bottom: 1em;"></li>');
58-
$li.append('<strong>' + variable + '</strong>');
59-
$li.append('<div>' + description + '</div>');
60-
61-
$list.append($li);
62-
}
63-
});
64-
65-
$table.replaceWith($list);
60+
const anchor = window.location.hash;
61+
let $table = $('#nativerank-variables-table');
62+
let $list = $('<ul id="variable-list"></ul>');
63+
64+
$table.find('tbody tr').each(function() {
65+
let $row = $(this);
66+
let $tds = $row.find('td');
67+
68+
if ($tds.length >= 2) {
69+
let variable = $tds.eq(0).html().trim(); // Keep HTML (e.g., <em>, <sub>)
70+
let description = $tds.eq(1).html().trim(); // Keep inner HTML
71+
72+
let $li = $('<li style="margin-bottom: 1em;"></li>');
73+
$li.append('<strong>' + variable + '</strong>');
74+
$li.append('<div>' + description + '</div>');
75+
76+
$list.append($li);
77+
}
78+
});
79+
$table.replaceWith($list);
80+
scrollToAnchor(anchor);
6681
});
6782

6883
$(window).on('load', function() {
84+
const anchor = window.location.hash;
6985
let $table = $('#native-rank-parameters-table');
7086
let $list = $('<ul id="native-rank-parameters-list"></ul>');
7187

@@ -98,5 +114,6 @@ $(window).on('load', function() {
98114
});
99115

100116
$table.replaceWith($list);
117+
scrollToAnchor(anchor);
101118
});
102119

0 commit comments

Comments
 (0)