PageSourceSearch

https://cnnewsmt.com.br/wp-content/plugins/nf5-publicidades/assets/js/front.js?ver=3.8.8

js cnnewsmt.com.br collected 2026-09-27 09:06:44 UTC 21,402 bytes, 667 lines download raw bytes

1(function(){
2  'use strict';
3
4  function getSliderTrack(slider){
5    return slider ? slider.querySelector(':scope > .nf5-ad-slider-track') : null;
6  }
7
8  function getItems(box){
9    if(box.classList.contains('nf5-ad-slider')){
10      var track=getSliderTrack(box);
11      return track ? track.querySelectorAll(':scope > .nf5-ad-slide') : box.querySelectorAll(':scope > .nf5-ad-slide');
12    }
13    if(box.classList.contains('nf5-ad-rotator')) return box.querySelectorAll(':scope > .nf5-ad-rotator-item');
14    return [];
15  }
16
17  function moveSlider(slider,index,animate){
18    var track=getSliderTrack(slider);
19    if(!track) return;
20
21    if(animate === false){
22      track.style.transition='none';
23    }else{
24      track.style.transition='';
25    }
26
27    slider.dataset.currentIndex=String(index);
28    track.style.transform='translate3d(' + (index * -100) + '%,0,0)';
29
30    if(animate === false){
31      track.offsetHeight;
32      track.style.transition='';
33    }
34  }
35
36  function setActive(items,index){
37    items.forEach(function(item){ item.classList.remove('is-active'); });
38    if(items[index]) items[index].classList.add('is-active');
39
40    if(items.length){
41      var parent=items[0].parentNode;
42      var slider=parent && parent.classList.contains('nf5-ad-slider-track') ? parent.closest('.nf5-ad-slider') 
42: parent;
43      if(slider && slider.classList && slider.classList.contains('nf5-ad-slider')){
44        moveSlider(slider,index,true);
45      }
46    }
47  }
48
49  function nextSlide(box,dir){
50    if(box.classList.contains('nf5-ad-slider')){
51      var total=parseInt(box.dataset.realCount||'0',10);
52      if(total<2) return;
53      var current=parseInt(box.dataset.currentIndex||'1',10);
54      moveSlider(box,current+dir,true);
55      return;
56    }
57
58    var items=Array.prototype.slice.call(getItems(box));
59    if(items.length<2) return;
60    var current=items.findIndex(function(item){ return item.classList.contains('is-active'); });
61    if(current<0) current=0;
62    var next=(current+dir+items.length)%items.length;
63    setActive(items,next);
64  }
65
66  function initArrows(root){
67    var boxes=(root||document).querySelectorAll('.nf5-ad-has-arrows');
68    boxes.forEach(function(box){
69      if(box.dataset.arrowsStarted==='1') return;
70      box.dataset.arrowsStarted='1';
71      var prev=box.querySelector(':scope > .nf5-ad-arrow-prev');
72      var next=box.querySelector(':scope > .nf5-ad-arrow-next');
73      if(!prev || !next) return;
74      prev.addEventListener('click',function(e){
75        e.preventDefault();
76        if(box.classList.contains('nf5-ad-grid-wrap')){
77          var grid=box.querySelector('.nf5-ad-grid');
78          if(grid) grid.scrollBy({left:-(box.clientWidth*0.85),behavior:'smooth'});
79        } else if(box.classList.contains('nf5-ad-slider')){
80          nextSlide(box,1);
81        } else nextSlide(box,-1);
82      });
83      next.addEventListener('click',function(e){
84        e.preventDefault();
85        if(box.classList.contains('nf5-ad-grid-wrap')){
86          var grid=box.querySelector('.nf5-ad-grid');
87          if(grid) grid.scrollBy({left:(box.clientWidth*0.85),behavior:'smooth'});
88        } else nextSlide(box,1);
89      });
90    });
91  }
92
93  function initSlider(root){
94    var sliders=(root||document).querySelectorAll('.nf5-ad-slider');
95    sliders.forEach(function(slider){
96      if(slider.dataset.started==='1') return;
97      slider.dataset.started='1';
98
99      var track=getSliderTrack(slider);
100      if(!track) return;
101
102      var originalSlides=Array.prototype.slice.call(track.querySelectorAll(':scope > .nf5-ad-slide'));
103      if(originalSlides.length<2){
104        slider.dataset.realCount=String(originalSlides.length);
105        moveSlider(slider,0,false);
106        return;
107      }
108
109      slider.dataset.realCount=String(originalSlides.length);
110
111      var firstClone=originalSlides[0].cloneNode(true);
112      var lastClone=originalSlides[originalSlides.length-1].cloneNode(true);
113      firstClone.classList.add('nf5-ad-clone');
114      lastClone.classList.add('nf5-ad-clone');
115      firstClone.classList.remove('is-active');
116      lastClone.classList.remove('is-active');
117
118      track.insertBefore(lastClone, originalSlides[0]);
119      track.appendChild(firstClone);
120
121      moveSlider(slider,1,false);
122
123      track.addEventListener('transitionend',function(){
124        var total=parseInt(slider.dataset.realCount||'0',10);
125        var current=parseInt(slider.dataset.currentIndex||'1',10);
126
127        if(current > total){
128          moveSlider(slider,1,false);
129        }else if(current < 1){
130          moveSlider(slider,total,false);
131        }
132
133        var activeIndex=parseInt(slider.dataset.currentIndex||'1',10);
134        var allSlides=Array.prototype.slice.call(track.querySelectorAll(':scope > .nf5-ad-slide'));
135        allSlides.forEach(function(slide){ slide.classList.remove('is-active'); });
136        if(allSlides[activeIndex]) allSlides[activeIndex].classList.add('is-active');
137      });
138
139      var delay=parseInt(slider.getAttribute('data-delay')||'4000',10);
140      if(!delay || delay<800) delay=4000;
141      setInterval(function(){ nextSlide(slider,1); },delay);
142    });
143  }
144
145  function executeScripts(root){
146    if(!root) return;
147    var scripts=root.querySelectorAll('script');
148    scripts.forEach(function(oldScript){
149      var newScript=document.createElement('script');
150      Array.prototype.slice.call(oldScript.attributes).forEach(function(attr){
151        newScript.setAttribute(attr.name, attr.value);
152      });
153      if(oldScript.text) newScript.text=oldScript.text;
154      oldScript.parentNode.replaceChild(newScript, oldScript);
155    });
156  }
157
158  function initClickTracking(root){
159    var links=(root||document).querySelectorAll('a[data-nf5-click]');
160    links.forEach(function(link){
161      if(link.dataset.nf5ClickStarted==='1') return;
162      link.dataset.nf5ClickStarted='1';
163      link.addEventListener('click',function(){
164        var id=link.getAttribute('data-nf5-click');
165        if(!id) return;
166        var ajaxurl=(window.NF5AdsFront && NF5AdsFront.ajaxurl) ? NF5AdsFront.ajaxurl : '/wp-admin/admin-ajax.php';
167        var body=new FormData();
168        body.append('action','nf5_publicidade_click');
169        body.append('id',id);
170        if(NF5AdsFront.nonce) body.append('nonce',NF5AdsFront.nonce);
171        try{
172          if(navigator.sendBeacon){
173            var params=new URLSearchParams();
174            params.append('action','nf5_publicidade_click');
175            params.append('id',id);
176            if(NF5AdsFront.nonce) params.append('nonce',NF5AdsFront.nonce);
177            navigator.sendBeacon(NF5AdsFront.ajaxurl, params);
178          }else{
179            fetch(ajaxurl,{method:'POST',credentials:'same-origin',cache:'no-store',body:body,keepalive:true});
180          }
181        }catch(e){}
182      },{passive:true});
183    });
184  }
185
186  function initVideos(root){
187    var videos=(root||document).querySelectorAll('video[data-nf5-video-autoplay="1"]');
188    videos.forEach(function(video){
189      if(video.dataset.nf5VideoStarted==='1') return;
190      video.dataset.nf5VideoStarted='1';
191
192      video.setAttribute('playsinline','');
193      video.setAttribute('webkit-playsinline','');
194      video.autoplay=true;
195
196      function tryPlay(){
197        try{
198          var p=video.play();
199          if(p && typeof p.catch==='function'){
200            p.catch(function(){
201              try{
202                video.muted=true;
203                video.setAttribute('muted','');
204                video.play().catch(function(){});
205              }catch(e){}
206            });
207          }
208        }catch(e){
209          try{
210            video.muted=true;
211            video.setAttribute('muted','');
212            video.play();
213          }catch(err){}
214        }
215      }
216
217      if(video.readyState >= 2){
218        tryPlay();
219      }else{
220        video.addEventListener('canplay',tryPlay,{once:true});
221        video.addEventListener('loadeddata',tryPlay,{once:true});
222      }
223      setTimeout(tryPlay,120);
224      setTimeout(tryPlay,800);
225    });
226  }
227
228  var nf5ImpressionSent={};
229  var nf5ImpressionTimer=null;
230  var nf5ImpressionQueue=[];
231
232  function queueImpression(id){
233    id=parseInt(id||'0',10);
234    if(!id || nf5ImpressionSent[id]) return;
235    nf5ImpressionSent[id]=1;
236    nf5ImpressionQueue.push(id);
237
238    if(nf5ImpressionTimer) return;
239    nf5ImpressionTimer=setTimeout(function(){
240      nf5ImpressionTimer=null;
241      if(!nf5ImpressionQueue.length) return;
242
243      var ids=nf5ImpressionQueue.splice(0,50);
244      var ajaxurl=(window.NF5AdsFront && NF5AdsFront.ajaxurl) ? NF5AdsFront.ajaxurl : '/wp-admin/admin-ajax.php';
245      var action=(window.NF5AdsFront && NF5AdsFront.impressionAction) ? NF5AdsFront.impressionAction : '
245nf5_publicidade_view';
246      var body=new FormData();
247      body.append('action',action);
248      body.append('ids',ids.join(','));
249
250      try{
251        fetch(ajaxurl,{
252          method:'POST',
253          credentials:'same-origin',
254          cache:'no-store',
255          body:body,
256          keepalive:true
257        }).catch(function(){});
258      }catch(e){}
259    },350);
260  }
261
262  function initImpressions(root){
263    var nodes=(root||document).querySelectorAll('[data-nf5-impression]');
264    nodes.forEach(function(node){
265      if(node.dataset.nf5ImpressionStarted==='1') return;
266      node.dataset.nf5ImpressionStarted='1';
267      if(node.getAttribute('data-nf5-impression-counted')==='1') return;
268      var id=node.getAttribute('data-nf5-impression');
269      queueImpression(id);
270    });
271  }
272
273  var nf5PopupQueueStarted=false;
274
275  function initPopups(root){
276    if(nf5PopupQueueStarted) return;
277
278    var doc=document;
279    var popups=Array.prototype.slice.call(doc.querySelectorAll('.nf5-popup-overlay[data-nf5-popup="1"]'));
280    if(!popups.length) return;
281
282    nf5PopupQueueStarted=true;
283    var currentIndex=0;
284
285    function storageKey(popup){
286      return 'nf5_seen_'+(popup.getAttribute('data-nf5-popup-id')||'popup');
287    }
288
289    function popupLimit(popup){
290      var limit=parseInt(popup.getAttribute('data-nf5-popup-limit')||'1',10);
291      if(isNaN(limit) || limit<0) limit=1;
292      return limit;
293    }
294
295    function popupCount(popup){
296      try{
297        if(!window.sessionStorage) return 0;
298        return Math.max(0,parseInt(sessionStorage.getItem(storageKey(popup))||'0',10)||0);
299      }catch(e){
300        return 0;
301      }
302    }
303
304    function wasSeen(popup){
305      var limit=popupLimit(popup);
306      if(limit===0) return false;
307      return popupCount(popup)>=limit;
308    }
309
310    function markShown(popup){
311      var limit=popupLimit(popup);
312      if(limit===0) return;
313
314      try{
315        if(window.sessionStorage){
316          sessionStorage.setItem(storageKey(popup),String(popupCount(popup)+1));
317        }
318      }catch(e){}
319    }
320
321    function unlock(){
322      if(!doc.querySelector('.nf5-popup-overlay.is-visible')){
323        doc.documentElement.classList.remove('nf5-popup-open');
324        doc.body.classList.remove('nf5-popup-open');
325      }
326    }
327
328    function sizeDialog(popup){
329      var dialog=popup.querySelector('.nf5-popup-dialog');
330      if(!dialog) return;
331
332      var configured=parseInt(popup.getAttribute('data-nf5-popup-width')||'720',10);
333      if(!configured || configured<280) configured=720;
334
335      var viewport=Math.max(280,(window.innerWidth||document.documentElement.clientWidth||1024)-28);
336      var target=Math.min(configured+36,viewport,1100);
337      dialog.style.setProperty('width',target+'px','important');
338      dialog.style.setProperty('max-width','96vw','important');
339    }
340
341    function showPopup(popup){
342      if(!popup || popup.dataset.nf5PopupShown==='1') return;
343      popup.dataset.nf5PopupShown='1';
344      popup.classList.remove('is-preparing');
345      popup.classList.add('is-visible');
346      doc.documentElement.classList.add('nf5-popup-open');
347      doc.body.classList.add('nf5-popup-open');
348      markShown(popup);
349
350      var close=popup.querySelector('.nf5-popup-close');
351      if(close){
352        try{close.focus({preventScroll:true});}catch(e){}
353      }
354    }
355
356    function waitForMediaAndShow(popup){
357      var iframe=popup.querySelector('iframe');
358      var video=popup.querySelector('video');
359      var finished=false;
360
361      function done(){
362        if(finished) return;
363        finished=true;
364        showPopup(popup);
365      }
366
367      if(iframe){
368        try{
369          iframe.removeAttribute('loading');
370          iframe.setAttribute('loading','eager');
371        }catch(e){}
372        iframe.addEventListener('load',done,{once:true});
373        setTimeout(done,650);
374        return;
375      }
376
377      if(video){
378        video.addEventListener('loadeddata',done,{once:true});
379        video.addEventListener('canplay',done,{once:true});
380        setTimeout(done,500);
381        return;
382      }
383
384      setTimeout(done,80);
385    }
386
387    function loadPopup(popup){
388      if(!popup || popup.dataset.nf5PopupLoaded==='1') return;
389
390      var content=popup.querySelector('[data-nf5-popup-content="1"]');
391      if(!content) return;
392
393      popup.dataset.nf5PopupLoaded='1';
394      popup.hidden=false;
395      popup.removeAttribute('hidden');
396      popup.classList.add('is-preparing');
397      sizeDialog(popup);
398
399      var payload=content.getAttribute('data-nf5-popup-payload')||'';
400      var body=new FormData();
401      var action=(window.NF5AdsFront && NF5AdsFront.renderAction) ? NF5AdsFront.renderAction : 'nf5_publicidade_render';
402      var ajaxurl=(window.NF5AdsFront && NF5AdsFront.ajaxurl) ? NF5AdsFront.ajaxurl : '/wp-admin/admin-ajax.php';
403
404      body.append('action',action);
405      body.append('data',payload);
406      body.append('_cb',Date.now()+'_'+Math.random().toString(16).slice(2));
407
408      fetch(ajaxurl,{
409        method:'POST',
410        credentials:'same-origin',
411        cache:'no-store',
412        body:body
413      })
414      .then(function(response){return response.json();})
415      .then(function(json){
416        if(!json || !json.success || !json.data || typeof json.data.html!=='string' || !json.data.html.trim()){
417          popup.remove();
418          openNext();
419          return;
420        }
421
422        content.innerHTML=json.data.html;
423
424        var meaningful=content.querySelector(
425          '.nf5-ad-wrap, .nf5-ad-slider, .nf5-ad-rotator, .nf5-ad-grid-wrap, ' +
426          'img, video, iframe, ins.adsbygoogle, .nf5-ad-text-inner, .nf5-ad-code-html'
427        );
428
429        if(!meaningful || !content.textContent.trim() && !content.querySelector('img,video,iframe,ins.adsbygoogle')){
430          popup.remove();
431          openNext();
432          return;
433        }
434
435        executeScripts(content);
436        initSlider(content);
437        initArrows(content);
438        initClickTracking(content);
439        initVideos(content);
440        initImpressions(content);
441        sizeDialog(popup);
442        waitForMediaAndShow(popup);
443      })
444      .catch(function(){
445        popup.remove();
446        openNext();
447      });
448    }
449
450    function closePopup(popup){
451      if(!popup) return;
452      popup.classList.remove('is-visible');
453
454      setTimeout(function(){
455        popup.hidden=true;
456        popup.setAttribute('hidden','hidden');
457        unlock();
458        currentIndex++;
459        setTimeout(openNext,500);
460      },220);
461    }
462
463    function bindPopup(popup){
464      if(!popup || popup.dataset.nf5PopupInit==='1') return;
465      popup.dataset.nf5PopupInit='1';
466
467      popup.addEventListener('click',function(ev){
468        if(ev.target && ev.target.getAttribute('data-nf5-popup-close')==='1'){
469          ev.preventDefault();
470          closePopup(popup);
471        }
472      });
473    }
474
475    function openNext(){
476      while(currentIndex<popups.length && wasSeen(popups[currentIndex])){
477        popups[currentIndex].remove();
478        currentIndex++;
479      }
480
481      if(currentIndex>=popups.length) return;
482      var popup=popups[currentIndex];
483      bindPopup(popup);
484      loadPopup(popup);
485    }
486
487    doc.addEventListener('keydown',function(ev){
488      if(ev.key!=='Escape') return;
489      var visible=doc.querySelector('.nf5-popup-overlay.is-visible');
490      if(visible) closePopup(visible);
491    });
492
493    popups.forEach(bindPopup);
494
495    function schedule(){
496      setTimeout(openNext,500);
497    }
498
499    if(document.readyState==='complete'){
500      schedule();
501    }else{
502      window.addEventListener('load',schedule,{once:true});
503    }
504  }
505
506  function initNF5Ads(root){
507    initSlider(root);
508    initArrows(root);
509    initClickTracking(root);
510    initVideos(root);
511    initImpressions(root);
512    initPopups(root);
513  }
514
515
516  window.addEventListener('message',function(event){
517    if(!event || !event.data || event.data.type!=='nf5_ad_height') return;
518    var height=parseInt(event.data.height||'0',10);
519    if(!height) return;
520    var frames=document.querySelectorAll('iframe[src*="nf5_publicidade_iframe"]');
521    frames.forEach(function(frame){
522      try{
523        if(event.source && frame.contentWindow===event.source){
524          frame.style.setProperty('height',height+'px','important');
525          frame.style.setProperty('min-height',height+'px','important');
526          frame.style.setProperty('overflow','visible','important');
527          frame.removeAttribute('height');
528        }
529      }catch(e){}
530    });
531  });
532
533  window.addEventListener('message',function(ev){
534    var data=ev && ev.data ? ev.data : null;
535    if(!data || data.type!=='nf5_ad_impressions' || !Array.isArray(data.ids)) return;
536    data.ids.forEach(function(id){ queueImpression(id); });
537    try{ if(ev.source && ev.source.postMessage) ev.source.postMessage({type:'nf5_ad_impressions_ack'},'*'); }catch(e){}
538  });
539
540  var nf5BatchBusy=false;
541  var nf5BatchQueue=[];
542  var nf5BatchTimer=null;
543  var nf5BatchSeq=0;
544
545  function finishAdNode(node){
546    try{
547      node.classList.remove('nf5-ad-reserved-space');
548      node.style.removeProperty('aspect-ratio');
549      node.style.removeProperty('min-height');
550      node.style.removeProperty('height');
551    }catch(e){}
552  }
553
554  function applyRenderedAd(node,html){
555    if(!node) return;
556    node.dataset.loaded='1';
557    node.dataset.queued='0';
558    node.innerHTML=typeof html==='string'?html:'';
559    finishAdNode(node);
560    if(html){
561      executeScripts(node);
562      initNF5Ads(node);
563    }
564  }
565
566  function pumpBatchQueue(){
567    if(nf5BatchBusy || !nf5BatchQueue.length) return;
568    nf5BatchBusy=true;
569
570    var nodes=nf5BatchQueue.splice(0,50);
571    var requestItems=[];
572    var nodeMap={};
573
574    nodes.forEach(function(node){
575      if(!node || node.dataset.loaded==='1') return;
576      var raw=node.getAttribute('data-nf5-ad')||'';
577      var data=null;
578      try{ data=JSON.parse(raw); }catch(e){ data=null; }
579      if(!data){
580        applyRenderedAd(node,'');
581        return;
582      }
583      var key='p'+(++nf5BatchSeq);
584      nodeMap[key]=node;
585      requestItems.push({key:key,data:data});
586    });
587
588    if(!requestItems.length){
589      nf5BatchBusy=false;
590      pumpBatchQueue();
591      return;
592    }
593
594    var ajaxurl=(window.NF5AdsFront && NF5AdsFront.ajaxurl) ? NF5AdsFront.ajaxurl : '/wp-admin/admin-ajax.php';
595    var action=(window.NF5AdsFront && NF5AdsFront.batchRenderAction) ? NF5AdsFront.batchRenderAction : 'nf5_publicidade_render_batch';
596    var body=new FormData();
597    body.append('action',action);
598    body.append('items',JSON.stringify(requestItems));
599
600    fetch(ajaxurl,{
601      method:'POST',
602      credentials:'same-origin',
603      cache:'no-store',
604      body:body
605    })
606    .then(function(r){return r.json();})
607    .then(function(json){
608      var items=(json && json.success && json.data && json.data.items) ? json.data.items : {};
609      Object.keys(nodeMap).forEach(function(key){
610        applyRenderedAd(nodeMap[key],typeof items[key]==='string'?items[key]:'');
611      });
612    })
613    .catch(function(){
614      Object.keys(nodeMap).forEach(function(key){ applyRenderedAd(nodeMap[key],''); });
615    })
616    .finally(function(){
617      nf5BatchBusy=false;
618      pumpBatchQueue();
619    });
620  }
621
622  function enqueueBatchNodes(nodes){
623    Array.prototype.slice.call(nodes||[]).forEach(function(node){
624      if(!node || node.dataset.loaded==='1' || node.dataset.queued==='1') return;
625      node.dataset.queued='1';
626      nf5BatchQueue.push(node);
627    });
628    if(nf5BatchTimer) clearTimeout(nf5BatchTimer);
629    nf5BatchTimer=setTimeout(function(){
630      nf5BatchTimer=null;
631      pumpBatchQueue();
632    },20);
633  }
634
635  function watchForLateAds(){
636    if(!('MutationObserver' in window) || !document.documentElement) return;
637    var timer=null;
638    var pending=[];
639    var observer=new MutationObserver(function(mutations){
640      mutations.forEach(function(m){
641        Array.prototype.slice.call(m.addedNodes||[]).forEach(function(node){
642          if(!node || node.nodeType!==1) return;
643          if(node.matches && node.matches('.nf5-ad-placeholder[data-nf5-ad]')) pending.push(node);
644          if(node.querySelectorAll){
645            Array.prototype.slice.call(node.querySelectorAll('.nf5-ad-placeholder[data-nf5-ad]')).forEach(function(n){pending.push(n);});
646          }
647        });
648      });
649      if(!pending.length) return;
650      if(timer) clearTimeout(timer);
651      timer=setTimeout(function(){
652        var list=pending.splice(0,pending.length);
653        enqueueBatchNodes(list);
654      },60);
655    });
656    observer.observe(document.documentElement,{childList:true,subtree:true});
657  }
658
659  function loadAds(){
660    var nodes=document.querySelectorAll('.nf5-ad-placeholder[data-nf5-ad]');
661    enqueueBatchNodes(nodes);
662    initNF5Ads(document);
663  }
664
665  watchForLateAds();
666  if(document.readyState==='loading') document.addEventListener('DOMContentLoaded',loadAds); else loadAds();
667})();

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.