PageSourceSearch

https://www.cronachedellacampania.it/wp-content/plugins/sv-news2-slider/assets/sv-news2-slider.js?ver=1.5.3

js cronachedellacampania.it collected 2026-09-24 09:59:49 UTC 9,684 bytes, 78 lines download raw bytes

1(function(){
2  'use strict';
3  var imaPromise=null;
4  function loadIma(){
5    if(window.google&&window.google.ima) return Promise.resolve(window.google.ima);
6    if(imaPromise) return imaPromise;
7    imaPromise=new Promise(function(resolve,reject){
8      var old=document.getElementById('sv-news2-ima-sdk');
9      if(old){old.addEventListener('load',function(){resolve(window.google&&window.google.ima)}, {once:true});old.addEventListener('error',reject,{once:true});return;}
10      var s=document.createElement('script');s.id='sv-news2-ima-sdk';s.async=true;s.src='https://imasdk.googleapis.com/js/sdkloader/ima3.js';
11      s.onload=function(){window.google&&window.google.ima?resolve(window.google.ima):reject(new Error('IMA unavailable'));};s.onerror=reject;document.head.appendChild(s);
12    });
13    return imaPromise;
14  }
15
16  function playVast(root,slide,video,onAdState){
17    if(root.getAttribute('data-vast-enabled')!=='1'||video.dataset.svNews2VastRequested==='1') return;
18    video.dataset.svNews2VastRequested='1';
19    var primary=root.getAttribute('data-vast-primary')||'', fallback=root.getAttribute('data-vast-fallback')||'';
20    var tags=[]; if(primary)tags.push(primary); if(fallback&&fallback!==primary)tags.push(fallback); if(!tags.length)return;
21    var notice=document.createElement('div');notice.className='sv-news2__vast-search';notice.innerHTML='<i></i><span>Ricerca pubblicità…</span>';slide.querySelector('.sv-news2__media').appendChild(notice);
22    loadIma().then(function(ima){
23      if(!ima){notice.remove();return;}
24      var idx=0, manager=null, loader=null, display=null, slot=null, badge=null, watchdog=0, countdown=0, adStarted=false, finished=false, resumeTime=video.currentTime||0, wasMuted=video.muted, oldVolume=video.volume;
25      function timers(){clearTimeout(watchdog);clearInterval(countdown);}
26      function destroy(){timers();try{if(manager)manager.destroy();}catch(e){}manager=loader=display=null;}
27      function clean(){notice.remove();if(slot)slot.remove();if(badge)badge.remove();slide.classList.remove('is-vast-playing');onAdState(false);}
28      function resume(){if(finished)return;finished=true;destroy();clean();if(adStarted){try{video.currentTime=resumeTime;}catch(e){}video.muted=wasMuted;video.volume=oldVolume;}if(slide.isConnected)video.play().catch(function(){});}
29      function next(){destroy();if(slot)slot.remove();slot=null;if(badge)badge.remove();badge=null;adStarted=false;idx++;if(idx<tags.length)request();else resume();}
30      function count(){countdown=setInterval(function(){if(!manager||!badge)return;var left=0;try{left=Math.max(0,Math.ceil(manager.getRemainingTime()));}catch(e){}badge.textContent=left?'Pubblicità · '+left+' s':'Pubblicità';},500);}
31      function request(){
32        if(finished||!tags[idx])return resume();
33        slot=document.createElement('div');slot.className='sv-news2__ima-slot';slot.hidden=true;slide.querySelector('.sv-news2__media').appendChild(slot);
34        try{
35          display=new ima.AdDisplayContainer(slot,video);try{display.initialize();}catch(e){}
36          loader=new ima.AdsLoader(display);
37          loader.addEventListener(ima.AdErrorEvent.Type.AD_ERROR,function(){adStarted?resume():next();},false);
38          loader.addEventListener(ima.AdsManagerLoadedEvent.Type.ADS_MANAGER_LOADED,function(ev){
39            try{
40              manager=ev.getAdsManager(video);
41              manager.addEventListener(ima.AdErrorEvent.Type.AD_ERROR,function(){adStarted?resume():next();});
42              manager.addEventListener(ima.AdEvent.Type.STARTED,function(){
43                timers();adStarted=true;resumeTime=video.currentTime||0;wasMuted=video.muted;oldVolume=video.volume;video.pause();slot.hidden=false;slide.classList.add('is-vast-playing');onAdState(true);notice.remove();badge=document.createElement('div');badge.className='sv-news2__vast-badge';badge.textContent='Pubblicità';slide.querySelector('.sv-news2__media').appendChild(badge);count();
44              });
45              manager.addEventListener(ima.AdEvent.Type.CONTENT_RESUME_REQUESTED,function(){adStarted?resume():next();});
46              manager.addEventListener(ima.AdEvent.Type.ALL_ADS_COMPLETED,function(){adStarted?resume():next();});
47              var r=slide.querySelector('.sv-news2__media').getBoundingClientRect(),w=Math.max(320,Math.round(r.width||640)),h=Math.max(180,Math.round(r.height||360));
48              manager.init(w,h,ima.ViewMode.NORMAL);manager.start();
49            }catch(e){next();}
50          },false);
51          var r=slide.querySelector('.sv-news2__media').getBoundingClientRect(),req=new ima.AdsRequest();req.adTagUrl=tags[idx];req.linearAdSlotWidth=Math.max(320,Math.round(r.width||640));req.linearAdSlotHeight=Math.max(180,Math.round(r.height||360));req.nonLinearAdSlotWidth=req.linearAdSlotWidth;req.nonLinearAdSlotHeight=req.linearAdSlotHeight;if(req.setAdWillAutoPlay)req.setAdWillAutoPlay(false);
51if(req.setAdWillPlayMuted)req.setAdWillPlayMuted(video.muted);loader.requestAds(req);watchdog=setTimeout(function(){if(!adStarted)next();},9000);
52        }catch(e){next();}
53      }
54      request();
55    }).catch(function(){notice.remove();});
56  }
57
58  function boot(root){
59    if(!root||root.dataset.svNews2Ready==='1') return;
60    root.dataset.svNews2Ready='1';
61    var slides=[].slice.call(root.querySelectorAll('.sv-news2__slide'));
62    var dots=[].slice.call(root.querySelectorAll('.sv-news2__dots button'));
63    var prev=root.querySelector('.sv-news2__prev'), next=root.querySelector('.sv-news2__next');
64    var index=0,timer=null,delay=parseInt(root.getAttribute('data-autoplay')||'0',10),hovered=false,videoPlaying=false,adPlaying=false;
65    function fitTitles(){slides.forEach(function(s){var title=s.querySelector('.sv-news2__title'),wrap=s.querySelector('.sv-news2__textwrap'),content=s.querySelector('.sv-news2__content');if(!title||!wrap||!content)return;title.style.fontSize='';var compactMode=root.classList.contains('sv-news2--compact'),max=compactMode?32:46,min=compactMode?18:24,len=(title.textContent||'').trim().length,start=max;if(len>95)start-=4;if(len>130)start-=4;if(len>170)start-=3;title.style.fontSize=start+'px';var room=Math.max(90,content.clientHeight-50),size=start;while(wrap.scrollHeight>room&&size>min){size-=1;
65title.style.fontSize=size+'px';}});}
66    function compact(){root.classList.toggle('sv-news2--compact',root.getBoundingClientRect().width<=720);requestAnimationFrame(fitTitles);}compact();if(window.ResizeObserver){new ResizeObserver(compact).observe(root);}else{window.addEventListener('resize',compact,{passive:true});}
67    function pauseVideos(except){slides.forEach(function(s,i){if(i!==except){var v=s.querySelector('video');if(v&&!v.paused)v.pause();}});}
68    function restart(){if(timer){clearInterval(timer);timer=null;}if(delay>0&&!hovered&&!videoPlaying&&!adPlaying&&slides.length>1)timer=setInterval(function(){show(index+1);},delay);}
69    function show(n){if(!slides.length||adPlaying)return;index=(n+slides.length)%slides.length;slides.forEach(function(s,i){var on=i===index;s.classList.toggle('is-active',on);s.setAttribute('aria-hidden',on?'false':'true');});dots.forEach(function(d,i){d.classList.toggle('is-active',i===index);});pauseVideos(index);requestAnimationFrame(fitTitles);restart();}
70    if(prev)prev.addEventListener('click',function(e){e.preventDefault();show(index-1);});if(next)next.addEventListener('click',function(e){e.preventDefault();show(index+1);});dots.forEach(function(d){d.addEventListener('click',function(){show(parseInt(d.getAttribute('data-goto'),10)||0);});});root.addEventListener('mouseenter',function(){hovered=true;restart();});root.addEventListener('mouseleave',function(){hovered=false;restart();});
71    root.querySelectorAll('video').forEach(function(v){var slide=v.closest('.sv-news2__slide'),playBtn=slide?slide.querySelector('.sv-news2__play-overlay'):null;if(playBtn){playBtn.addEventListener('click',function(e){e.preventDefault();e.stopPropagation();if(root.getAttribute('data-vast-enabled')==='1')loadIma().catch(function(){});v.play().catch(function(){});});}v.addEventListener('pointerdown',function(){if(root.getAttribute('data-vast-enabled')==='1')loadIma().catch(function(){});},{passive:true});v.addEventListener('play',function(){videoPlaying=true;if(slide)slide.classList.add('is-video-playing');restart();if(slide)playVast(root,slide,v,function(on){adPlaying=on;restart();});});v.addEventListener('pause',function(){if(!adPlaying){videoPlaying=false;if(slide)slide.classList.remove('is-video-playing');}restart();});v.addEventListener('ended',function(){videoPlaying=false;if(slide)slide.classList.remove('is-video-playing');if(!adPlaying)show(index+1);});});
72    var sx=0,sy=0;root.addEventListener('touchstart',function(e){if(e.touches.length===1){sx=e.touches[0].clientX;sy=e.touches[0].clientY;}},{passive:true});root.addEventListener('touchend',function(e){if(adPlaying||!e.changedTouches.length)return;var t=e.changedTouches[0],dx=t.clientX-sx,dy=t.clientY-sy;if(Math.abs(dx)>55&&Math.abs(dx)>Math.abs(dy))show(index+(dx<0?1:-1));},{passive:true});restart();
73  }
74  function init(ctx){(ctx||document).querySelectorAll('.sv-news2').forEach(boot);}
75  if(document.readyState==='loading')document.addEventListener('DOMContentLoaded',function(){init(document);});else init(document);
76  if(window.MutationObserver){new MutationObserver(function(ms){ms.forEach(function(m){m.addedNodes.forEach(function(n){if(n.nodeType!==1)return;if(n.matches&&n.matches('.sv-news2'))boot(n);if(n.querySelectorAll)init(n);});});}).observe(document.documentElement,{childList:true,subtree:true});}
77  document.addEventListener('sv-news2:tdc-rendered',function(){init(document);});
78})();

Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.