Files
website/js/tabs.js
T
esefandClaude Opus 5.5 59d226f283 Replace Bot Status tab with the VEGA status page
The Status tab embeds status.userevolt.app (VEGA) in an iframe that loads
on first open, with a VEGA-coloured top bar. Old /yuukabot links go to
/status. Removes the Firebase bot dashboard (yuukabot.js/css).

Co-Authored-By: Claude Opus 5.5 <[email protected]>
2026-10-10 15:20:26 +03:00

126 lines
3.9 KiB
JavaScript

document.addEventListener('DOMContentLoaded', () => {
const tabs = document.querySelectorAll('.tab-content');
const mainVideo = document.getElementById('background-video');
const calVideo = document.getElementById('calendar-background-video');
const bucketlistVideo = document.getElementById('bucketlist-background-video');
const botVideo = document.getElementById('yuukabot-background-video');
function pathToTab(path) {
const slug = path.replace(/^\/+|\/+$/g, '') || 'about';
const valid = ['about', 'gallery', 'bucketlist', 'status', 'calendar', 'services'];
// old links
if (slug === 'ahmet') return 'bucketlist';
if (slug === 'yuukabot') return 'status';
return valid.includes(slug) ? slug : 'about';
}
function tabToPath(tabId) {
return '/' + (tabId === 'about' ? '' : tabId);
}
const topLine = document.getElementById('top-line');
// tabs not listed here use the main video
const tabVideos = {
calendar: calVideo,
bucketlist: bucketlistVideo,
status: botVideo,
services: botVideo
};
function setBgForTab(tabId) {
[mainVideo, calVideo, bucketlistVideo, botVideo].forEach(v => {
if (v) { v.style.display = 'none'; v.pause(); }
});
const target = tabVideos[tabId];
if (target) {
target.style.display = 'block';
target.play().catch(() => {});
} else if (mainVideo) {
mainVideo.style.display = 'block';
if (mainVideo.paused) mainVideo.play().catch(() => {});
}
if (topLine) {
topLine.classList.toggle('cal-theme', tabId === 'calendar');
topLine.classList.toggle('bucketlist-theme', tabId === 'bucketlist');
topLine.classList.toggle('status-theme', tabId === 'status');
}
}
const navCurrent = document.getElementById('nav-current');
function showTab(tabId) {
tabs.forEach(t => t.style.display = 'none');
const target = document.getElementById(tabId);
if (target) target.style.display = 'block';
setBgForTab(tabId);
// VEGA polls every 2s, so only load it once someone opens the tab
const statusFrame = document.getElementById('status-frame');
if (tabId === 'status' && statusFrame && !statusFrame.src) {
statusFrame.src = 'https://status.userevolt.app/';
}
// tab name next to the hamburger on mobile
const btn = document.getElementById(tabId + '-btn');
if (navCurrent && btn) navCurrent.textContent = btn.textContent;
}
// changing the url breaks every button when index.html is opened as a file
function setUrl(method, tabId) {
if (window.location.protocol === 'file:') return;
history[method]({ tab: tabId }, '', tabToPath(tabId) + window.location.search);
}
function navigateTo(tabId) {
showTab(tabId);
window.scrollTo(0, 0);
setUrl('pushState', tabId);
}
const initialTab = pathToTab(window.location.pathname);
showTab(initialTab);
setUrl('replaceState', initialTab);
const buttons = document.querySelectorAll('#nav-tabs button');
buttons.forEach(button => {
button.addEventListener('click', () => {
const targetId = button.id.replace('-btn', '');
navigateTo(targetId);
closeMenu();
});
});
// hamburger menu (mobile)
const hamburger = document.getElementById('nav-hamburger');
function openMenu() {
topLine.classList.add('nav-open');
hamburger.setAttribute('aria-expanded', 'true');
}
function closeMenu() {
topLine.classList.remove('nav-open');
hamburger.setAttribute('aria-expanded', 'false');
}
hamburger.addEventListener('click', () => {
topLine.classList.contains('nav-open') ? closeMenu() : openMenu();
});
document.addEventListener('click', (e) => {
if (!topLine.contains(e.target)) closeMenu();
});
document.addEventListener('keydown', (e) => {
if (e.key === 'Escape') closeMenu();
});
// back/forward buttons
window.addEventListener('popstate', (e) => {
showTab(e.state && e.state.tab ? e.state.tab : pathToTab(window.location.pathname));
});
});