Files
Kronic-Krusaders/kronic-chat/js/borg_shell.js
T

40 lines
2.3 KiB
JavaScript

/* Borg stage 2: navigation shell only. Does not modify legacy Media app.js. */
(() => {
const wrap=document.getElementById('borgWindowWrap');
const header=document.getElementById('borgWindowHeader');
const title=document.getElementById('borgWindowTitle');
if(!wrap || !header)return;
let pos=null;
const open=(name='Media Library')=>{wrap.hidden=false;title.textContent=name;};
const close=()=>{wrap.hidden=true;};
document.querySelectorAll('[data-borg]').forEach(btn=>btn.addEventListener('click',()=>{
document.querySelectorAll('[data-borg]').forEach(b=>b.classList.toggle('borg-selected',b===btn));
const kind=btn.dataset.borg;
if(kind==='room'){close();return;}
const labels={libraries:'Libraries',movies:'Movies',shows:'TV Shows',music:'Music',iptv:'IPTV',youtube:'Tube',twitch:'Twitch',settings:'Manage Libraries'};
open(labels[kind]||'Media Library');
// Trigger existing application actions when they can be identified safely.
if(kind==='libraries'){document.getElementById('librariesButton')?.click();}
if(kind==='settings'){document.getElementById('manageButton')?.click();}
// Other tabs intentionally show the current Media view until mapped to real app.js navigation.
}));
document.getElementById('borgClose')?.addEventListener('click',close);
document.getElementById('borgMinimize')?.addEventListener('click',close);
document.getElementById('borgMaximize')?.addEventListener('click',()=>wrap.classList.toggle('borg-max'));
header.addEventListener('pointerdown',e=>{
if(e.target.closest('button') || wrap.classList.contains('borg-max') || matchMedia('(max-width:700px)').matches)return;
pos={x:e.clientX,y:e.clientY,left:wrap.offsetLeft,top:wrap.offsetTop};
header.setPointerCapture(e.pointerId);
});
header.addEventListener('pointermove',e=>{
if(!pos)return;
const l=Math.max(0,Math.min(window.innerWidth-90,pos.left+e.clientX-pos.x));
const t=Math.max(0,Math.min(window.innerHeight-90,pos.top+e.clientY-pos.y));
wrap.style.left=l+'px';wrap.style.top=t+'px';
});
const stop=()=>{pos=null;};header.addEventListener('pointerup',stop);header.addEventListener('pointercancel',stop);
document.getElementById('homeButton')?.addEventListener('click',()=>open('Libraries'));
// Initial welcome room; Media contents are already mounted and retain their state.
close();
})();