"use strict";
// Concept shell: mobile sidebar, theme toggle, active menu item, result summary tiles.
(() => {
const $ = (s) => document.querySelector(s);
const root = document.documentElement;
// Theme toggle
const toggle = $("#theme-toggle");
const syncToggle = () => {
const dark = root.getAttribute("data-bs-theme") === "dark";
toggle?.setAttribute("aria-label", dark ? "Açık temaya geç" : "Koyu temaya geç");
toggle?.setAttribute("title", dark ? "Açık tema" : "Koyu tema");
};
toggle?.addEventListener("click", () => {
const next = root.getAttribute("data-bs-theme") === "dark" ? "light" : "dark";
root.setAttribute("data-bs-theme", next);
try { localStorage.setItem("kap-theme", next); } catch { /* yoksay */ }
syncToggle();
});
syncToggle();
// Signed in user: header menu; guests get a sign in card instead of the upload card
const esc = (v) => String(v ?? "").replace(/[&<>"']/g, (c) => ({ "&": "&", "<": "<", ">": ">", '"': """, "'": "'" }[c]));
const area = $("#user-area");
if (area) {
fetch("/api/auth/me").then((r) => r.json()).then(({ user }) => {
const work = $("#work-row"), cta = $("#members-cta");
if (work) work.hidden = !user;
if (cta) cta.hidden = !!user;
if (!user) {
area.classList.remove("dropdown");
area.innerHTML = `<a class="btn btn-primary btn-sm text-nowrap" href="/giris?next=${encodeURIComponent(location.pathname + location.hash)}" aria-label="Giriş yap"><i class="fas fa-right-to-bracket" aria-hidden="true"></i><span class="d-none d-sm-inline ms-1">Giriş yap</span></a>`;
return;
}
area.innerHTML = `
<button type="button" class="user-chip dropdown-toggle" data-bs-toggle="dropdown" aria-expanded="false">
<span class="avatar" aria-hidden="true">${esc(user.username.slice(0, 1))}</span><span class="d-none d-sm-inline">${esc(user.username)}</span>
</button>
<ul class="dropdown-menu dropdown-menu-end">
<li><span class="dropdown-item-text small muted">Giriş yapan: <b>${esc(user.username)}</b></span></li>
<li><hr class="dropdown-divider"></li>
<li><button type="button" class="dropdown-item text-danger" id="logout-btn"><i class="fas fa-right-from-bracket me-2" aria-hidden="true"></i>Çıkış yap</button></li>
</ul>`;
$("#logout-btn").addEventListener("click", async () => {
await fetch("/api/auth/logout", { method: "POST" });
location.href = "/";
});
}).catch(() => { const w = $("#work-row"); if (w) w.hidden = false; /* sunucu yine de yetkiyi kontrol eder */ });
}
// Mobile sidebar
const sidebar = $(".nav-left-sidebar");
const burger = $(".sidebar-toggler");
const overlay = document.createElement("div");
overlay.className = "sidebar-overlay";
document.body.appendChild(overlay);
const setOpen = (open) => {
sidebar?.classList.toggle("active", open);
overlay.classList.toggle("active", open);
document.body.classList.toggle("sidebar-open", open);
burger?.setAttribute("aria-expanded", String(open));
};
burger?.addEventListener("click", (e) => { e.preventDefault(); setOpen(!sidebar.classList.contains("active")); });
overlay.addEventListener("click", () => setOpen(false));
sidebar?.addEventListener("click", (e) => { if (e.target.closest("a")) setOpen(false); });
document.addEventListener("keydown", (e) => { if (e.key === "Escape") setOpen(false); });
// Highlight the menu item whose section is in view (analysis page only)
const links = [...document.querySelectorAll(".nav-left-sidebar a[data-section]")];
const sections = links.map((a) => document.getElementById(a.dataset.section)).filter(Boolean);
if (sections.length) {
const io = new IntersectionObserver((entries) => {
entries.forEach((en) => {
if (!en.isIntersecting) return;
links.forEach((a) => a.classList.toggle("active", a.dataset.section === en.target.id));
});
}, { rootMargin: "-40% 0px -55% 0px" });
sections.forEach((s) => io.observe(s));
}
// Result menu item and summary tiles follow what app.js renders
const result = $("#result");
if (result) {
const resultLink = $('.nav-left-sidebar a[data-section="result"]');
const tiles = {
company: $("#t-company"), years: $("#t-years"), sector: $("#t-sector"), mult: $("#t-mult"),
};
const sync = () => {
const shown = !result.hidden;
resultLink?.classList.toggle("disabled", !shown);
resultLink?.setAttribute("aria-disabled", String(!shown));
$("#crumb-result").hidden = !shown;
$("#result-tiles").hidden = !shown;
if (!shown) return;
tiles.company.textContent = $("#r-company").textContent || "–";
tiles.years.textContent = $("#r-years").textContent || "–";
const sel = $("#sector");
tiles.sector.textContent = sel?.selectedOptions[0]?.textContent?.split("—")[0].trim() || "Seçilmedi";
const auto = $('#m-mode button[data-mode="auto"]')?.getAttribute("aria-pressed") === "true";
tiles.mult.textContent = auto ? "Enflasyon endeksi" : "Elle";
};
new MutationObserver(sync).observe(result, { attributes: true, attributeFilter: ["hidden"], childList: true, subtree: true, characterData: true });
$("#sector")?.addEventListener("change", sync);
sync();
}
})();
Tüm kodlar
KAP Finansal Analiz
Şirketlerin finansal tablolarını yıllar arası analiz eden web uygulaması
Lisans bilgisi projenin LICENSE dosyasında.