MediaWiki:Common.js: Unterschied zwischen den Versionen

Keine Bearbeitungszusammenfassung
Keine Bearbeitungszusammenfassung
Zeile 739: Zeile 739:
// -------------------------------------
// -------------------------------------


/* Whisky News Popup mit Slàinte mhath Animation (v6) */
/* Whisky News Popup Slàinte + Whiskyglas – SAFE MODE (v7)
  - self-contained: injiziert eigene CSS, hohe z-index, robustes Canvas-Sizing
  - News + 2 Karten bleiben erhalten
  - Fallback: statisches SVG bei reduced-motion/kein Canvas
*/
mw.loader.using(['mediawiki.util','jquery']).then(function(){
mw.loader.using(['mediawiki.util','jquery']).then(function(){
   (function($, mw){
   (function($, mw){
Zeile 746: Zeile 750:
     var CONFIG = {
     var CONFIG = {
       enabled: true,
       enabled: true,
       id: 'wow_mannheim_whisky_news_v6',
       id: 'wow_mannheim_whisky_news_v7', // bei Änderungen erhöhen (Cache/LS reset)
       title: 'Whisky News: Messeabfüllungen – World of Whisky (Mannheim)',
       title: 'Whisky News: Messeabfüllungen – World of Whisky (Mannheim)',
       introHTML: '<p>Frisch zur Messe in Mannheim: Zwei limitierte Abfüllungen. Schau sie dir an und bewerte sie im Wiki!</p>',
       introHTML: '<p>Frisch zur Messe in Mannheim: Zwei limitierte Abfüllungen. Schau sie dir an und bewerte sie im Wiki!</p>',
       images: [
       images: [
         {
        // >>> Falls du echte Datei-URLs hast, hier einsetzen:
          src: 'https://ados-wiki.de/images/2/2f/South_Islay_Single_Malt_13_year-old_%28Sherry_Octave_Cask_Finish%29.single.jpg',
         { src: 'https://ados-wiki.de/images/2/2f/South_Islay_Single_Malt_13_year-old_%28Sherry_Octave_Cask_Finish%29.single.jpg',
           alt: 'South Islay 13y – Sherry Octave Cask Finish',
           alt: 'South Islay 13y – Sherry Octave Cask Finish',
           link: 'https://ados-wiki.de/wiki/South_Islay_Single_Malt_13_year-old_(Sherry_Octave_Cask_Finish)',
           link: 'https://ados-wiki.de/wiki/South_Islay_Single_Malt_13_year-old_(Sherry_Octave_Cask_Finish)',
           cta: 'Zur South Islay Abfüllung'
           cta: 'Zur South Islay Abfüllung' },
        },
         { src: 'https://ados-wiki.de/images/9/95/Tullibardine_13_year-old_%28Shiraz_Wine_Octave_Cask_Finish%29.single.jpg',
         {
          src: 'https://ados-wiki.de/images/9/95/Tullibardine_13_year-old_%28Shiraz_Wine_Octave_Cask_Finish%29.single.jpg',
           alt: 'Tullibardine 13y – Shiraz Wine Octave Cask Finish',
           alt: 'Tullibardine 13y – Shiraz Wine Octave Cask Finish',
           link: 'https://ados-wiki.de/wiki/Tullibardine_13_year-old',
           link: 'https://ados-wiki.de/wiki/Tullibardine_13_year-old',
           cta: 'Zur Tullibardine Abfüllung'
           cta: 'Zur Tullibardine Abfüllung' }
        }
       ],
       ],
       toastText: 'Slàinte mhath',
       toastText: 'Slàinte mhath',
Zeile 771: Zeile 772:
     if (!CONFIG.enabled) return;
     if (!CONFIG.enabled) return;


     // === LocalStorage: nur 1x pro Tag ===
     /* ---------- HARDENED CSS INJECTION ---------- */
    (function injectCSS(){
      var css = `
:root{--mw-news-z:2147483000;}
.mw-news7-overlay{position:fixed;inset:0;background:rgba(0,0,0,.45);z-index:var(--mw-news-z);}
.mw-news7-modal{position:fixed;top:50%;left:50%;transform:translate(-50%,-50%);background:#fff;
  max-width:96%;width:720px;padding:22px 26px 26px;border-radius:14px;z-index:calc(var(--mw-news-z) + 1);
  text-align:center;box-shadow:0 10px 28px rgba(0,0,0,.35);max-height:94vh;overflow-y:auto;}
.mw-news7-stage{position:relative;height:300px;margin:-6px -6px 12px;border-radius:10px;overflow:hidden;
  background:radial-gradient(ellipse at center,#0b1c38 0%,#061025 60%,#03060d 100%);box-shadow:inset 0 0 30px rgba(0,0,0,.65);}
.mw-news7-canvas{display:block;width:100%;height:100%;}
.mw-news7-toast{font:700 clamp(20px,4.2vw,36px)/1.15 "Segoe UI",Roboto,Arial,sans-serif;color:#fff;
  background:linear-gradient(0deg,#ffc76a,#fff);-webkit-background-clip:text;background-clip:text;
  -webkit-text-fill-color:transparent;text-shadow:0 0 18px rgba(255,200,120,.35);margin:6px 0 2px;opacity:0;
  transform:translateY(8px) scale(.98);animation:mwnews7-in .9s ease-out forwards,mwnews7-glow 3.5s ease-in-out .9s infinite;}
@keyframes mwnews7-in{0%{opacity:0;transform:translateY(12px) scale(.98);filter:blur(2px);}
  60%{opacity:1;transform:translateY(0) scale(1);filter:blur(0);}100%{opacity:1;transform:translateY(0) scale(1);}}
@keyframes mwnews7-glow{0%,100%{text-shadow:0 0 12px rgba(255,200,120,.25),0 0 0 rgba(255,255,255,0);}
  50%{text-shadow:0 0 22px rgba(255,200,120,.5),0 0 6px rgba(255,255,255,.25);}}
.mw-news7-cards{display:flex;gap:10px;flex-wrap:wrap;justify-content:center;}
.mw-news7-card{display:block;width:300px;text-decoration:none;color:#000;border-radius:8px;overflow:hidden;
  box-shadow:0 3px 8px rgba(0,0,0,.15);transition:transform .2s,box-shadow .2s;}
.mw-news7-card:hover{transform:translateY(-3px);box-shadow:0 8px 18px rgba(0,0,0,.18);}
.mw-news7-thumb img{width:100%;height:200px;object-fit:cover;display:block;}
.mw-news7-meta{padding:8px;}
.mw-news7-title{font-weight:600;margin-bottom:4px;}
.mw-news7-cta{color:#36c;font-size:.9em;}
.mw-news7-btnrow{display:flex;justify-content:center;margin-top:12px;}
.mw-news7-close{padding:10px 16px;border:0;background:#36c;color:#fff;border-radius:6px;cursor:pointer;font-size:1em;}
.mw-news7-close:hover{background:#258;}
@media (max-width:600px){
  .mw-news7-modal{width:calc(100% - 20px);padding:16px;}
  .mw-news7-stage{height:240px;margin:-4px -4px 10px;}
  .mw-news7-card{width:100%;}
  .mw-news7-thumb img{height:220px;object-fit:contain;background:#000;}
}
@media (prefers-reduced-motion:reduce){.mw-news7-toast{animation:none;opacity:1;transform:none;}}
      `;
      var el = document.createElement('style'); el.className = 'mw-news7-style';
      el.textContent = css; document.head.appendChild(el);
    })();
 
    /* ---------- DAILY LIMIT ---------- */
     var isAnon = (mw.config.get('wgUserName') === null);
     var isAnon = (mw.config.get('wgUserName') === null);
     function LSget(k){ try { return localStorage.getItem(k); } catch(e){ return null; } }
     function LSget(k){ try { return localStorage.getItem(k); } catch(e){ return null; } }
Zeile 781: Zeile 824:


     $(function(){
     $(function(){
       // === Popup Grundstruktur ===
       /* ---------- BUILD DOM ---------- */
       var $overlay = $('<div>', {'class':'mw-popup-overlay'});
       var $overlay = $('<div>', {'class':'mw-news7-overlay'});
       var $modal = $('<div>', {'class':'mw-popup-modal','role':'dialog','aria-modal':'true'});
       var $modal   = $('<div>', {'class':'mw-news7-modal','role':'dialog','aria-modal':'true','aria-label':'Whisky News Popup'});


       var $stage = $('<div>', {'class':'mw-fw-canvas-wrap'});
       var $stage   = $('<div>', {'class':'mw-news7-stage'});
       var $canvas = $('<canvas>', {'class':'mw-fw-canvas','aria-hidden':'true'});
       var $canvas = $('<canvas>', {'class':'mw-news7-canvas','aria-hidden':'true'});
       $stage.append($canvas);
       $stage.append($canvas);


       var $toast = $('<div>', {'class':'mw-slainte-toast'}).text(CONFIG.toastText);
       var $toast   = $('<div>', {'class':'mw-news7-toast'}).text(CONFIG.toastText);
      var $title = $('<h2>').text(CONFIG.title);
      var $intro = $('<div>', {'class':'mw-popup-content'}).html(CONFIG.introHTML);


       // === Karten ===
       var $title  = $('<h2>').text(CONFIG.title);
       var $cards = $('<div>', {'class':'mw-wnews-cards'});
      var $intro  = $('<div>').html(CONFIG.introHTML);
 
       var $cards   = $('<div>', {'class':'mw-news7-cards'});
       CONFIG.images.forEach(function(img){
       CONFIG.images.forEach(function(img){
         var $card = $('<a>', {'class':'mw-wnews-card','href':img.link,'target':'_blank','rel':'noopener'});
         var $card = $('<a>', {'class':'mw-news7-card','href':img.link,'target':'_blank','rel':'noopener'});
         var $thumb = $('<div>', {'class':'mw-wnews-thumb'});
         var $thumb = $('<div>', {'class':'mw-news7-thumb'});
         if (img.src) $thumb.append($('<img>', {src: img.src, alt: img.alt, loading:'lazy'}));
         if (img.src) $thumb.append($('<img>', {src: img.src, alt: img.alt || ''}));
         $card.append(
         $card.append($thumb,
          $thumb,
           $('<div>', {'class':'mw-news7-meta'}).append(
           $('<div>', {'class':'mw-wnews-meta'}).append(
             $('<div>', {'class':'mw-news7-title', text: img.alt || 'Mehr'}),
             $('<div>', {'class':'mw-wnews-title', text: img.alt}),
             $('<div>', {'class':'mw-news7-cta', text: img.cta || 'Ansehen'})
             $('<div>', {'class':'mw-wnews-cta', text: img.cta || 'Mehr ansehen'})
           ));
           )
        );
         $cards.append($card);
         $cards.append($card);
       });
       });


      // === Button ===
       var $btnRow = $('<div>', {'class':'mw-news7-btnrow'});
       var $btnRow = $('<div>', {'class':'mw-popup-button-row'});
       var $ok     = $('<button>', {'class':'mw-news7-close', type:'button'}).text('OK');
       var $ok = $('<button>', {'class':'mw-popup-close', type:'button'}).text('OK');
       $btnRow.append($ok);
       $btnRow.append($ok);


      // === Zusammenbauen ===
       $modal.append($stage, $toast, $title, $intro, $cards, $btnRow);
       $modal.append($stage, $toast, $title, $intro, $cards, $btnRow);
       $('body').append($overlay, $modal);
       $('body').append($overlay, $modal);


      // === Schließen ===
       function close(){
       function close(){
         stopAnim(true);
         stopAnim(true);
         markSeen();
         markSeen();
         $overlay.remove(); $modal.remove();
         $overlay.remove(); $modal.remove();
         $(document).off('keydown.mwwnews visibilitychange');
         $(document).off('keydown.mwnews7 visibilitychange');
       }
       }
       if (CONFIG.clickBackdropToClose) $overlay.on('click', close);
       if (CONFIG.clickBackdropToClose) $overlay.on('click', close);
       $ok.on('click', close);
       $ok.on('click', close);
       if (CONFIG.escToClose){
       if (CONFIG.escToClose){
         $(document).on('keydown.mwwnews', function(e){
         $(document).on('keydown.mwnews7', function(e){
           var k = e.key || e.keyCode;
           var k = e.key || e.keyCode;
           if (k==='Escape' || k==='Esc' || k===27){ e.preventDefault(); close(); }
           if (k==='Escape' || k==='Esc' || k===27){ e.preventDefault(); close(); }
Zeile 834: Zeile 872:
       }
       }


       // === Canvas Whiskyglas Animation ===
       /* ---------- CANVAS ANIMATION (robust) ---------- */
       var canvas = $canvas[0], ctx = canvas.getContext && canvas.getContext('2d');
       var canvas = $canvas[0], ctx = canvas.getContext && canvas.getContext('2d');
       var reduce = window.matchMedia && window.matchMedia('(prefers-reduced-motion: reduce)').matches;
       var reduce = window.matchMedia && window.matchMedia('(prefers-reduced-motion: reduce)').matches;
Zeile 858: Zeile 896:
         glass.x=w*0.18; glass.y=h*0.15; glass.w=w*0.64; glass.h=h*0.7;
         glass.x=w*0.18; glass.y=h*0.15; glass.w=w*0.64; glass.h=h*0.7;
         glass.r=Math.min(glass.w,glass.h)*0.08;
         glass.r=Math.min(glass.w,glass.h)*0.08;
         baseFill=glass.y+glass.h*0.58; amp=Math.min(14*dpr,canvas.height*0.03);
         baseFill=glass.y+glass.h*0.58;
        amp=Math.min(14*dpr, canvas.height*0.03);
       }
       }


Zeile 872: Zeile 911:
         ctx.arcTo(glass.x,glass.y,glass.x+glass.w,glass.y,glass.r);
         ctx.arcTo(glass.x,glass.y,glass.x+glass.w,glass.y,glass.r);
         ctx.closePath(); ctx.stroke();
         ctx.closePath(); ctx.stroke();
        // Glanz
         ctx.beginPath();
         ctx.beginPath();
         ctx.moveTo(glass.x+glass.w*0.15,glass.y+glass.h*0.1);
         ctx.moveTo(glass.x+glass.w*0.15,glass.y+glass.h*0.1);
         ctx.quadraticCurveTo(glass.x+glass.w*0.25,glass.y+glass.h*0.05,glass.x+glass.w*0.3,glass.y+glass.h*0.3);
         ctx.quadraticCurveTo(glass.x+glass.w*0.25,glass.y+glass.h*0.05,glass.x+glass.w*0.3,glass.y+glass.h*0.3);
         ctx.strokeStyle='rgba(255,255,255,0.18)'; ctx.stroke(); ctx.restore();
         ctx.strokeStyle='rgba(255,255,255,0.18)'; ctx.stroke();
        ctx.restore();
       }
       }


       function drawLiquid(t){
       function drawLiquid(t){
         var topY=baseFill+Math.sin(t*2.0)*amp*0.25+Math.sin(t*0.7)*amp*0.15;
         var topY = baseFill + Math.sin(t*2.0)*amp*0.25 + Math.sin(t*0.7)*amp*0.15;
 
        // Clip ins Glas
         ctx.save();
         ctx.save();
         ctx.beginPath();
         ctx.beginPath();
Zeile 888: Zeile 931:
         ctx.arcTo(glass.x,glass.y,glass.x+glass.w,glass.y,glass.r);
         ctx.arcTo(glass.x,glass.y,glass.x+glass.w,glass.y,glass.r);
         ctx.closePath(); ctx.clip();
         ctx.closePath(); ctx.clip();
         var grd=ctx.createLinearGradient(0,topY-30*dpr,0,glass.y+glass.h);
 
         grd.addColorStop(0,'rgba(255,190,90,0.96)');
        // Whisky (Wellen-Path)
         grd.addColorStop(1,'rgba(170,85,20,0.98)');
         var grd = ctx.createLinearGradient(0, topY-30*dpr, 0, glass.y+glass.h);
         grd.addColorStop(0, 'rgba(255,190,90,0.96)');
         grd.addColorStop(1, 'rgba(170,85,20,0.98)');
         ctx.beginPath();
         ctx.beginPath();
         ctx.moveTo(glass.x,topY);
         ctx.moveTo(glass.x, topY);
         for(var x=0;x<=glass.w;x+=6*dpr){
         for (var x=0; x<=glass.w; x+=6*dpr){
           var y=topY+Math.sin((x*0.055)+t*3.6)*amp*0.22;
           var y=topY+Math.sin((x*0.055)+t*3.6)*amp*0.22;
           ctx.lineTo(glass.x+x,y);
           ctx.lineTo(glass.x+x,y);
Zeile 901: Zeile 946:
         ctx.closePath();
         ctx.closePath();
         ctx.fillStyle=grd; ctx.fill();
         ctx.fillStyle=grd; ctx.fill();
        // Lichtsaum
         ctx.beginPath();
         ctx.beginPath();
         ctx.moveTo(glass.x,topY);
         ctx.moveTo(glass.x, topY);
         for(var x2=0;x2<=glass.w;x2+=6*dpr){
         for (var x2=0; x2<=glass.w; x2+=6*dpr){
           var y2=topY+Math.sin((x2*0.055)+t*3.6)*amp*0.22;
           var y2=topY+Math.sin((x2*0.055)+t*3.6)*amp*0.22;
           ctx.lineTo(glass.x+x2,y2);
           ctx.lineTo(glass.x+x2,y2);
         }
         }
         ctx.strokeStyle='rgba(255,215,120,0.35)';
         ctx.strokeStyle='rgba(255,215,120,0.35)';
         ctx.lineWidth=Math.max(1,1*dpr); ctx.stroke();
         ctx.lineWidth=Math.max(1,1*dpr);
        ctx.stroke();
 
         ctx.restore();
         ctx.restore();
       }
       }


       function frame(ts){
       function frame(ts){
         if(!t0) t0=ts;
         if(!t0) t0 = ts;
         var t=(ts-t0)/1000;
         var t = (ts - t0)/1000;
 
        // Hintergrund
         ctx.globalCompositeOperation='source-over';
         ctx.globalCompositeOperation='source-over';
         ctx.fillStyle='rgba(5,10,20,0.16)';
         ctx.fillStyle='rgba(5,10,20,0.16)';
         ctx.fillRect(0,0,canvas.width,canvas.height);
         ctx.fillRect(0,0,canvas.width,canvas.height);
         drawGlass(); drawLiquid(t);
 
         drawGlass();
        drawLiquid(t);
 
        // Randglanz
         ctx.save();
         ctx.save();
         ctx.globalCompositeOperation='lighter';
         ctx.globalCompositeOperation='lighter';
Zeile 925: Zeile 980:
         ctx.beginPath();
         ctx.beginPath();
         ctx.arc(glass.x+glass.w*0.85,glass.y+glass.h*0.15,10*dpr,0,Math.PI*2);
         ctx.arc(glass.x+glass.w*0.85,glass.y+glass.h*0.15,10*dpr,0,Math.PI*2);
         ctx.stroke(); ctx.restore();
         ctx.stroke();
         raf=requestAnimationFrame(frame);
        ctx.restore();
 
         raf = requestAnimationFrame(frame);
       }
       }


       function startAnim(){
       function startAnim(){
         if(!ctx||reduce)return;
        var reduceMotion = window.matchMedia && window.matchMedia('(prefers-reduced-motion: reduce)').matches;
         if(!setSize()){setTimeout(startAnim,50);return;}
         if (!ctx || reduceMotion){
         if(started)return;
          // Fallback: statisches SVG in die Bühne
         started=true;t0=0;
          $stage.html(
         raf=requestAnimationFrame(frame);
            '<svg viewBox="0 0 600 300" class="mw-news7-fallback" xmlns="http://www.w3.org/2000/svg">'+
         if('ResizeObserver'in window){
            '<defs><linearGradient id="whisky" x1="0" y1="0" x2="0" y2="1">'+
           ro=new ResizeObserver(function(){setSize();});
            '<stop offset="0%" stop-color="#FFBE5A"/><stop offset="100%" stop-color="#AA5514"/></linearGradient></defs>'+
            '<rect x="108" y="45" width="384" height="210" rx="20" ry="20" fill="none" stroke="rgba(255,255,255,0.35)" stroke-width="4"/>'+
            '<rect x="108" y="150" width="384" height="105" rx="20" ry="20" fill="url(#whisky)"/></svg>'
          );
          return;
        }
         if (!setSize()){ setTimeout(startAnim, 50); return; }
         if (started) return;
         started = true; t0 = 0;
         raf = requestAnimationFrame(frame);
 
         if ('ResizeObserver' in window){
           ro = new ResizeObserver(function(){ setSize(); });
           ro.observe($stage[0]);
           ro.observe($stage[0]);
         }else{$(window).on('resize.mwwnews',setSize);}
         } else {
         document.addEventListener('visibilitychange',onVis);
          $(window).on('resize.mwnews7', setSize);
        }
         document.addEventListener('visibilitychange', onVis);
       }
       }
       function stopAnim(remove){
       function stopAnim(remove){
         if(raf){cancelAnimationFrame(raf);raf=null;}
         if (raf){ cancelAnimationFrame(raf); raf=null; }
         started=false;
         started=false;
         if(remove){
         if (remove){
           if(ro){ro.disconnect();ro=null;}else{$(window).off('resize.mwwnews');}
           if (ro){ ro.disconnect(); ro=null; } else { $(window).off('resize.mwnews7'); }
           document.removeEventListener('visibilitychange',onVis);
           document.removeEventListener('visibilitychange', onVis);
         }
         }
       }
       }
       function onVis(){if(document.hidden)stopAnim(false);else startAnim();}
       function onVis(){ if (document.hidden) stopAnim(false); else startAnim(); }
       setTimeout(startAnim,0);
 
      // Start
       setTimeout(startAnim, 0);
       markSeen();
       markSeen();
     });
     });
   })(jQuery,mw);
   })(jQuery, mw);
});
});