(function () { function branchMatch(el, name) { if (!name) return false; var raw = el.getAttribute("data-branch") || ""; return raw.split(/\s+/).indexOf(name) !== -1; } function applyCommitGraph() { var slot = document.querySelector(".commitgraph-slot"); var graph = slot && slot.querySelector(".commitgraph"); if (!graph) return; var sel = document.querySelector("select[data-rev]"); var name = sel ? sel.value : (graph.getAttribute("data-selected") || ""); graph.setAttribute("data-selected", name); graph.querySelectorAll("[data-branch]").forEach(function (el) { el.classList.toggle("is-glow", branchMatch(el, name)); }); } // De grafiek staat nĂ¡ , terwijl repo.js in de kolom wordt // geladen. Pas binden als de hele pagina er is, anders ontbreekt de gloed. function startCommitGraph() { applyCommitGraph(); if (window.__bgGraphBound) return; window.__bgGraphBound = true; window.addEventListener("resize", applyCommitGraph); document.querySelectorAll("select[data-rev]").forEach(function (sel) { sel.addEventListener("change", function () { applyCommitGraph(); var url = new URL(window.location.href); url.searchParams.set("rev", sel.value); url.searchParams.delete("page"); window.location = url.toString(); }); }); } if (document.readyState === "loading") { document.addEventListener("DOMContentLoaded", startCommitGraph); } else { startCommitGraph(); } var filter = document.querySelector("[data-tree-filter]"); var list = document.querySelector(".treelist"); if (list) { var repo = list.getAttribute("data-repo") || ""; var key = "bluegit.tree." + repo; var saved = {}; try { var raw = JSON.parse(localStorage.getItem(key) || "{}"); if (raw && typeof raw === "object") { saved = raw; } } catch (e) { saved = {}; } function parentOf(path) { var i = path.lastIndexOf("/"); return i < 0 ? "" : path.slice(0, i); } var force = {}; var active = null; list.querySelectorAll("li.active").forEach(function (li) { var path = li.getAttribute("data-path") || ""; if (!active || path.length > (active.getAttribute("data-path") || "").length) { active = li; } }); if (active) { var activePath = active.getAttribute("data-path") || ""; if (active.getAttribute("data-dir") === "1") { force[activePath] = true; } var anc = parentOf(activePath); while (anc) { force[anc] = true; anc = parentOf(anc); } } function isOpen(path, li) { if (force[path]) { return true; } if (Object.prototype.hasOwnProperty.call(saved, path)) { return !!saved[path]; } return li.classList.contains("open"); } function paint() { var items = list.querySelectorAll("li"); var byPath = {}; var paths = []; items.forEach(function (li) { var path = li.getAttribute("data-path") || ""; byPath[path] = li; paths.push(path.toLowerCase()); if (li.getAttribute("data-dir") === "1") { var open = isOpen(path, li); li.classList.toggle("open", open); var btn = li.querySelector("button.twist"); if (btn) { btn.setAttribute("aria-expanded", open ? "true" : "false"); } } }); var q = filter ? filter.value.trim().toLowerCase() : ""; items.forEach(function (li, i) { var path = li.getAttribute("data-path") || ""; var low = paths[i]; if (q !== "") { if (low.indexOf(q) !== -1) { li.hidden = false; return; } var prefix = low + "/"; var child = false; for (var j = 0; j < paths.length; j++) { if (paths[j].indexOf(prefix) === 0 && paths[j].indexOf(q) !== -1) { child = true; break; } } li.hidden = !child; return; } var hidden = false; var up = parentOf(path); while (up) { var node = byPath[up]; if (node && node.getAttribute("data-dir") === "1" && !node.classList.contains("open")) { hidden = true; break; } up = parentOf(up); } li.hidden = hidden; }); } function remember(path, open) { delete force[path]; saved[path] = open; try { localStorage.setItem(key, JSON.stringify(saved)); } catch (e) {} paint(); } list.addEventListener("click", function (ev) { var li = ev.target.closest("li"); if (!li || !list.contains(li) || li.getAttribute("data-dir") !== "1") { return; } var link = ev.target.closest("a"); if (link && li.contains(link) && (ev.metaKey || ev.ctrlKey || ev.shiftKey || ev.altKey)) { return; } ev.preventDefault(); var path = li.getAttribute("data-path") || ""; remember(path, !li.classList.contains("open")); }); if (filter) { filter.addEventListener("input", paint); if (new URLSearchParams(window.location.search).get("focus") === "1") { filter.focus(); } } paint(); var shown = null; list.querySelectorAll("li.active").forEach(function (li) { if (li.hidden) { return; } if (!shown || (li.getAttribute("data-path") || "").length > (shown.getAttribute("data-path") || "").length) { shown = li; } }); if (shown) { var top = shown.offsetTop; var bottom = top + shown.offsetHeight; if (top < list.scrollTop) { list.scrollTop = top; } else if (bottom > list.scrollTop + list.clientHeight) { list.scrollTop = bottom - list.clientHeight; } } } })(); // Bestandskaart: Copy zet de inhoud in het klembord; fouten in een eigen // modal. SVG-voorbeeld: lege/ongeldige SVG toont een lege staat. (function () { document.querySelectorAll("[data-copy-file]").forEach(function (btn) { btn.addEventListener("click", function () { if (btn.disabled) { return; } var fail = function () { var m = window.BGModal; if (m && m.alert) { m.alert(btn.getAttribute("data-copy-fail"), { title: btn.getAttribute("data-copy-title"), ok: btn.getAttribute("data-copy-close") }); } }; fetch(btn.getAttribute("data-copy-file"), { credentials: "same-origin" }).then(function (res) { if (!res.ok || res.headers.get("X-BlueGit-Binary") === "1") { throw new Error("raw"); } return res.text(); }).then(function (text) { if (!navigator.clipboard || !window.isSecureContext) { throw new Error("clipboard"); } return navigator.clipboard.writeText(text); }).then(function () { var old = btn.textContent; btn.textContent = btn.getAttribute("data-copy-ok"); setTimeout(function () { btn.textContent = old; }, 2000); }).catch(fail); }); }); document.querySelectorAll("[data-img-preview]").forEach(function (img) { var fit = function () { if (img.naturalWidth && img.naturalWidth < 128 && img.naturalHeight < 128) { img.classList.add("pixel"); img.style.width = (img.naturalWidth * Math.max(1, Math.floor(128 / img.naturalWidth))) + "px"; } }; if (img.complete) { fit(); } else { img.addEventListener("load", fit); } }); document.querySelectorAll("[data-svg-preview]").forEach(function (img) { var empty = function () { img.hidden = true; var c = img.parentNode.querySelector("[data-svg-empty]"); if (c) { c.hidden = false; } }; img.addEventListener("error", empty); }); })();