MediaWiki:Common.js: Unterschied zwischen den Versionen
Admin (Diskussion | Beiträge) Keine Bearbeitungszusammenfassung Markierung: Manuelle Zurücksetzung |
Admin (Diskussion | Beiträge) Keine Bearbeitungszusammenfassung |
||
| Zeile 130: | Zeile 130: | ||
// === Skript 2 === | // === Skript 2 === | ||
/* Sticky Charity Banner (v1) – MediaWiki | /* Sticky Charity Banner (v1) – MediaWiki */ | ||
*/ | |||
mw.loader.using(['mediawiki.util', 'jquery']).then(function () { | mw.loader.using(['mediawiki.util', 'jquery']).then(function () { | ||
(function ($, mw) { | (function ($, mw) { | ||
| Zeile 142: | Zeile 137: | ||
var CONFIG = { | var CONFIG = { | ||
enabled: true, | enabled: true, | ||
id: 'charity_banner_v1', | id: 'charity_banner_v1', | ||
text: '❤️ Unterstütze die Kinderherzen-Charity – Jede Spende zählt!', | text: '❤️ Unterstütze die Kinderherzen-Charity – Jede Spende zählt!', | ||
primary: { | primary: { | ||
label: 'Mehr erfahren', | label: 'Mehr erfahren', | ||
href: 'https://www.kinderherzen.de/whisky-fuer-den-guten-zweck/' | href: 'https://www.kinderherzen.de/whisky-fuer-den-guten-zweck/' | ||
}, | }, | ||
secondary: { | secondary: { | ||
label: 'Mehr auf dem Wiki', | label: 'Mehr auf dem Wiki', | ||
href: 'https://ados-wiki.de/index.php?title=Charity-Event_%E2%80%9EWhisky_f%C3%BCr_den_guten_Zweck%E2%80%9C_%E2%80%93_The_Whisky_Waiter' | href: 'https://ados-wiki.de/index.php?title=Charity-Event_%E2%80%9EWhisky_f%C3%BCr_den_guten_Zweck%E2%80%9C_%E2%80%93_The_Whisky_Waiter' | ||
}, | }, | ||
showOnNamespaces: 'all', | showOnNamespaces: 'all', | ||
endISO: null, | endISO: null, | ||
dismiss: { mode: 'day' }, | dismiss: { mode: 'day' }, | ||
zIndex: 10050 | zIndex: 10050 | ||
}; | }; | ||
if (!CONFIG.enabled) return; | if (!CONFIG.enabled) return; | ||
if (CONFIG.endISO && new Date() > new Date(CONFIG.endISO)) return; | if (CONFIG.endISO && new Date() > new Date(CONFIG.endISO)) return; | ||
var ns = mw.config.get('wgNamespaceNumber'); | var ns = mw.config.get('wgNamespaceNumber'); | ||
if (CONFIG.showOnNamespaces !== 'all' && | if (CONFIG.showOnNamespaces !== 'all' && | ||
| Zeile 171: | Zeile 163: | ||
} | } | ||
function getLS(k){ try { return localStorage.getItem(k); } catch(e){ return null; } } | function getLS(k){ try { return localStorage.getItem(k); } catch(e){ return null; } } | ||
function setLS(k,v){ try { localStorage.setItem(k,v); } catch(e){} } | function setLS(k,v){ try { localStorage.setItem(k,v); } catch(e){} } | ||
| Zeile 177: | Zeile 168: | ||
var today = (function(d){ return d.getFullYear()+'-'+('0'+(d.getMonth()+1)).slice(-2)+'-'+('0'+d.getDate()).slice(-2); })(new Date()); | var today = (function(d){ return d.getFullYear()+'-'+('0'+(d.getMonth()+1)).slice(-2)+'-'+('0'+d.getDate()).slice(-2); })(new Date()); | ||
var dismissed = getLS(key); | var dismissed = getLS(key); | ||
if (CONFIG.dismiss.mode === 'forever' && dismissed) return; | if (CONFIG.dismiss.mode === 'forever' && dismissed) return; | ||
if (CONFIG.dismiss.mode === 'day' && dismissed === today) return; | if (CONFIG.dismiss.mode === 'day' && dismissed === today) return; | ||
$(function () { | $(function () { | ||
var $bar = $('<div>', { | var $bar = $('<div>', { | ||
'class': 'mw-sticky-banner', | 'class': 'mw-sticky-banner', | ||
| Zeile 192: | Zeile 180: | ||
var $inner = $('<div>', { 'class': 'mw-sticky-banner__inner' }); | var $inner = $('<div>', { 'class': 'mw-sticky-banner__inner' }); | ||
var $text = $('<div>', { 'class': 'mw-sticky-banner__text', 'html': mw.html.escape(CONFIG.text) }); | var $text = $('<div>', { 'class': 'mw-sticky-banner__text', 'html': mw.html.escape(CONFIG.text) }); | ||
var $btns = $('<div>', { 'class': 'mw-sticky-banner__btns' }); | var $btns = $('<div>', { 'class': 'mw-sticky-banner__btns' }); | ||
if (CONFIG.primary && CONFIG.primary.href) { | if (CONFIG.primary && CONFIG.primary.href) { | ||
| Zeile 226: | Zeile 212: | ||
if (CONFIG.dismiss.mode === 'forever') { setLS(key, '1'); } | if (CONFIG.dismiss.mode === 'forever') { setLS(key, '1'); } | ||
else if (CONFIG.dismiss.mode === 'day') { setLS(key, today); } | else if (CONFIG.dismiss.mode === 'day') { setLS(key, today); } | ||
} | } | ||
| Zeile 242: | Zeile 227: | ||
/* ADOS Whisky-Ratings – RatePage Frontend (ES5, Widgets + Stats + Summary, Doppel-Init-Schutz; ANON VOTING ERLAUBT) */ | |||
/* ADOS Whisky-Ratings – RatePage Frontend (ES5, Widgets + Stats + Summary, Doppel-Init-Schutz) */ | |||
mw.loader.using(['mediawiki.api', 'mediawiki.user']).then(function () { | mw.loader.using(['mediawiki.api', 'mediawiki.user']).then(function () { | ||
// ---------- kleine Hilfsfunktion | // ---------- kleine Hilfsfunktion ---------- | ||
function get(obj, path) { | function get(obj, path) { | ||
var cur = obj, i; | var cur = obj, i; | ||
| Zeile 263: | Zeile 245: | ||
var i, nodes; | var i, nodes; | ||
nodes = scope.querySelectorAll('.whisky-rating__item'); | nodes = scope.querySelectorAll('.whisky-rating__item'); | ||
for (i = 0; i < nodes.length; i++) setupWidget(nodes[i]); | for (i = 0; i < nodes.length; i++) setupWidget(nodes[i]); | ||
initMetaOnly(scope); | initMetaOnly(scope); | ||
nodes = scope.querySelectorAll('[data-ratepage-summary="true"]'); | nodes = scope.querySelectorAll('[data-ratepage-summary="true"]'); | ||
for (i = 0; i < nodes.length; i++) renderSummary(nodes[i]); | for (i = 0; i < nodes.length; i++) renderSummary(nodes[i]); | ||
| Zeile 280: | Zeile 259: | ||
boot(document); | boot(document); | ||
} | } | ||
mw.hook('wikipage.content').add(function($content){ | mw.hook('wikipage.content').add(function($content){ | ||
if ($content && $content[0]) boot($content[0]); | if ($content && $content[0]) boot($content[0]); | ||
}); | }); | ||
// ---------- Interaktives Widget | // ---------- Interaktives Widget ---------- | ||
function setupWidget(box) { | function setupWidget(box) { | ||
if (box.getAttribute('data-rating-init') === '1') return; | if (box.getAttribute('data-rating-init') === '1') return; | ||
box.setAttribute('data-rating-init', '1'); | box.setAttribute('data-rating-init', '1'); | ||
var pageId = mw.config.get('wgArticleId'); | var pageId = mw.config.get('wgArticleId'); | ||
var contest = box.dataset.ratepageContest || undefined; | var contest = box.dataset.ratepageContest || undefined; | ||
var scale = parseInt(box.dataset.ratepageScale || '10', 10); | var scale = parseInt(box.dataset.ratepageScale || '10', 10); | ||
| Zeile 299: | Zeile 275: | ||
var meta = box.querySelector('.whisky-rating__meta'); | var meta = box.querySelector('.whisky-rating__meta'); | ||
while (widget.firstChild) widget.removeChild(widget.firstChild); | while (widget.firstChild) widget.removeChild(widget.firstChild); | ||
// Anonyme NICHT blockieren – nur optionaler Hinweis | |||
var isAnon = mw.user.isAnon(); | var isAnon = mw.user.isAnon(); | ||
if (isAnon) { | if (isAnon && meta && !meta.textContent) { | ||
meta.textContent = 'Bewerte diesen Whisky!'; | |||
} | } | ||
| Zeile 318: | Zeile 293: | ||
btn.setAttribute('aria-pressed', 'false'); | btn.setAttribute('aria-pressed', 'false'); | ||
// Immer klickbar – egal ob anonym oder eingeloggt | |||
btn.title = iVal + ' / ' + scale; | |||
btn.addEventListener('mouseenter', function(){ highlight(iVal); }); | |||
btn.addEventListener('mouseleave', function(){ highlight(current); }); | |||
btn.addEventListener('click', function(){ vote(iVal); }); | |||
btn.addEventListener('keydown', function(e){ | |||
if (e.key === 'Enter' || e.key === ' ') { e.preventDefault(); vote(iVal); } | |||
if (e.key === 'ArrowRight' && iVal < scale) buttons[iVal].focus(); | |||
if (e.key === 'ArrowLeft' && iVal > 1) buttons[iVal-2].focus(); | |||
}); | |||
widget.appendChild(btn); | widget.appendChild(btn); | ||
buttons.push(btn); | buttons.push(btn); | ||
| Zeile 349: | Zeile 321: | ||
} | } | ||
function updateStats() { | function updateStats() { | ||
var api = new mw.Api(); | var api = new mw.Api(); | ||
| Zeile 362: | Zeile 333: | ||
try { | try { | ||
var pages = get(data, ['query','pages']) || {}; | var pages = get(data, ['query','pages']) || {}; | ||
var keys = []; | var keys = []; for (var k in pages) if (Object.prototype.hasOwnProperty.call(pages, k)) keys.push(k); | ||
var pid = keys.length ? keys[0] : String(pageId); | var pid = keys.length ? keys[0] : String(pageId); | ||
var page = pages[pid] || {}; | var page = pages[pid] || {}; | ||
| Zeile 397: | Zeile 367: | ||
if (typeof pr.canVote !== 'undefined' && pr.canVote === 0) { | if (typeof pr.canVote !== 'undefined' && pr.canVote === 0) { | ||
// Serverseitig verboten → hier deaktivieren | |||
box.classList.add('whisky-rating--disabled'); | box.classList.add('whisky-rating--disabled'); | ||
var gls = widget.querySelectorAll('.whisky-glass'); | var gls = widget.querySelectorAll('.whisky-glass'); | ||
| Zeile 414: | Zeile 385: | ||
} | } | ||
function vote(value) { | function vote(value) { | ||
var api = new mw.Api(); | var api = new mw.Api(); | ||
| Zeile 454: | Zeile 424: | ||
} | } | ||
// ---------- Meta-only | // ---------- Meta-only ---------- | ||
function initMetaOnly(scope) { | function initMetaOnly(scope) { | ||
var root = scope || document; | var root = scope || document; | ||
| Zeile 460: | Zeile 430: | ||
var i; | var i; | ||
for (i = 0; i < nodes.length; i++) (function(box){ | for (i = 0; i < nodes.length; i++) (function(box){ | ||
if (box.getAttribute('data-meta-init') === '1') return; | if (box.getAttribute('data-meta-init') === '1') return; | ||
box.setAttribute('data-meta-init', '1'); | box.setAttribute('data-meta-init', '1'); | ||
| Zeile 475: | Zeile 444: | ||
}).done(function (data) { | }).done(function (data) { | ||
var pages = get(data, ['query','pages']) || {}; | var pages = get(data, ['query','pages']) || {}; | ||
var keys = []; | var keys = []; for (var k in pages) if (Object.prototype.hasOwnProperty.call(pages,k)) keys.push(k); | ||
var pid = keys.length ? keys[0] : String(pageId); | var pid = keys.length ? keys[0] : String(pageId); | ||
var pr = pages[pid] && pages[pid].pagerating; | var pr = pages[pid] && pages[pid].pagerating; | ||
| Zeile 494: | Zeile 462: | ||
} | } | ||
// ---------- | // ---------- Summary inkl. Gesamt + Balken ---------- | ||
function renderSummary(container) { | function renderSummary(container) { | ||
if (container.getAttribute('data-summary-init') === '1') return; | if (container.getAttribute('data-summary-init') === '1') return; | ||
container.setAttribute('data-summary-init', '1'); | container.setAttribute('data-summary-init', '1'); | ||
| Zeile 505: | Zeile 472: | ||
var i; | var i; | ||
for (i = 0; i < parts.length; i++) parts[i] = parts[i].replace(/^\s+|\s+$/g, ''); | for (i = 0; i < parts.length; i++) parts[i] = parts[i].replace(/^\s+|\s+$/g, ''); | ||
var nameToId = { 'nase':'NASE', 'geschmack':'GESCHMACK', 'abgang':'ABGANG', 'gesamteindruck':'GESAMTEINDRUCK' }; | |||
var nameToId = { 'nase':'NASE', 'geschmack':'GESCHMACK', 'abgang':'ABGANG', 'gesamteindruck':'GESAMTEINDRUCK' }; | |||
var contests = []; | var contests = []; | ||
var seen = {}; | |||
for (i = 0; i < parts.length; i++) { | for (i = 0; i < parts.length; i++) { | ||
var key = parts[i]; | var key = parts[i]; if (!key) continue; | ||
var norm = key.toLowerCase(); | var norm = key.toLowerCase(); | ||
var id = nameToId[norm] ? nameToId[norm] : key; | |||
if (!seen[id]) { contests.push(id); seen[id] = true; } | |||
} | } | ||
var labels = { NASE: 'Nase', GESCHMACK: 'Geschmack', ABGANG: 'Abgang', GESAMTEINDRUCK: 'Gesamteindruck' }; | var labels = { NASE: 'Nase', GESCHMACK: 'Geschmack', ABGANG: 'Abgang', GESAMTEINDRUCK: 'Gesamteindruck' }; | ||
| Zeile 534: | Zeile 497: | ||
}).then(function (data) { | }).then(function (data) { | ||
var pages = get(data, ['query','pages']) || {}; | var pages = get(data, ['query','pages']) || {}; | ||
var keys = []; | var keys = []; for (var k in pages) if (Object.prototype.hasOwnProperty.call(pages,k)) keys.push(k); | ||
var pid = keys.length ? keys[0] : String(pageId); | var pid = keys.length ? keys[0] : String(pageId); | ||
var pr = pages[pid] && pages[pid].pagerating; | var pr = pages[pid] && pages[pid].pagerating; | ||
| Zeile 553: | Zeile 515: | ||
return { contest: contest, label: (labels[contest] || contest), avg: avg, total: total }; | return { contest: contest, label: (labels[contest] || contest), avg: avg, total: total }; | ||
}, function () { | }, function () { | ||
return { contest: contest, label: (labels[contest] || contest), avg: null, total: 0, _error: true }; | return { contest: contest, label: (labels[contest] || contest), avg: null, total: 0, _error: true }; | ||
}); | }); | ||
| Zeile 576: | Zeile 537: | ||
var tbody = document.createElement('tbody'); | var tbody = document.createElement('tbody'); | ||
// | // Zeilen mit Balken | ||
var r; | var r; | ||
for (r = 0; r < rows.length; r++) { | for (r = 0; r < rows.length; r++) { | ||
var row = rows[r]; | var row = rows[r]; | ||
var totalText = row.total ? String(row.total) : '0'; | var totalText = row.total ? String(row.total) : '0'; | ||
var tr = document.createElement('tr'); | |||
var | |||
var tdLabel = document.createElement('td'); | |||
var | tdLabel.textContent = row.label; | ||
tr.appendChild(tdLabel); | |||
var tdAvg = document.createElement('td'); | |||
if (row.avg !== null) { | |||
var wrap = document.createElement('div'); wrap.className = 'whisky-bar'; | |||
var track = document.createElement('div'); track.className = 'whisky-bar__track'; | |||
var fill = document.createElement('div'); fill.className = 'whisky-bar__fill'; | |||
fill.style.width = Math.max(0, Math.min(100, (row.avg/10)*100)) + '%'; | |||
var val = document.createElement('span'); val.className = 'whisky-bar__value'; | |||
} else { | val.textContent = (row.avg.toFixed ? row.avg.toFixed(1) : (Math.round(row.avg*10)/10)); | ||
track.appendChild(fill); wrap.appendChild(track); wrap.appendChild(val); tdAvg.appendChild(wrap); | |||
} | } else { | ||
tr.appendChild(tdAvg | tdAvg.textContent = '–'; | ||
} | |||
tr.appendChild(tdAvg); | |||
var tdCnt = document.createElement('td'); | |||
tdCnt.textContent = totalText; | |||
tr.appendChild(tdCnt); | |||
tbody.appendChild(tr); | |||
} | } | ||
// Gesamt | // Gesamt | ||
var present = 0, sumAvg = 0; | var present = 0, sumAvg = 0, totalVotes = 0; | ||
for (r = 0; r < rows.length; r++) { | for (r = 0; r < rows.length; r++) { | ||
if (rows[r].avg !== null) { present++; sumAvg += rows[r].avg; } | if (rows[r].avg !== null) { present++; sumAvg += rows[r].avg; } | ||
if (rows[r].total) totalVotes += rows[r].total; | |||
} | } | ||
var overall = (present > 0) ? Math.round((sumAvg / present) * 10) / 10 : null; | var overall = (present > 0) ? Math.round((sumAvg / present) * 10) / 10 : null; | ||
var overallText = (overall !== null) | var overallText = (overall !== null) | ||
| Zeile 637: | Zeile 583: | ||
var trG = document.createElement('tr'); | var trG = document.createElement('tr'); | ||
var tdGL = document.createElement('td'); | |||
var tdGL = document.createElement('td'); | tdGL.innerHTML = '<strong>Gesamt</strong>'; | ||
tdGL.innerHTML = '<strong>Gesamt</strong>'; | trG.appendChild(tdGL); | ||
trG.appendChild(tdGL); | |||
var tdGA = document.createElement('td'); | |||
var tdGA = document.createElement('td'); | if (overall !== null) { | ||
if (overall !== null) { | var w = document.createElement('div'); w.className = 'whisky-bar'; | ||
var t = document.createElement('div'); t.className = 'whisky-bar__track'; | |||
var f = document.createElement('div'); f.className = 'whisky-bar__fill'; | |||
f.style.width = Math.max(0, Math.min(100, (overall/10)*100)) + '%'; | |||
var v = document.createElement('span'); v.className = 'whisky-bar__value'; | |||
v.innerHTML = '<strong>' + overallText + '</strong>'; | |||
t.appendChild(f); w.appendChild(t); w.appendChild(v); tdGA.appendChild(w); | |||
} else { | |||
} else { | tdGA.innerHTML = '<strong>–</strong>'; | ||
} | |||
} | trG.appendChild(tdGA); | ||
trG.appendChild(tdGA | |||
var tdGD = document.createElement('td'); | |||
tdGD.textContent = totalVotes; | |||
trG.appendChild(tdGD); | |||
tbody.appendChild(trG); | |||
table.appendChild(tbody); | table.appendChild(tbody); | ||
while (container.firstChild) container.removeChild(container.firstChild); | while (container.firstChild) container.removeChild(container.firstChild); | ||
container.appendChild(table); | container.appendChild(table); | ||
var badge = document.getElementById('whisky-overall-badge'); | var badge = document.getElementById('whisky-overall-badge'); | ||
if (badge && overall !== null) { | if (badge && overall !== null) { | ||
| Zeile 678: | Zeile 617: | ||
} | } | ||
}).catch(function(){ | }).catch(function(){ | ||
container.textContent = 'Konnte Bewertungen nicht | container.textContent = 'Konnte Bewertungen nicht geladen werden.'; | ||
}); | }); | ||
} | } | ||
}); | }); | ||
Version vom 3. Oktober 2025, 14:53 Uhr
/* Das folgende JavaScript wird für alle Benutzer geladen. */
// === Skript 1 ===
/* Charity-Popup (v9) – mit zwei Buttons nebeneinander/untereinander je nach Platz */
mw.loader.using(['mediawiki.util', 'jquery']).then(function () {
(function ($, mw) {
'use strict';
// --- kleines Style-Snippet für responsive Video-Einbettung ---
$('<style>')
.prop('type', 'text/css')
.text(
'.mw-popup-content .mw-popup-video{position:relative;width:100%;max-width:800px;margin:12px auto;border-radius:12px;overflow:hidden;background:#000}' +
'.mw-popup-content .mw-popup-video::before{content:"";display:block;padding-top:56.25%}' + /* 16:9 */
'.mw-popup-content .mw-popup-video iframe{position:absolute;inset:0;border:0;width:100%;height:100%}' +
'.mw-popup-content .mw-popup-video .mw-popup-video-fallback{display:block;margin-top:8px;text-align:center}'
)
.appendTo('head');
var CONFIG = {
enabled: true,
id: 'charity_notice_v9', // Version hochsetzen, damit alle es sehen
title: 'Charity für kinderherzen e.V',
logoUrl: 'https://www.kinderherzen.de/wp-content/uploads/2019/03/kinderherzen.de_orange_RGB.jpg',
html:
'<p>Liebe Whisky, ADoS Heads,</p>' +
'<p>wir wurden jetzt schon gefragt, ob ihr dieses Wiki-Projekt unterstützen könnt.</p>' +
'<p>Wir freuen uns sehr, dass dieses Projekt so gut angenommen wurde.</p>' +
'<p>Wir würden uns daher sehr freuen, wenn ihr anstatt uns, lieber das Projekt vom Whiskywaiter unterstützen würdet.</p>' +
'<p><strong>Jede Spende zählt!</strong></p>' +
// --- hier kommt die Video-Einbettung ---
'<div class="mw-popup-video" role="group" aria-label="Video: Whisky für den guten Zweck">' +
'<iframe ' +
'src="https://www.youtube-nocookie.com/embed/R6Ls3INs91Q?rel=0" ' +
'title="YouTube-Video: Whisky für den guten Zweck" ' +
'loading="lazy" ' +
'allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture; web-share" ' +
'allowfullscreen ' +
'referrerpolicy="strict-origin-when-cross-origin">' +
'</iframe>' +
// Fallback-Link, falls iframes blockiert sind
'<a class="mw-popup-video-fallback mw-ui-button" target="_blank" rel="noopener" href="https://www.youtube.com/watch?v=R6Ls3INs91Q">Video auf YouTube öffnen</a>' +
'</div>' +
// --- Ende Video ---
'<p><a href="https://www.kinderherzen.de/whisky-fuer-den-guten-zweck/" target="_blank" rel="noopener" class="mw-ui-button">Mehr erfahren</a></p>',
wikiButton: {
text: 'Mehr auf dem Wiki',
url: 'https://ados-wiki.de/index.php?title=Charity-Event_%E2%80%9EWhisky_f%C3%BCr_den_guten_Zweck%E2%80%9C_%E2%80%93_The_Whisky_Waiter'
},
showOnNamespaces: 'all',
dailyLimit: 1,
escToClose: true,
clickBackdropToClose: true
};
if (!CONFIG.enabled) return;
var ns = mw.config.get('wgNamespaceNumber');
if (CONFIG.showOnNamespaces !== 'all' &&
$.isArray(CONFIG.showOnNamespaces) &&
$.inArray(ns, CONFIG.showOnNamespaces) === -1) {
return;
}
var isAnon = mw.config.get('wgUserName') === null;
function storageGet(k){ try { return window.localStorage.getItem(k); } catch (e) { return null; } }
function storageSet(k,v){ try { window.localStorage.setItem(k, v); } catch (e) {} }
var key = 'popup_' + CONFIG.id + (isAnon ? ':anon' : ':user');
var today = (function(d){ return d.getFullYear() + '-' + ('0'+(d.getMonth()+1)).slice(-2) + '-' + ('0'+d.getDate()).slice(-2); })(new Date());
if (storageGet(key) === today) return;
function markSeen(){ storageSet(key, today); }
$(function () {
var $overlay = $('<div>', { 'class': 'mw-popup-overlay' });
var $modal = $('<div>', {
'class': 'mw-popup-modal',
'role': 'dialog',
'aria-modal': 'true',
'aria-labelledby': 'mw-popup-title'
});
var $logoWrap = $('<div>', { 'class': 'mw-popup-logo' })
.append($('<div>', { 'class': 'mw-popup-heart' }))
.append($('<img>', { src: CONFIG.logoUrl, alt: 'Kinderherzen Logo' }));
var $title = $('<h2>', { id: 'mw-popup-title' }).text(CONFIG.title);
var $content = $('<div>', { 'class': 'mw-popup-content' }).html(CONFIG.html);
var $btnOk = $('<button>', { 'class': 'mw-popup-close', type: 'button' }).text('OK');
var $btnWiki = $('<a>', {
'class': 'mw-popup-wiki-button',
'href': CONFIG.wikiButton.url,
'target': '_blank',
'rel': 'noopener'
}).text(CONFIG.wikiButton.text);
var $btnWrapper = $('<div>', { 'class': 'mw-popup-button-row' }).append($btnOk, $btnWiki);
$modal.append($logoWrap, $title, $content, $btnWrapper);
$('body').append($overlay, $modal);
// Fokus setzen
setTimeout(function(){ try { $modal.attr('tabindex','-1').focus(); } catch(e) {} }, 0);
function close() {
markSeen();
$overlay.remove();
$modal.remove();
$(document).off('keydown.mwpopup');
}
$btnOk.on('click', close);
if (CONFIG.clickBackdropToClose) $overlay.on('click', close);
if (CONFIG.escToClose) {
$(document).on('keydown.mwpopup', function (e) {
var key = e.key || e.keyCode;
if (key === 'Escape' || key === 'Esc' || key === 27) {
e.preventDefault();
close();
}
});
}
markSeen();
});
})(jQuery, mw);
});
// === Skript 2 ===
/* Sticky Charity Banner (v1) – MediaWiki */
mw.loader.using(['mediawiki.util', 'jquery']).then(function () {
(function ($, mw) {
'use strict';
var CONFIG = {
enabled: true,
id: 'charity_banner_v1',
text: '❤️ Unterstütze die Kinderherzen-Charity – Jede Spende zählt!',
primary: {
label: 'Mehr erfahren',
href: 'https://www.kinderherzen.de/whisky-fuer-den-guten-zweck/'
},
secondary: {
label: 'Mehr auf dem Wiki',
href: 'https://ados-wiki.de/index.php?title=Charity-Event_%E2%80%9EWhisky_f%C3%BCr_den_guten_Zweck%E2%80%9C_%E2%80%93_The_Whisky_Waiter'
},
showOnNamespaces: 'all',
endISO: null,
dismiss: { mode: 'day' },
zIndex: 10050
};
if (!CONFIG.enabled) return;
if (CONFIG.endISO && new Date() > new Date(CONFIG.endISO)) return;
var ns = mw.config.get('wgNamespaceNumber');
if (CONFIG.showOnNamespaces !== 'all' &&
$.isArray(CONFIG.showOnNamespaces) &&
$.inArray(ns, CONFIG.showOnNamespaces) === -1) {
return;
}
function getLS(k){ try { return localStorage.getItem(k); } catch(e){ return null; } }
function setLS(k,v){ try { localStorage.setItem(k,v); } catch(e){} }
var key = 'sticky_banner:' + CONFIG.id;
var today = (function(d){ return d.getFullYear()+'-'+('0'+(d.getMonth()+1)).slice(-2)+'-'+('0'+d.getDate()).slice(-2); })(new Date());
var dismissed = getLS(key);
if (CONFIG.dismiss.mode === 'forever' && dismissed) return;
if (CONFIG.dismiss.mode === 'day' && dismissed === today) return;
$(function () {
var $bar = $('<div>', {
'class': 'mw-sticky-banner',
'role': 'region',
'aria-label': 'Charity-Hinweis',
'style': 'z-index:' + CONFIG.zIndex + ';'
});
var $inner = $('<div>', { 'class': 'mw-sticky-banner__inner' });
var $text = $('<div>', { 'class': 'mw-sticky-banner__text', 'html': mw.html.escape(CONFIG.text) });
var $btns = $('<div>', { 'class': 'mw-sticky-banner__btns' });
if (CONFIG.primary && CONFIG.primary.href) {
$btns.append($('<a>', {
'class': 'mw-sticky-banner__btn mw-sticky-banner__btn--primary',
'href': CONFIG.primary.href,
'target': '_blank',
'rel': 'noopener'
}).text(CONFIG.primary.label || 'Mehr erfahren'));
}
if (CONFIG.secondary && CONFIG.secondary.href) {
$btns.append($('<a>', {
'class': 'mw-sticky-banner__btn mw-sticky-banner__btn--secondary',
'href': CONFIG.secondary.href
}).text(CONFIG.secondary.label || 'Mehr auf dem Wiki'));
}
var $close = $('<button>', {
'class': 'mw-sticky-banner__close',
'type': 'button',
'aria-label': 'Banner schließen'
}).text('×');
$inner.append($text, $btns, $close);
$bar.append($inner);
$('body').prepend($bar);
$('body').addClass('mw-sticky-banner-active');
function rememberDismiss() {
if (CONFIG.dismiss.mode === 'forever') { setLS(key, '1'); }
else if (CONFIG.dismiss.mode === 'day') { setLS(key, today); }
}
function close() {
rememberDismiss();
$bar.remove();
$('body').removeClass('mw-sticky-banner-active');
}
$close.on('click', close);
});
})(jQuery, mw);
});
/* ADOS Whisky-Ratings – RatePage Frontend (ES5, Widgets + Stats + Summary, Doppel-Init-Schutz; ANON VOTING ERLAUBT) */
mw.loader.using(['mediawiki.api', 'mediawiki.user']).then(function () {
// ---------- kleine Hilfsfunktion ----------
function get(obj, path) {
var cur = obj, i;
for (i = 0; i < path.length; i++) {
if (!cur || typeof cur !== 'object') return undefined;
cur = cur[path[i]];
}
return cur;
}
// ---------- Bootstrapping ----------
function boot(root) {
var scope = root || document;
var i, nodes;
nodes = scope.querySelectorAll('.whisky-rating__item');
for (i = 0; i < nodes.length; i++) setupWidget(nodes[i]);
initMetaOnly(scope);
nodes = scope.querySelectorAll('[data-ratepage-summary="true"]');
for (i = 0; i < nodes.length; i++) renderSummary(nodes[i]);
}
if (document.readyState === 'loading') {
document.addEventListener('DOMContentLoaded', function(){ boot(document); });
} else {
boot(document);
}
mw.hook('wikipage.content').add(function($content){
if ($content && $content[0]) boot($content[0]);
});
// ---------- Interaktives Widget ----------
function setupWidget(box) {
if (box.getAttribute('data-rating-init') === '1') return;
box.setAttribute('data-rating-init', '1');
var pageId = mw.config.get('wgArticleId');
var contest = box.dataset.ratepageContest || undefined;
var scale = parseInt(box.dataset.ratepageScale || '10', 10);
var widget = box.querySelector('.whisky-rating__widget');
var meta = box.querySelector('.whisky-rating__meta');
while (widget.firstChild) widget.removeChild(widget.firstChild);
// Anonyme NICHT blockieren – nur optionaler Hinweis
var isAnon = mw.user.isAnon();
if (isAnon && meta && !meta.textContent) {
meta.textContent = 'Bewerte diesen Whisky!';
}
var buttons = [];
var i;
for (i = 1; i <= scale; i++) {
(function(iVal){
var btn = document.createElement('button');
btn.type = 'button';
btn.className = 'whisky-glass';
btn.setAttribute('aria-label', iVal + ' von ' + scale);
btn.setAttribute('aria-pressed', 'false');
// Immer klickbar – egal ob anonym oder eingeloggt
btn.title = iVal + ' / ' + scale;
btn.addEventListener('mouseenter', function(){ highlight(iVal); });
btn.addEventListener('mouseleave', function(){ highlight(current); });
btn.addEventListener('click', function(){ vote(iVal); });
btn.addEventListener('keydown', function(e){
if (e.key === 'Enter' || e.key === ' ') { e.preventDefault(); vote(iVal); }
if (e.key === 'ArrowRight' && iVal < scale) buttons[iVal].focus();
if (e.key === 'ArrowLeft' && iVal > 1) buttons[iVal-2].focus();
});
widget.appendChild(btn);
buttons.push(btn);
})(i);
}
var current = 0;
highlight(current);
function highlight(n) {
var j;
for (j = 0; j < buttons.length; j++) {
var active = (j < n);
buttons[j].classList.toggle('is-active', active);
buttons[j].setAttribute('aria-pressed', active ? 'true' : 'false');
}
}
function updateStats() {
var api = new mw.Api();
api.get({
action: 'query',
prop: 'pagerating',
pageids: pageId,
prcontest: contest || undefined,
format: 'json',
errorformat: 'plaintext'
}).done(function (data) {
try {
var pages = get(data, ['query','pages']) || {};
var keys = []; for (var k in pages) if (Object.prototype.hasOwnProperty.call(pages, k)) keys.push(k);
var pid = keys.length ? keys[0] : String(pageId);
var page = pages[pid] || {};
var pr = page.pagerating;
if (!meta) return;
if (!pr) {
if (!meta.textContent) meta.textContent = 'Noch keine Bewertungen';
return;
}
if (typeof pr.canSee !== 'undefined' && pr.canSee === 0) {
meta.textContent = 'Bewertungen sind verborgen.';
} else {
var hist = pr.pageRating || {};
var total = 0, sum = 0;
for (var key in hist) {
if (Object.prototype.hasOwnProperty.call(hist, key)) {
var s = parseInt(key, 10), c = parseInt(hist[key], 10);
if (!isNaN(s) && !isNaN(c)) { total += c; sum += s * c; }
}
}
meta.textContent = total
? ('Ø ' + (Math.round((sum/total)*10)/10) + ' (' + total + ' Stimmen)')
: 'Noch keine Bewertungen';
}
if (pr.userVote) {
current = pr.userVote;
highlight(current);
}
if (typeof pr.canVote !== 'undefined' && pr.canVote === 0) {
// Serverseitig verboten → hier deaktivieren
box.classList.add('whisky-rating--disabled');
var gls = widget.querySelectorAll('.whisky-glass');
for (var i2 = 0; i2 < gls.length; i2++) gls[i2].disabled = true;
if (meta.textContent.indexOf('nicht abstimmen') === -1) {
meta.textContent += (meta.textContent ? ' • ' : '') + 'Du darfst hier nicht abstimmen.';
}
}
} catch (e) {
if (window.console && console.error) console.error(e);
if (meta && !meta.textContent) meta.textContent = 'Bewertungen konnten nicht geladen werden.';
}
}).fail(function (xhr) {
if (window.console && console.error) console.error('Pagerating-Load-Error', xhr);
if (meta && !meta.textContent) meta.textContent = 'Bewertungen konnten nicht geladen werden.';
});
}
function vote(value) {
var api = new mw.Api();
if (meta) meta.textContent = 'Wird gespeichert …';
var saved = false;
var failTimer = setTimeout(function () {
if (!saved && meta) meta.textContent = 'Speichern dauert ungewöhnlich lange … bitte Seite neu laden.';
}, 8000);
api.postWithToken('csrf', {
action: 'ratepage',
pageid: pageId,
answer: value,
contest: contest || undefined,
format: 'json'
}).done(function () {
saved = true;
clearTimeout(failTimer);
current = value;
highlight(current);
if (meta) meta.textContent = 'Danke! Deine Bewertung: ' + value + ' / ' + scale;
updateStats();
}).fail(function (xhr) {
clearTimeout(failTimer);
var msg = 'Unbekannter Fehler';
try {
var j = xhr && xhr.responseJSON ? xhr.responseJSON : xhr;
if (j && j.error) {
msg = (j.error.code ? j.error.code + ': ' : '') + (j.error.info || '');
}
} catch(e){}
if (window.console && console.error) console.error('RatePage-API-Fehler:', xhr);
if (meta) meta.textContent = 'Speichern fehlgeschlagen: ' + msg;
});
}
updateStats();
}
// ---------- Meta-only ----------
function initMetaOnly(scope) {
var root = scope || document;
var nodes = root.querySelectorAll('.whisky-rating__meta-only');
var i;
for (i = 0; i < nodes.length; i++) (function(box){
if (box.getAttribute('data-meta-init') === '1') return;
box.setAttribute('data-meta-init', '1');
var pageId = parseInt(box.dataset.ratepagePageid || mw.config.get('wgArticleId'), 10);
var contest = box.dataset.ratepageContest || undefined;
new mw.Api().get({
action: 'query',
prop: 'pagerating',
pageids: pageId,
prcontest: contest || undefined,
format: 'json'
}).done(function (data) {
var pages = get(data, ['query','pages']) || {};
var keys = []; for (var k in pages) if (Object.prototype.hasOwnProperty.call(pages,k)) keys.push(k);
var pid = keys.length ? keys[0] : String(pageId);
var pr = pages[pid] && pages[pid].pagerating;
if (!pr) { box.textContent = ''; return; }
if (typeof pr.canSee !== 'undefined' && pr.canSee === 0) { box.textContent = 'Bewertung verborgen'; return; }
var hist = pr.pageRating || {};
var total = 0, sum = 0;
for (var key in hist) {
if (Object.prototype.hasOwnProperty.call(hist, key)) {
var s = Number(key), c = Number(hist[key]);
if (s && c) { total += c; sum += s * c; }
}
}
box.textContent = total ? ('Ø ' + (Math.round((sum/total)*10)/10) + ' (' + total + ' Stimmen)') : 'Noch keine Bewertungen';
});
})(nodes[i]);
}
// ---------- Summary inkl. Gesamt + Balken ----------
function renderSummary(container) {
if (container.getAttribute('data-summary-init') === '1') return;
container.setAttribute('data-summary-init', '1');
var pageId = mw.config.get('wgArticleId');
var raw = container.dataset.ratepageContests || 'NASE,GESCHMACK,ABGANG';
var parts = raw.split(',');
var i;
for (i = 0; i < parts.length; i++) parts[i] = parts[i].replace(/^\s+|\s+$/g, '');
var nameToId = { 'nase':'NASE', 'geschmack':'GESCHMACK', 'abgang':'ABGANG', 'gesamteindruck':'GESAMTEINDRUCK' };
var contests = [];
var seen = {};
for (i = 0; i < parts.length; i++) {
var key = parts[i]; if (!key) continue;
var norm = key.toLowerCase();
var id = nameToId[norm] ? nameToId[norm] : key;
if (!seen[id]) { contests.push(id); seen[id] = true; }
}
var labels = { NASE: 'Nase', GESCHMACK: 'Geschmack', ABGANG: 'Abgang', GESAMTEINDRUCK: 'Gesamteindruck' };
container.textContent = 'Lade Bewertungen …';
function fetchContest(contest) {
return new mw.Api().get({
action: 'query',
prop: 'pagerating',
pageids: pageId,
prcontest: contest,
format: 'json',
errorformat: 'plaintext'
}).then(function (data) {
var pages = get(data, ['query','pages']) || {};
var keys = []; for (var k in pages) if (Object.prototype.hasOwnProperty.call(pages,k)) keys.push(k);
var pid = keys.length ? keys[0] : String(pageId);
var pr = pages[pid] && pages[pid].pagerating;
if (!pr || (typeof pr.canSee !== 'undefined' && pr.canSee === 0)) {
return { contest: contest, label: (labels[contest] || contest), avg: null, total: 0 };
}
var hist = pr.pageRating || {};
var total = 0, sum = 0;
for (var key in hist) {
if (Object.prototype.hasOwnProperty.call(hist, key)) {
var s = Number(key), c = Number(hist[key]);
if (s && c) { total += c; sum += s * c; }
}
}
var avg = total ? Math.round((sum / total) * 10) / 10 : null;
return { contest: contest, label: (labels[contest] || contest), avg: avg, total: total };
}, function () {
return { contest: contest, label: (labels[contest] || contest), avg: null, total: 0, _error: true };
});
}
var promises = [];
for (i = 0; i < contests.length; i++) promises.push(fetchContest(contests[i]));
Promise.all(promises).then(function (rows) {
if (!rows || !rows.length) {
container.textContent = 'Konnte Bewertungen nicht laden.';
return;
}
var table = document.createElement('table');
table.className = 'whisky-summary__table';
var thead = document.createElement('thead');
thead.innerHTML = '<tr><th>Kategorie</th><th>Ø</th><th>Stimmen</th></tr>';
table.appendChild(thead);
var tbody = document.createElement('tbody');
// Zeilen mit Balken
var r;
for (r = 0; r < rows.length; r++) {
var row = rows[r];
var totalText = row.total ? String(row.total) : '0';
var tr = document.createElement('tr');
var tdLabel = document.createElement('td');
tdLabel.textContent = row.label;
tr.appendChild(tdLabel);
var tdAvg = document.createElement('td');
if (row.avg !== null) {
var wrap = document.createElement('div'); wrap.className = 'whisky-bar';
var track = document.createElement('div'); track.className = 'whisky-bar__track';
var fill = document.createElement('div'); fill.className = 'whisky-bar__fill';
fill.style.width = Math.max(0, Math.min(100, (row.avg/10)*100)) + '%';
var val = document.createElement('span'); val.className = 'whisky-bar__value';
val.textContent = (row.avg.toFixed ? row.avg.toFixed(1) : (Math.round(row.avg*10)/10));
track.appendChild(fill); wrap.appendChild(track); wrap.appendChild(val); tdAvg.appendChild(wrap);
} else {
tdAvg.textContent = '–';
}
tr.appendChild(tdAvg);
var tdCnt = document.createElement('td');
tdCnt.textContent = totalText;
tr.appendChild(tdCnt);
tbody.appendChild(tr);
}
// Gesamt
var present = 0, sumAvg = 0, totalVotes = 0;
for (r = 0; r < rows.length; r++) {
if (rows[r].avg !== null) { present++; sumAvg += rows[r].avg; }
if (rows[r].total) totalVotes += rows[r].total;
}
var overall = (present > 0) ? Math.round((sumAvg / present) * 10) / 10 : null;
var overallText = (overall !== null)
? (overall.toFixed ? overall.toFixed(1) : (Math.round(overall*10)/10))
: '–';
var trG = document.createElement('tr');
var tdGL = document.createElement('td');
tdGL.innerHTML = '<strong>Gesamt</strong>';
trG.appendChild(tdGL);
var tdGA = document.createElement('td');
if (overall !== null) {
var w = document.createElement('div'); w.className = 'whisky-bar';
var t = document.createElement('div'); t.className = 'whisky-bar__track';
var f = document.createElement('div'); f.className = 'whisky-bar__fill';
f.style.width = Math.max(0, Math.min(100, (overall/10)*100)) + '%';
var v = document.createElement('span'); v.className = 'whisky-bar__value';
v.innerHTML = '<strong>' + overallText + '</strong>';
t.appendChild(f); w.appendChild(t); w.appendChild(v); tdGA.appendChild(w);
} else {
tdGA.innerHTML = '<strong>–</strong>';
}
trG.appendChild(tdGA);
var tdGD = document.createElement('td');
tdGD.textContent = totalVotes;
trG.appendChild(tdGD);
tbody.appendChild(trG);
table.appendChild(tbody);
while (container.firstChild) container.removeChild(container.firstChild);
container.appendChild(table);
var badge = document.getElementById('whisky-overall-badge');
if (badge && overall !== null) {
badge.textContent = overallText;
}
}).catch(function(){
container.textContent = 'Konnte Bewertungen nicht geladen werden.';
});
}
});