Gear planner: - Personal gear sets (18 slots) with enchant, exceed, soul imprint and manastones, stat totals by source and side-by-side comparison of 2-4 sets - Sets can be shown on the own profile page (read-only for other members) - Admin catalog: import items from aion2hub.com (Global client), compare stored values with the source one by one or all at once, at most one request per second - New permissions gear.view (all with dashboard access) and gear.manage Dashboard: - Role badges ordered like the member list (roster_order) - Stronger hover effect on "Rangliste & Verlauf" / "Zum Lumishop", no more blue hover on secondary buttons - "Anstehende Raids" box links to the raids page, next raids link to the raid and to the calendar day - Raid attendance only knows present/absent (old "excused" entries count as unset) Bug reports: - Up to 5 images per report, pasting copied images with Ctrl+V (also for the gallery) - Images are only served to the reporter and bugs.manage via bug_image.php Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
176 lines
8.2 KiB
JavaScript
176 lines
8.2 KiB
JavaScript
/**
|
|
* Schoenere Datei-Auswahl: macht aus jedem sichtbaren <input type="file"> eine Flaeche zum
|
|
* Klicken oder Hineinziehen, mit Vorschaubildern der gewaehlten Bilder. Das echte Eingabefeld
|
|
* bleibt erhalten (liegt unsichtbar ueber der Flaeche), Formulare funktionieren also wie vorher.
|
|
*
|
|
* Optional am Feld:
|
|
* data-paste kopierte Bilder (Screenshot, "Bild kopieren") lassen sich mit Strg+V einfuegen
|
|
* data-max-files=N hoechstens N Bilder (mehr ausgewaehlte/eingefuegte werden abgeschnitten)
|
|
*/
|
|
(function () {
|
|
'use strict';
|
|
|
|
var ICON = '<svg viewBox="0 0 24 24" width="26" height="26" fill="none" stroke="currentColor" stroke-width="1.8" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true">'
|
|
+ '<rect x="3" y="4" width="18" height="16" rx="3"/><circle cx="9" cy="10" r="2"/><path d="M21 16l-5-5-8 8"/></svg>';
|
|
|
|
// Felder mit data-paste - ein gemeinsamer Paste-Listener entscheidet, welches das Bild bekommt
|
|
var pasteTargets = [];
|
|
|
|
function formatSize(bytes) {
|
|
return bytes > 1024 * 1024 ? (bytes / 1024 / 1024).toFixed(1).replace('.', ',') + ' MB' : Math.round(bytes / 1024) + ' KB';
|
|
}
|
|
|
|
function enhance(input) {
|
|
if (input.dataset.enhanced || input.hidden || input.closest('[hidden]') || input.style.display === 'none') return;
|
|
input.dataset.enhanced = '1';
|
|
|
|
var multiple = input.multiple;
|
|
var zone = document.createElement('div');
|
|
zone.className = 'file-drop';
|
|
zone.innerHTML =
|
|
'<div class="file-drop-body">' + ICON +
|
|
'<span class="file-drop-title">' + (multiple ? 'Bilder auswählen' : 'Bild auswählen') + '</span>' +
|
|
'<span class="file-drop-hint">oder hierher ziehen' + (input.hasAttribute('data-paste') ? ' · Strg+V fügt kopierte Bilder ein' : '') + ' · PNG, JPG, GIF, WEBP</span>' +
|
|
'</div>' +
|
|
'<div class="file-drop-files" hidden></div>';
|
|
input.parentNode.insertBefore(zone, input);
|
|
// Das Feld liegt nur ueber der Klickflaeche - der "Entfernen"-Knopf bleibt klickbar.
|
|
zone.querySelector('.file-drop-body').appendChild(input);
|
|
input.classList.add('file-drop-input');
|
|
|
|
var list = zone.querySelector('.file-drop-files');
|
|
var urls = [];
|
|
var maxFiles = parseInt(input.dataset.maxFiles, 10) || 0;
|
|
var trimmed = 0;
|
|
|
|
/** Dateien setzen (bei mehreren ggf. an die schon gewaehlten anhaengen), Obergrenze beachten. */
|
|
function setFiles(files, append) {
|
|
if (typeof DataTransfer === 'undefined') return false;
|
|
var all = (append && multiple ? Array.prototype.slice.call(input.files || []) : []).concat(files);
|
|
if (!multiple) all = all.slice(-1);
|
|
trimmed = maxFiles && all.length > maxFiles ? all.length - maxFiles : 0;
|
|
if (trimmed) all = all.slice(0, maxFiles);
|
|
var dt = new DataTransfer();
|
|
all.forEach(function (file) { dt.items.add(file); });
|
|
input.files = dt.files;
|
|
render();
|
|
return true;
|
|
}
|
|
|
|
function render() {
|
|
urls.forEach(URL.revokeObjectURL);
|
|
urls = [];
|
|
list.textContent = '';
|
|
var files = Array.prototype.slice.call(input.files || []);
|
|
zone.classList.toggle('has-files', files.length > 0);
|
|
list.hidden = files.length === 0;
|
|
files.forEach(function (file) {
|
|
var item = document.createElement('div');
|
|
item.className = 'file-drop-file';
|
|
if (/^image\//.test(file.type)) {
|
|
var url = URL.createObjectURL(file);
|
|
urls.push(url);
|
|
var img = document.createElement('img');
|
|
img.src = url;
|
|
img.alt = '';
|
|
item.appendChild(img);
|
|
}
|
|
var meta = document.createElement('span');
|
|
meta.className = 'file-drop-name';
|
|
meta.textContent = file.name + ' · ' + formatSize(file.size);
|
|
item.appendChild(meta);
|
|
list.appendChild(item);
|
|
});
|
|
if (trimmed) {
|
|
var note = document.createElement('span');
|
|
note.className = 'file-drop-note';
|
|
note.textContent = 'Höchstens ' + maxFiles + ' Bilder - ' + (trimmed === 1 ? 'eins wurde' : trimmed + ' wurden') + ' weggelassen.';
|
|
list.appendChild(note);
|
|
}
|
|
if (files.length) {
|
|
var clear = document.createElement('button');
|
|
clear.type = 'button';
|
|
clear.className = 'file-drop-clear';
|
|
clear.textContent = 'Entfernen';
|
|
clear.addEventListener('click', function (e) {
|
|
e.preventDefault();
|
|
input.value = '';
|
|
trimmed = 0;
|
|
render();
|
|
});
|
|
list.appendChild(clear);
|
|
}
|
|
}
|
|
|
|
input.addEventListener('change', function () {
|
|
// Zu viele auf einmal ausgewaehlt: auf die Obergrenze kuerzen
|
|
if (maxFiles && input.files && input.files.length > maxFiles) {
|
|
setFiles(Array.prototype.slice.call(input.files), false);
|
|
} else {
|
|
trimmed = 0;
|
|
render();
|
|
}
|
|
});
|
|
if (input.hasAttribute('data-paste')) {
|
|
pasteTargets.push({
|
|
input: input,
|
|
zone: zone,
|
|
add: function (files) {
|
|
if (!setFiles(files, true)) return;
|
|
zone.classList.add('is-pasted');
|
|
setTimeout(function () { zone.classList.remove('is-pasted'); }, 700);
|
|
}
|
|
});
|
|
}
|
|
['dragenter', 'dragover'].forEach(function (type) {
|
|
input.addEventListener(type, function () { zone.classList.add('is-dragging'); });
|
|
});
|
|
['dragleave', 'drop'].forEach(function (type) {
|
|
input.addEventListener(type, function () { zone.classList.remove('is-dragging'); });
|
|
});
|
|
input.addEventListener('focus', function () { zone.classList.add('is-focused'); });
|
|
input.addEventListener('blur', function () { zone.classList.remove('is-focused'); });
|
|
// Nach dem Absenden (z.B. Seite bleibt bei Fehler) Vorschau aktuell halten
|
|
if (input.files && input.files.length) render();
|
|
}
|
|
|
|
/** Bilder aus der Zwischenablage (Strg+V) als Dateien, mit sprechendem Namen. */
|
|
function clipboardImages(event) {
|
|
var items = event.clipboardData ? event.clipboardData.items : null;
|
|
var files = [];
|
|
var now = new Date();
|
|
var pad = function (n) { return (n < 10 ? '0' : '') + n; };
|
|
var stamp = now.getFullYear() + pad(now.getMonth() + 1) + pad(now.getDate()) + '-' + pad(now.getHours()) + pad(now.getMinutes()) + pad(now.getSeconds());
|
|
Array.prototype.forEach.call(items || [], function (item, i) {
|
|
if (item.kind !== 'file' || !/^image\//.test(item.type)) return;
|
|
var file = item.getAsFile();
|
|
if (!file) return;
|
|
var ext = item.type.split('/')[1].replace('jpeg', 'jpg');
|
|
files.push(new File([file], 'Eingefuegt-' + stamp + (i ? '-' + (i + 1) : '') + '.' + ext, { type: item.type }));
|
|
});
|
|
return files;
|
|
}
|
|
|
|
document.addEventListener('paste', function (event) {
|
|
if (!pasteTargets.length) return;
|
|
// Nur sichtbare Felder (z.B. nicht im zugeklappten Formular); bevorzugt das im Formular,
|
|
// in dem man gerade tippt
|
|
var visible = pasteTargets.filter(function (t) { return t.zone.offsetParent !== null; });
|
|
if (!visible.length) return;
|
|
var active = document.activeElement;
|
|
var target = visible.filter(function (t) { return t.input.form && active && t.input.form.contains(active); })[0] || visible[0];
|
|
var files = clipboardImages(event);
|
|
if (!files.length) return; // nur Text - normales Einfuegen
|
|
event.preventDefault();
|
|
target.add(files);
|
|
});
|
|
|
|
function init() {
|
|
document.querySelectorAll('input[type="file"]').forEach(enhance);
|
|
}
|
|
if (document.readyState === 'loading') {
|
|
document.addEventListener('DOMContentLoaded', init);
|
|
} else {
|
|
init();
|
|
}
|
|
})();
|