Name the element a change is in and let the diff show the lines around it

Each group of changes gets a bar with its place in the settings (like
router.firewall.rules[3], and the rule's zones) and buttons to show more
lines above and below, or all that are hidden.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-11-18 19:56:54 +01:00
co-authored by Claude Sonnet 5.5
parent f31262df31
commit eb11fc30b3
6 changed files with 375 additions and 56 deletions
+41
View File
@@ -0,0 +1,41 @@
// The bars of a diff (the Changes page) show the lines hidden next to a change:
// a bar sits above its hidden lines (.hid), which follow it up to the next line
// that is shown. "down" shows the first ones (below the change above the bar, and
// the bar moves after them), "up" the last ones (above the change below the bar).
(function () {
var STEP = 10;
function hiddenAfter(bar) {
var rows = [];
for (var el = bar.nextElementSibling; el && el.classList.contains("hid"); el = el.nextElementSibling) rows.push(el);
return rows;
}
document.addEventListener("click", function (e) {
var btn = e.target.closest ? e.target.closest("[data-more]") : null;
var bar = btn && btn.closest(".diff .gap");
if (!bar) return;
e.preventDefault();
var rows = hiddenAfter(bar);
var how = btn.getAttribute("data-more");
var shown;
if (how === "down") {
shown = rows.slice(0, STEP);
shown.forEach(function (r) { r.classList.remove("hid"); });
if (shown.length) bar.after(shown[shown.length - 1]);
} else if (how === "up") {
shown = rows.slice(-STEP);
shown.forEach(function (r) { r.classList.remove("hid"); });
} else {
rows.forEach(function (r) { r.classList.remove("hid"); });
}
var left = hiddenAfter(bar).length;
if (!left) {
// Nothing more to show: the bar stays only to say where the changes are.
bar.querySelectorAll("[data-more]").forEach(function (b) { b.remove(); });
} else {
var all = bar.querySelector('[data-more="all"]');
if (all) all.textContent = "Show " + left + " lines";
}
});
})();