Fix detail view navigation and full screen
This commit is contained in:
parent
01f06b84b2
commit
ec8f238a05
67
script.js
67
script.js
@ -44,14 +44,6 @@ let updateInterval;
|
|||||||
let lastRenderedEonstrip = null;
|
let lastRenderedEonstrip = null;
|
||||||
let currentDetailCob = null;
|
let currentDetailCob = null;
|
||||||
|
|
||||||
function fmt(d, o) {
|
|
||||||
// shift if TAI, then format
|
|
||||||
const shifted = currentTimezone==='TAI'
|
|
||||||
? new Date(d.getTime() + getTAIOffsetAt(d)*1000)
|
|
||||||
: d;
|
|
||||||
return shifted.toLocaleString('en-US', o);
|
|
||||||
}
|
|
||||||
|
|
||||||
function formatSafeDate(rawDate, cobSeconds, intlOptions) {
|
function formatSafeDate(rawDate, cobSeconds, intlOptions) {
|
||||||
if (rawDate instanceof Date && !isNaN(rawDate.getTime())) {
|
if (rawDate instanceof Date && !isNaN(rawDate.getTime())) {
|
||||||
// Date is valid: optionally shift for TAI vs UTC, then format:
|
// Date is valid: optionally shift for TAI vs UTC, then format:
|
||||||
@ -71,10 +63,6 @@ function formatSafeDate(rawDate, cobSeconds, intlOptions) {
|
|||||||
|
|
||||||
// parseCobiets, floorDiv and other CoBiE helpers are provided by cobie.js
|
// parseCobiets, floorDiv and other CoBiE helpers are provided by cobie.js
|
||||||
|
|
||||||
function getCurrentTAIOffset() {
|
|
||||||
return getTAIOffsetAt(new Date());
|
|
||||||
}
|
|
||||||
|
|
||||||
function getHumanDiff(d1, d2) {
|
function getHumanDiff(d1, d2) {
|
||||||
// make sure start ≤ end
|
// make sure start ≤ end
|
||||||
let start = d1 < d2 ? d1 : d2;
|
let start = d1 < d2 ? d1 : d2;
|
||||||
@ -713,17 +701,35 @@ function showEonstripDetail(index, startCob) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (Array.isArray(window.SPECIAL_EVENTS)) {
|
if (Array.isArray(window.SPECIAL_EVENTS)) {
|
||||||
const offsetStart = ((startCob % COBIE_UNITS.cosmocycle) + COBIE_UNITS.cosmocycle) % COBIE_UNITS.cosmocycle;
|
|
||||||
const events = [];
|
const events = [];
|
||||||
|
const start = startCob;
|
||||||
|
const end = startCob + COBIE_UNITS.eonstrip;
|
||||||
window.SPECIAL_EVENTS.forEach(ev => {
|
window.SPECIAL_EVENTS.forEach(ev => {
|
||||||
const evCob = parseCobiets(ev.cobie || ev.start);
|
const startCobEv = parseCobiets(ev.start || ev.cobie);
|
||||||
if (evCob === null) return;
|
if (startCobEv === null) return;
|
||||||
const evOffset = ((evCob % COBIE_UNITS.cosmocycle) + COBIE_UNITS.cosmocycle) % COBIE_UNITS.cosmocycle;
|
const endCobEv = ev.end ? parseCobiets(ev.end) : Number.POSITIVE_INFINITY;
|
||||||
if (evOffset >= offsetStart && evOffset < offsetStart + COBIE_UNITS.eonstrip) {
|
const unitVal = COBIE_UNITS[ev.unit] || COBIE_UNITS.cosmocycle;
|
||||||
const rel = (evOffset - offsetStart) / COBIE_UNITS.eonstrip;
|
const interval = (ev.interval || 1) * unitVal;
|
||||||
const durSec = ev.duration ? ev.duration : 0;
|
let duration = 0;
|
||||||
const dur = durSec / COBIE_UNITS.eonstrip;
|
if (typeof ev.duration === 'string') {
|
||||||
events.push({ label: ev.label, start: rel, end: rel + dur });
|
const d = parseCobiets(ev.duration);
|
||||||
|
if (d !== null) duration = d;
|
||||||
|
} else if (typeof ev.duration === 'number') {
|
||||||
|
duration = ev.duration;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (start > endCobEv) return;
|
||||||
|
|
||||||
|
let n = Math.floor((start - startCobEv) / interval);
|
||||||
|
if (n < 0) n = 0;
|
||||||
|
let occ = startCobEv + n * interval;
|
||||||
|
if (occ + duration <= start) occ += interval;
|
||||||
|
|
||||||
|
while (occ < end && occ <= endCobEv) {
|
||||||
|
const relStart = (occ - start) / COBIE_UNITS.eonstrip;
|
||||||
|
const relEnd = (occ + duration - start) / COBIE_UNITS.eonstrip;
|
||||||
|
events.push({ label: ev.label, start: relStart, end: relEnd });
|
||||||
|
occ += interval;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
events.sort((a,b)=>a.start-b.start);
|
events.sort((a,b)=>a.start-b.start);
|
||||||
@ -769,6 +775,12 @@ function detailNow() {
|
|||||||
showEonstripDetail(start);
|
showEonstripDetail(start);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function exitDetailView() {
|
||||||
|
document.getElementById('eonstripDetailView').style.display = 'none';
|
||||||
|
document.getElementById('calendarView').style.display = 'block';
|
||||||
|
currentDetailCob = null;
|
||||||
|
}
|
||||||
|
|
||||||
function getStep(mods) {
|
function getStep(mods) {
|
||||||
// base step = 1 megasequence
|
// base step = 1 megasequence
|
||||||
let step = 1;
|
let step = 1;
|
||||||
@ -796,6 +808,10 @@ function getStep(mods) {
|
|||||||
function navigatePeriod(evt, direction) {
|
function navigatePeriod(evt, direction) {
|
||||||
const step = getStep(evt);
|
const step = getStep(evt);
|
||||||
|
|
||||||
|
if (currentDetailCob !== null) {
|
||||||
|
exitDetailView();
|
||||||
|
}
|
||||||
|
|
||||||
animateSwipe(direction, () => {
|
animateSwipe(direction, () => {
|
||||||
currentOffset += direction * step;
|
currentOffset += direction * step;
|
||||||
updateCalendar();
|
updateCalendar();
|
||||||
@ -831,6 +847,9 @@ function goToNow() {
|
|||||||
manualCobiets = 0;
|
manualCobiets = 0;
|
||||||
compareManualMode = false;
|
compareManualMode = false;
|
||||||
currentOffset = 0;
|
currentOffset = 0;
|
||||||
|
if (currentDetailCob !== null) {
|
||||||
|
exitDetailView();
|
||||||
|
}
|
||||||
updateCurrentTime();
|
updateCurrentTime();
|
||||||
updateCalendar();
|
updateCalendar();
|
||||||
clearInterval(updateInterval);
|
clearInterval(updateInterval);
|
||||||
@ -924,11 +943,7 @@ if (matchingOption) {
|
|||||||
currentTimezone = userTimezone;
|
currentTimezone = userTimezone;
|
||||||
}
|
}
|
||||||
|
|
||||||
document.getElementById('backToCalendar').addEventListener('click', () => {
|
document.getElementById('backToCalendar').addEventListener('click', exitDetailView);
|
||||||
document.getElementById('eonstripDetailView').style.display = 'none';
|
|
||||||
document.getElementById('calendarView').style.display = 'block';
|
|
||||||
currentDetailCob = null;
|
|
||||||
});
|
|
||||||
document.getElementById('detailPrev').addEventListener('click', detailPrev);
|
document.getElementById('detailPrev').addEventListener('click', detailPrev);
|
||||||
document.getElementById('detailNext').addEventListener('click', detailNext);
|
document.getElementById('detailNext').addEventListener('click', detailNext);
|
||||||
document.getElementById('detailNow').addEventListener('click', detailNow);
|
document.getElementById('detailNow').addEventListener('click', detailNow);
|
||||||
|
|||||||
@ -602,6 +602,7 @@ body.fullscreen-clock .current-time,
|
|||||||
body.fullscreen-clock .timezone-selector,
|
body.fullscreen-clock .timezone-selector,
|
||||||
body.fullscreen-clock .calendar-controls,
|
body.fullscreen-clock .calendar-controls,
|
||||||
body.fullscreen-clock .calendar-view,
|
body.fullscreen-clock .calendar-view,
|
||||||
|
body.fullscreen-clock .detail-view,
|
||||||
body.fullscreen-clock .time-details,
|
body.fullscreen-clock .time-details,
|
||||||
body.fullscreen-clock .explanations {
|
body.fullscreen-clock .explanations {
|
||||||
display: none;
|
display: none;
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user