LuminaWebsite/assets/js/home-photos.js
Maaxxs b62f1213c0 Raid count in the sidebar, member screenshots on the start page, clickable dashboard tiles
- Sidebar: number of upcoming raids next to "Raids" (all not archived, same as the dashboard
  tile). Gold while a raid was posted since the last visit of the raid page (users.raids_seen_at,
  schema v46; the posting time comes from the raid id = Discord message id). New raids are
  marked "Neu" on the raid page, also in live updates; your own new raid is not. The raid ids
  are cached in settings.raids_nav_cache: every raid fetch refreshes it, otherwise the sidebar
  asks the bot after 5 minutes with a 3 s timeout and keeps the last state if it is down.
- Start page: the group photo alternates every 6 s with gallery pictures that members released
  themselves ("Auf der Startseite zeigen", member_gallery.show_on_home, schema v47) - without
  name or caption, only visible pictures of active members, with a pause button, only while
  the photo is in view. Only the member can release a picture; leadership can only take it off
  (logged).
- Dashboard: the tiles "Mitglieder" and "Berechtigungsgruppen" link to the user management and
  the roles, like "Anstehende Raids".
- Tour: new steps for gallery, calendar, gear planner and patch notes; menu customization,
  profile page, daily reward and the raid count mentioned.
- Privacy policy (activity, start page, withdrawal), account anonymization (resets
  raids_seen_at), README and patch notes updated.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-09-24 23:20:32 +02:00

140 lines
4.9 KiB
JavaScript

/**
* Startseite: Das Gemeinschaftsfoto wechselt sich alle paar Sekunden mit Galeriebildern ab, die
* Mitglieder selbst fuer die Startseite freigegeben haben (index.php, data-photos) - in zufaelliger
* Reihenfolge, nach jeder Runde wieder das Gemeinschaftsfoto. Zwei uebereinanderliegende Bilder
* blenden ineinander; das naechste laedt erst, wenn es dran ist. Gewechselt wird nur, solange das
* Foto zu sehen ist, und der Knopf oben rechts haelt den Wechsel an.
*/
(function () {
'use strict';
var INTERVAL = 6000; // Millisekunden je Bild
var figure = document.querySelector('.home-photo[data-photos]');
if (!figure) return;
var photos;
try {
photos = JSON.parse(figure.getAttribute('data-photos') || '[]');
} catch (e) {
return;
}
var first = figure.querySelector('.home-photo-slide');
if (!first || !Array.isArray(photos) || photos.length === 0) return;
var tagEl = figure.querySelector('.home-photo-tag');
var textEl = figure.querySelector('.home-photo-text');
var toggle = figure.querySelector('.home-photo-toggle');
var groupSlide = {
src: first.getAttribute('src'),
srcset: first.getAttribute('srcset') || '',
alt: first.getAttribute('alt') || '',
tag: tagEl ? tagEl.textContent : '',
text: textEl ? textEl.textContent : ''
};
// Ohne Namen und Bildunterschrift - freigegeben ist nur das Bild selbst
var gallerySlides = photos.map(function (url) {
return { src: url, srcset: '', alt: 'Screenshot aus der Galerie unserer Mitglieder', tag: '📸 Aus der Galerie', text: 'Momente unserer Mitglieder' };
});
var layers = [first, first.cloneNode(false)];
layers[1].classList.remove('is-visible');
layers[1].removeAttribute('loading');
layers[1].setAttribute('aria-hidden', 'true');
first.parentNode.insertBefore(layers[1], first.nextSibling);
var active = 0;
var queue = [];
var timer = 0;
var busy = false;
var paused = false;
var inView = !('IntersectionObserver' in window);
function shuffle(list) {
for (var i = list.length - 1; i > 0; i--) {
var j = Math.floor(Math.random() * (i + 1));
var tmp = list[i];
list[i] = list[j];
list[j] = tmp;
}
return list;
}
function nextSlide() {
if (queue.length === 0) {
queue = shuffle(gallerySlides.slice());
queue.push(groupSlide);
}
return queue.shift();
}
function schedule() {
window.clearTimeout(timer);
timer = 0;
if (paused || busy || !inView || document.hidden) return;
timer = window.setTimeout(function () {
timer = 0;
show(nextSlide());
}, INTERVAL);
}
function show(slide) {
var next = layers[1 - active];
busy = true;
function done() {
next.onload = next.onerror = null;
next.classList.add('is-visible');
next.removeAttribute('aria-hidden');
layers[active].classList.remove('is-visible');
layers[active].setAttribute('aria-hidden', 'true');
active = 1 - active;
if (tagEl) tagEl.textContent = slide.tag;
if (textEl) textEl.textContent = slide.text;
busy = false;
schedule();
}
next.onload = done;
next.onerror = function () {
next.onload = next.onerror = null;
busy = false;
// Bild fehlt inzwischen (z.B. geloescht) - nicht mehr zeigen und gleich das naechste
gallerySlides = gallerySlides.filter(function (s) { return s !== slide; });
queue = queue.filter(function (s) { return s !== slide; });
if (gallerySlides.length === 0) {
if (toggle) toggle.hidden = true;
return;
}
show(nextSlide());
};
next.alt = slide.alt;
if (slide.srcset) {
next.setAttribute('srcset', slide.srcset);
} else {
next.removeAttribute('srcset');
}
next.setAttribute('src', slide.src);
// Dieselbe Adresse wie zuvor laedt nicht neu - dann gibt es auch kein load-Ereignis
if (next.complete && next.naturalWidth > 0 && next.onload) done();
}
if (!inView) {
new IntersectionObserver(function (entries) {
inView = entries[entries.length - 1].isIntersecting;
schedule();
}, { threshold: 0.3 }).observe(figure);
}
document.addEventListener('visibilitychange', schedule);
if (toggle) {
toggle.hidden = false;
toggle.addEventListener('click', function () {
paused = !paused;
toggle.setAttribute('aria-pressed', paused ? 'true' : 'false');
toggle.setAttribute('aria-label', paused ? 'Bilderwechsel fortsetzen' : 'Bilderwechsel anhalten');
schedule();
});
}
schedule();
})();