// 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"; } }); })();