add tabs for rotators
This commit is contained in:
+101
-4
@@ -16,6 +16,29 @@
|
|||||||
margin: 0;
|
margin: 0;
|
||||||
padding: 0;
|
padding: 0;
|
||||||
}
|
}
|
||||||
|
.tab-bar {
|
||||||
|
display: flex;
|
||||||
|
align-items: center;
|
||||||
|
background: #111;
|
||||||
|
border-bottom: 1px solid #333;
|
||||||
|
padding: 0 8px;
|
||||||
|
gap: 0;
|
||||||
|
user-select: none;
|
||||||
|
}
|
||||||
|
.tab {
|
||||||
|
padding: 10px 18px;
|
||||||
|
font-size: 15px;
|
||||||
|
color: #888;
|
||||||
|
cursor: pointer;
|
||||||
|
border-bottom: 2px solid transparent;
|
||||||
|
white-space: nowrap;
|
||||||
|
}
|
||||||
|
.tab:hover { color: #ccc; }
|
||||||
|
.tab.active {
|
||||||
|
color: #fff;
|
||||||
|
border-bottom-color: #4a9eff;
|
||||||
|
}
|
||||||
|
.tab-spacer { flex: 1; }
|
||||||
.rotators {
|
.rotators {
|
||||||
display: flex;
|
display: flex;
|
||||||
flex-wrap: wrap;
|
flex-wrap: wrap;
|
||||||
@@ -24,10 +47,13 @@
|
|||||||
padding: 20px;
|
padding: 20px;
|
||||||
}
|
}
|
||||||
.rotator-card {
|
.rotator-card {
|
||||||
display: flex;
|
display: none;
|
||||||
flex-direction: column;
|
flex-direction: column;
|
||||||
align-items: center;
|
align-items: center;
|
||||||
}
|
}
|
||||||
|
.rotator-card.visible {
|
||||||
|
display: flex;
|
||||||
|
}
|
||||||
canvas {
|
canvas {
|
||||||
display: block;
|
display: block;
|
||||||
cursor: crosshair;
|
cursor: crosshair;
|
||||||
@@ -75,6 +101,7 @@
|
|||||||
</head>
|
</head>
|
||||||
<body>
|
<body>
|
||||||
|
|
||||||
|
<div class="tab-bar" id="tab-bar"></div>
|
||||||
<div class="rotators" id="rotators"></div>
|
<div class="rotators" id="rotators"></div>
|
||||||
|
|
||||||
<script>
|
<script>
|
||||||
@@ -351,8 +378,9 @@
|
|||||||
this.state = state;
|
this.state = state;
|
||||||
this.label = label;
|
this.label = label;
|
||||||
|
|
||||||
const card = document.createElement('div');
|
this.card = document.createElement('div');
|
||||||
card.className = 'rotator-card';
|
this.card.className = 'rotator-card';
|
||||||
|
const card = this.card;
|
||||||
|
|
||||||
this.nameEl = document.createElement('p');
|
this.nameEl = document.createElement('p');
|
||||||
this.nameEl.className = 'rotator-label';
|
this.nameEl.className = 'rotator-label';
|
||||||
@@ -443,8 +471,12 @@
|
|||||||
class RotatorApp {
|
class RotatorApp {
|
||||||
constructor() {
|
constructor() {
|
||||||
this.rotators = {};
|
this.rotators = {};
|
||||||
|
this.labels = [];
|
||||||
this.container = document.getElementById('rotators');
|
this.container = document.getElementById('rotators');
|
||||||
|
this.tabBar = document.getElementById('tab-bar');
|
||||||
this.websocket = null;
|
this.websocket = null;
|
||||||
|
this.tiled = false;
|
||||||
|
this.activeTab = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
async initialize() {
|
async initialize() {
|
||||||
@@ -469,17 +501,82 @@
|
|||||||
}
|
}
|
||||||
|
|
||||||
this.rotators[label] = { state, ui };
|
this.rotators[label] = { state, ui };
|
||||||
|
this.labels.push(label);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
this.buildTabBar();
|
||||||
|
this.applyHash();
|
||||||
|
window.addEventListener('hashchange', () => this.applyHash());
|
||||||
|
|
||||||
document.title = Object.values(this.rotators)
|
document.title = Object.values(this.rotators)
|
||||||
.map(r => r.state.antName || "Rotator")
|
.map(r => r.state.antName || "Rotator")
|
||||||
.join(" / ");
|
.join(" / ");
|
||||||
|
}
|
||||||
|
|
||||||
|
buildTabBar() {
|
||||||
|
for (const label of this.labels) {
|
||||||
|
const tab = document.createElement('div');
|
||||||
|
tab.className = 'tab';
|
||||||
|
tab.textContent = this.rotators[label].state.antName || label;
|
||||||
|
tab.addEventListener('click', () => {
|
||||||
|
location.hash = encodeURIComponent(label);
|
||||||
|
});
|
||||||
|
this.rotators[label].tab = tab;
|
||||||
|
this.tabBar.appendChild(tab);
|
||||||
|
}
|
||||||
|
|
||||||
|
this.allTab = document.createElement('div');
|
||||||
|
this.allTab.className = 'tab';
|
||||||
|
this.allTab.textContent = 'All';
|
||||||
|
this.allTab.addEventListener('click', () => {
|
||||||
|
location.hash = 'all';
|
||||||
|
});
|
||||||
|
this.tabBar.appendChild(this.allTab);
|
||||||
|
}
|
||||||
|
|
||||||
|
applyHash() {
|
||||||
|
const hash = decodeURIComponent(location.hash.slice(1));
|
||||||
|
|
||||||
|
if (hash === 'all' || (hash === '' && this.labels.length <= 1)) {
|
||||||
|
this.tiled = true;
|
||||||
|
this.showAll();
|
||||||
|
} else if (this.rotators[hash]) {
|
||||||
|
this.tiled = false;
|
||||||
|
this.showTab(hash);
|
||||||
|
} else {
|
||||||
|
// default: first tab, or all if single rotator
|
||||||
|
this.tiled = false;
|
||||||
|
this.showTab(this.labels[0]);
|
||||||
|
}
|
||||||
|
|
||||||
|
this.allTab.classList.toggle('active', this.tiled);
|
||||||
|
}
|
||||||
|
|
||||||
|
showTab(label) {
|
||||||
|
this.activeTab = label;
|
||||||
|
for (const l of this.labels) {
|
||||||
|
const rot = this.rotators[l];
|
||||||
|
const visible = l === label;
|
||||||
|
rot.ui.card.classList.toggle('visible', visible);
|
||||||
|
rot.tab.classList.toggle('active', visible);
|
||||||
|
}
|
||||||
|
// re-render visible one (canvas may have been hidden)
|
||||||
|
this.rotators[label].ui.renderer.render();
|
||||||
|
}
|
||||||
|
|
||||||
|
showAll() {
|
||||||
|
this.activeTab = null;
|
||||||
|
for (const l of this.labels) {
|
||||||
|
const rot = this.rotators[l];
|
||||||
|
rot.ui.card.classList.add('visible');
|
||||||
|
rot.tab.classList.remove('active');
|
||||||
|
rot.ui.renderer.render();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
async startWs() {
|
async startWs() {
|
||||||
return new Promise((resolve) => {
|
return new Promise((resolve) => {
|
||||||
this.websocket = new WebSocket(document.location.href.replace(/\/?$/, '/') + "ws");
|
this.websocket = new WebSocket(location.origin.replace(/^http/, 'ws') + location.pathname.replace(/\/?$/, '/') + 'ws');
|
||||||
let resolved = false;
|
let resolved = false;
|
||||||
|
|
||||||
this.websocket.addEventListener("message", (e) => {
|
this.websocket.addEventListener("message", (e) => {
|
||||||
|
|||||||
Reference in New Issue
Block a user