MediaWiki:Common.js: Unterschied zwischen den Versionen
Admin (Diskussion | Beiträge) Keine Bearbeitungszusammenfassung Markierung: Manuelle Zurücksetzung |
Admin (Diskussion | Beiträge) Keine Bearbeitungszusammenfassung |
||
| (10 dazwischenliegende Versionen desselben Benutzers werden nicht angezeigt) | |||
| Zeile 396: | Zeile 396: | ||
}); | }); | ||
| Zeile 458: | Zeile 454: | ||
/* ========== Kategorien rekursiv einsammeln (inkl. Subkats, Namespaces) ========== */ | /* ========== Kategorien rekursiv einsammeln (inkl. Subkats, Namespaces) ========== */ | ||
function fetchCategoryMembersRecursiveSingleResolved(api, catTitle, limit, outSet, pages, nsStr){ | function fetchCategoryMembersRecursiveSingleResolved(api, catTitle, limit, outSet, pages, nsStr){ | ||
var visited = {}, queue = [catTitle]; | var visited = {}, queue = [catTitle]; | ||
| Zeile 468: | Zeile 463: | ||
list: 'categorymembers', | list: 'categorymembers', | ||
cmtitle: title, | cmtitle: title, | ||
cmtype: 'page|subcat', | cmtype: 'page|subcat', | ||
cmlimit: Math.min(200, limit), | cmlimit: Math.min(200, limit), | ||
| Zeile 577: | Zeile 571: | ||
/* ========== Render ========== */ | /* ========== Render ========== */ | ||
function renderTopN(container, rows, N, minVotes) { | function renderTopN(container, rows, N, minVotes) { | ||
var keep = (container.getAttribute && container.getAttribute('data-keep-status') === 'true'); | var keep = (container.getAttribute && container.getAttribute('data-keep-status') === 'true'); | ||
var statusBox = keep ? container.querySelector('.whisky-top5__status') : null; | var statusBox = keep ? container.querySelector('.whisky-top5__status') : null; | ||
| Zeile 637: | Zeile 630: | ||
container.setAttribute('data-top5-init','1'); | container.setAttribute('data-top5-init','1'); | ||
var rawCats = container.getAttribute('data-categories') || container.getAttribute('data-category') || ''; | var rawCats = container.getAttribute('data-categories') || container.getAttribute('data-category') || ''; | ||
var parts = rawCats.split(/\n|;/), rootCats = [], i; | var parts = rawCats.split(/\n|;/), rootCats = [], i; | ||
| Zeile 647: | Zeile 639: | ||
var minVotes = parseInt(container.getAttribute('data-min-votes') || '1', 10); | var minVotes = parseInt(container.getAttribute('data-min-votes') || '1', 10); | ||
var includeHidden = (container.getAttribute('data-include-hidden') === 'true'); | var includeHidden = (container.getAttribute('data-include-hidden') === 'true'); | ||
var nsStr = container.getAttribute('data-namespaces') || '0|14'; | var nsStr = container.getAttribute('data-namespaces') || '0|14'; | ||
var rawC = container.getAttribute('data-contests') || 'NASE,GESCHMACK,ABGANG,GESAMTEINDRUCK'; | var rawC = container.getAttribute('data-contests') || 'NASE,GESCHMACK,ABGANG,GESAMTEINDRUCK'; | ||
| Zeile 658: | Zeile 650: | ||
status('Sammle Seiten …'); | status('Sammle Seiten …'); | ||
fetchCategoryMembersRecursiveMulti(rootCats, lim, status, nsStr).then(function(members){ | fetchCategoryMembersRecursiveMulti(rootCats, lim, status, nsStr).then(function(members){ | ||
status('Gefundene Seiten gesamt: ' + (members ? members.length : 0) + ' – lade Bewertungen …', true); | status('Gefundene Seiten gesamt: ' + (members ? members.length : 0) + ' – lade Bewertungen …', true); | ||
| Zeile 703: | Zeile 693: | ||
}); | }); | ||
| Zeile 712: | Zeile 700: | ||
var el = this, val = parseFloat(el.getAttribute('data-rating') || '0'); | var el = this, val = parseFloat(el.getAttribute('data-rating') || '0'); | ||
if (isNaN(val)) val = 0; | if (isNaN(val)) val = 0; | ||
val = Math.max(0, Math.min(5, val)); | val = Math.max(0, Math.min(5, val)); | ||
el.style.setProperty('--stars', (val).toString()); | el.style.setProperty('--stars', (val).toString()); | ||
el.setAttribute('aria-label', val + ' von 5 Sternen'); | el.setAttribute('aria-label', val + ' von 5 Sternen'); | ||
| Zeile 721: | Zeile 707: | ||
}); | }); | ||
// Force light color-scheme at document level (helps Mobile Safari) | // Force light color-scheme at document level (helps Mobile Safari) | ||
| Zeile 736: | Zeile 720: | ||
} | } | ||
}); | }); | ||
| Zeile 751: | Zeile 733: | ||
if (!chart || !block) return; | if (!chart || !block) return; | ||
const total = chart.data.datasets.reduce((sum, ds) => | const total = chart.data.datasets.reduce((sum, ds) => | ||
sum + (ds.data || []).reduce((a, b) => a + (parseFloat(b) || 0), 0) | sum + (ds.data || []).reduce((a, b) => a + (parseFloat(b) || 0), 0) | ||
, 0); | , 0); | ||
const oldInfo = block.querySelector(':scope > .chart-total-info'); | const oldInfo = block.querySelector(':scope > .chart-total-info'); | ||
if (oldInfo) oldInfo.remove(); | if (oldInfo) oldInfo.remove(); | ||
const info = document.createElement('div'); | const info = document.createElement('div'); | ||
info.className = 'chart-total-info'; | info.className = 'chart-total-info'; | ||
| Zeile 775: | Zeile 754: | ||
} | } | ||
/* === ADOS Multi-Serien-Chart (Chart.js) ============================= * | /* === ADOS Multi-Serien-Chart (Chart.js) ============================= * | ||
| Zeile 784: | Zeile 761: | ||
(function () { | (function () { | ||
var _chartReady = null; | var _chartReady = null; | ||
function ensureChartJS() { | function ensureChartJS() { | ||
| Zeile 791: | Zeile 767: | ||
if (window.Chart) return resolve(); | if (window.Chart) return resolve(); | ||
var s = document.createElement('script'); | var s = document.createElement('script'); | ||
s.src = 'https://cdn.jsdelivr.net/npm/chart.js'; | s.src = 'https://cdn.jsdelivr.net/npm/chart.js'; | ||
s.async = true; | s.async = true; | ||
s.onload = function(){ resolve(); }; | s.onload = function(){ resolve(); }; | ||
| Zeile 800: | Zeile 776: | ||
} | } | ||
var ADOS_COLORS = { | var ADOS_COLORS = { | ||
'A Dream of Scotland': '#C2410C', | 'A Dream of Scotland': '#C2410C', | ||
'A Dream of Ireland': '#15803D', | 'A Dream of Ireland': '#15803D', | ||
'A Dream of... – Der Rest der Welt': '#1D4ED8', | 'A Dream of... – Der Rest der Welt': '#1D4ED8', | ||
'Friendly Mr. Z': '#9333EA', | 'Friendly Mr. Z': '#9333EA', | ||
'Die Whisky Elfen': '#0891B2', | 'Die Whisky Elfen': '#0891B2', | ||
'The Fine Art of Whisky': '#CA8A04' | 'The Fine Art of Whisky': '#CA8A04' | ||
}; | }; | ||
var COLOR_CYCLE = ['#2563eb','#16a34a','#f97316','#dc2626','#a855f7','#0ea5e9','#f59e0b','#10b981']; | var COLOR_CYCLE = ['#2563eb','#16a34a','#f97316','#dc2626','#a855f7','#0ea5e9','#f59e0b','#10b981']; | ||
| Zeile 822: | Zeile 797: | ||
} | } | ||
function buildDatasetsFromTable(tbl){ | function buildDatasetsFromTable(tbl){ | ||
var rows = Array.from(tbl.querySelectorAll('tr')); | var rows = Array.from(tbl.querySelectorAll('tr')); | ||
| Zeile 828: | Zeile 802: | ||
var yearsSet = new Set(); | var yearsSet = new Set(); | ||
var bySeries = new Map(); | var bySeries = new Map(); | ||
rows.slice(1).forEach(function(tr){ | rows.slice(1).forEach(function(tr){ | ||
| Zeile 863: | Zeile 837: | ||
} | } | ||
function renderOne(block){ | |||
function renderOne(block){ | if (block.dataset.rendered === '1') return; | ||
var el = block.nextElementSibling, tbl = null, wrapToHide = null; | |||
while (el) { | |||
if (/^H[1-6]$/.test(el.tagName) || (el.classList && el.classList.contains('ados-chart-multi'))) break; | |||
if (el.tagName === 'TABLE') { | |||
tbl = el; | |||
} else if (el.querySelector) { | |||
var t = el.querySelector('table'); | |||
if (t) tbl = t; | |||
} | |||
if (tbl) { | |||
wrapToHide = tbl.parentElement; | |||
break; | |||
} | |||
el = el.nextElementSibling; | |||
} | } | ||
if (!tbl) return; | |||
var out = buildDatasetsFromTable(tbl); | |||
if (!out.labels.length || !out.datasets.length) return; | |||
var hide = (block.dataset.hideTable || '').toLowerCase() === 'true'; | |||
if (hide) { | |||
var onlyTable = wrapToHide && wrapToHide.children.length === 1 && wrapToHide.firstElementChild === tbl; | |||
if (onlyTable) { | |||
wrapToHide.setAttribute('aria-hidden','true'); | |||
wrapToHide.style.display = 'none'; | |||
} else { | |||
tbl.setAttribute('aria-hidden','true'); | |||
tbl.style.display = 'none'; | |||
} | |||
} | } | ||
var wrap = document.createElement('div'); | |||
wrap.style.position = 'relative'; | |||
wrap.style.width = '100%'; | |||
wrap.style.height = block.dataset.height || (window.matchMedia('(min-width:768px)').matches ? '450px' : '300px'); | |||
var canvas = document.createElement('canvas'); | |||
wrap.appendChild(canvas); | |||
block.innerHTML = ''; | |||
block.appendChild(wrap); | |||
var type = (block.dataset.type || 'line').toLowerCase(); | |||
var title = block.dataset.title || ''; | |||
var cumulative = (block.dataset.cumulative || '').toLowerCase() === 'true'; | |||
if (cumulative) { | |||
out.datasets = out.datasets.map(function(ds){ | |||
var acc = 0; | |||
return Object.assign({}, ds, { | |||
data: ds.data.map(function(v){ acc += v; return acc; }) | |||
}); | |||
}); | }); | ||
} | |||
ensureChartJS().then(function(){ | ensureChartJS().then(function(){ | ||
const chart = new Chart(canvas.getContext('2d'), { | |||
type: type, | |||
data: { labels: out.labels, datasets: out.datasets }, | |||
options: { | |||
responsive: true, | |||
maintainAspectRatio: false, | |||
interaction: { mode: 'nearest', intersect: false }, | |||
plugins: { | |||
legend: { position: 'bottom', labels: { font: { size: 13 }, boxWidth: 20 } }, | |||
title: { display: !!title, text: title, font: { size: 16 } }, | |||
tooltip:{ backgroundColor: 'rgba(0,0,0,0.8)', titleFont: {size:14}, bodyFont: {size:13} } | |||
}, | |||
scales: { | |||
x: { ticks: { font: { size: 12 } } }, | |||
y: { beginAtZero: true, ticks: { precision: 0, font: { size: 12 } } } | |||
} | |||
} | |||
}); | |||
const hideTotal = (block.dataset.hideTotal || '').toLowerCase() === 'true'; | |||
const oldInfo = block.querySelector(':scope > .chart-total-info'); | |||
if (oldInfo) oldInfo.remove(); | |||
if (!hideTotal) { | |||
addTotalBelowLegend(chart, block); | |||
if (window.ResizeObserver) { | |||
const obs = new ResizeObserver(() => addTotalBelowLegend(chart, block)); | |||
obs.observe(chart.canvas); | |||
chart.$adosTotalObserver = obs; | |||
} | |||
} | |||
block.dataset.rendered = '1'; | |||
}); | |||
} | |||
} | } | ||
function boot($scope){ | function boot($scope){ | ||
var blocks = ($scope && $scope[0] ? $scope[0] : document).querySelectorAll('.ados-chart-multi'); | var blocks = ($scope && $scope[0] ? $scope[0] : document).querySelectorAll('.ados-chart-multi'); | ||
| Zeile 982: | Zeile 941: | ||
mw.hook('wikipage.content').add(boot); | mw.hook('wikipage.content').add(boot); | ||
} else { | } else { | ||
(document.readyState === 'loading') | (document.readyState === 'loading') | ||
? document.addEventListener('DOMContentLoaded', function(){ boot(); }) | ? document.addEventListener('DOMContentLoaded', function(){ boot(); }) | ||
| Zeile 988: | Zeile 946: | ||
} | } | ||
})(); | })(); | ||
// ==========================Scan================================== | // ==========================Scan================================== | ||
mw.loader.using('mediawiki.util').then(function () { | mw.loader.using('mediawiki.util').then(function () { | ||
if (mw.config.get('wgPageName') !== 'LabelScan') return; | if (mw.config.get('wgPageName') !== 'LabelScan') return; | ||
| Zeile 998: | Zeile 954: | ||
mw.loader.load('/index.php?title=MediaWiki:Gadget-LabelScan.css&action=raw&ctype=text/css', 'text/css'); | mw.loader.load('/index.php?title=MediaWiki:Gadget-LabelScan.css&action=raw&ctype=text/css', 'text/css'); | ||
}); | }); | ||
// ==========================ScanApp================================== | // ==========================ScanApp================================== | ||
/* ==== PWA: Manifest + Service Worker + Install-Button (ES5) ==== */ | /* ==== PWA: Manifest + Service Worker + Install-Button (ES5) ==== */ | ||
| Zeile 1.032: | Zeile 985: | ||
}); | }); | ||
function onReady(fn){ if (document.readyState === "loading") document.addEventListener("DOMContentLoaded", fn); else fn(); } | |||
onReady(function () { | onReady(function () { | ||
var btn = document.getElementById("ados-install"); | var btn = document.getElementById("ados-install"); | ||
| Zeile 1.045: | Zeile 997: | ||
}); | }); | ||
})(); | })(); | ||
if ('serviceWorker' in navigator) { | if ('serviceWorker' in navigator) { | ||
| Zeile 1.052: | Zeile 1.003: | ||
// ============================================================ | |||
mw.loader.using('mediawiki.util').then(function () { | |||
function checkNeuBadges() { | |||
var badges = document.querySelectorAll('.ados-neu-badge'); | |||
var now = new Date(); | |||
badges.forEach(function (badge) { | |||
var expiry = badge.getAttribute('data-expiry'); | |||
if (!expiry) return; | |||
var expiryDate = new Date(expiry + "T23:59:59"); | |||
if (now > expiryDate) { | |||
badge.style.display = "none"; | |||
} | |||
}); | |||
} | } | ||
if (document.readyState === "loading") { | |||
document.addEventListener("DOMContentLoaded", checkNeuBadges); | |||
} else { | |||
checkNeuBadges(); | |||
} | |||
} | } | ||
}); | |||
// ============================================================ | |||
mw.loader.load('/wiki/MediaWiki:WhiskybaseBatch.js?action=raw&ctype=text/javascript'); | |||