SchemeArena / js /app.js
JieRuan's picture
SchemeArena project page: overview, results, scenario explorer
0d2d822 verified
Raw History Blame Contribute Delete
2.17 kB
(function () {
"use strict";
var TABS = ["overview", "results", "explorer"];
function activate(tab, sub) {
if (TABS.indexOf(tab) === -1) tab = "overview";
document.querySelectorAll(".tab-btn").forEach(function (b) { b.classList.toggle("active", b.dataset.tab === tab); });
document.querySelectorAll(".tab-panel").forEach(function (p) { p.classList.toggle("active", p.id === "tab-" + tab); });
if (tab === "results") window.renderResults();
if (tab === "explorer") window.openExplorer(sub);
}
function fromHash() {
var h = (location.hash || "#overview").slice(1).split("/");
activate(h[0], h[1]);
}
document.querySelectorAll(".tab-btn").forEach(function (b) {
b.addEventListener("click", function () {
history.pushState(null, "", "#" + b.dataset.tab);
activate(b.dataset.tab);
window.scrollTo({ top: 0 });
});
});
window.addEventListener("hashchange", function () { fromHash(); window.scrollTo({ top: 0 }); });
// BibTeX modal + copy buttons
var modal = document.getElementById("bibtexModal");
document.getElementById("bibtexModalCode").textContent = document.getElementById("bibtex").textContent;
document.querySelectorAll("[data-open-bibtex]").forEach(function (b) { b.addEventListener("click", function () { modal.classList.add("open"); }); });
document.querySelectorAll("[data-close-bibtex]").forEach(function (b) { b.addEventListener("click", function () { modal.classList.remove("open"); }); });
modal.addEventListener("click", function (e) { if (e.target === modal) modal.classList.remove("open"); });
document.addEventListener("keydown", function (e) { if (e.key === "Escape") modal.classList.remove("open"); });
document.querySelectorAll("[data-copy]").forEach(function (b) {
b.addEventListener("click", function () {
var text = document.getElementById(b.dataset.copy).textContent;
var done = function () { b.textContent = "Copied!"; setTimeout(function () { b.textContent = "Copy"; }, 1600); };
if (navigator.clipboard) navigator.clipboard.writeText(text).then(done, function () {});
});
});
window.renderSetupTable();
fromHash();
})();