- Moderation page with tabs: approval, all comments (critical/suspicious flags, search, filters), swear word filter (mark / hold / block, maintained by mods, detects leetspeak) - Discord-style emoji reactions on gallery pictures and comments (without reloading) - Member list and profile: "last active" / online dot, sortable - Map: all marker categories hidden at start Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
71 lines
2.9 KiB
JavaScript
71 lines
2.9 KiB
JavaScript
/**
|
|
* Reaktionen (Emojis) ohne Neuladen: Klick auf eine Reaktion oder ein Emoji in der Auswahl
|
|
* schickt das Formular im Hintergrund und ersetzt die Leiste durch die neue vom Server.
|
|
* Ohne JavaScript funktionieren die Formulare ganz normal (mit Neuladen).
|
|
*/
|
|
(function () {
|
|
'use strict';
|
|
|
|
document.addEventListener('submit', function (event) {
|
|
var form = event.target;
|
|
if (!form.classList || !form.classList.contains('reaction-form')) return;
|
|
event.preventDefault();
|
|
|
|
var bar = form.closest('.reaction-bar');
|
|
if (!bar || bar.classList.contains('is-busy')) return;
|
|
bar.classList.add('is-busy');
|
|
|
|
fetch(form.action, {
|
|
method: 'POST',
|
|
body: new FormData(form),
|
|
credentials: 'same-origin',
|
|
headers: { 'X-Requested-With': 'fetch', 'Accept': 'application/json' }
|
|
})
|
|
.then(function (response) { return response.json(); })
|
|
.then(function (data) {
|
|
if (!data.ok) {
|
|
alert(data.error || 'Das hat nicht geklappt.');
|
|
bar.classList.remove('is-busy');
|
|
return;
|
|
}
|
|
var wrapper = document.createElement('div');
|
|
wrapper.innerHTML = data.html;
|
|
var fresh = wrapper.firstElementChild;
|
|
if (fresh) {
|
|
bar.replaceWith(fresh);
|
|
var changed = fresh.querySelector('.reaction.is-mine');
|
|
if (changed) changed.classList.add('pop');
|
|
} else {
|
|
bar.remove();
|
|
}
|
|
})
|
|
.catch(function () {
|
|
bar.classList.remove('is-busy');
|
|
form.submit(); // Rueckfall: normal abschicken
|
|
});
|
|
});
|
|
|
|
// Emoji-Auswahl im Bild halten: ragt sie rechts hinaus, klappt sie nach links auf
|
|
document.addEventListener('toggle', function (event) {
|
|
var details = event.target;
|
|
if (!details.classList || !details.classList.contains('reaction-add') || !details.open) return;
|
|
var picker = details.querySelector('.reaction-picker');
|
|
picker.classList.remove('align-right');
|
|
if (picker.getBoundingClientRect().right > window.innerWidth - 8) {
|
|
picker.classList.add('align-right');
|
|
}
|
|
}, true);
|
|
|
|
// Emoji-Auswahl schliessen bei Klick daneben oder Escape
|
|
document.addEventListener('click', function (event) {
|
|
document.querySelectorAll('.reaction-add[open]').forEach(function (details) {
|
|
if (!details.contains(event.target)) details.removeAttribute('open');
|
|
});
|
|
});
|
|
document.addEventListener('keydown', function (event) {
|
|
if (event.key !== 'Escape') return;
|
|
document.querySelectorAll('.reaction-add[open]').forEach(function (details) {
|
|
details.removeAttribute('open');
|
|
});
|
|
});
|
|
})();
|