PageSourceSearch

https://www.criar.cat/web/assets/js/sticky-add-portadas.js

js criar.cat collected 2026-09-26 12:23:24 UTC 3,768 bytes, 123 lines download raw bytes

1(function () {
2    //console.error('SA-v.1.0.8 - Tiempo de espera reducido');
3  
4    let handleScroll;
5    let adsInitialized = false;
6  
7    function iniciarStickyAds() {
8      if ($(window).width() <= 991) return;
9      if (adsInitialized) return;
10      adsInitialized = true;
11  
12      const wrapHeader = $('.wrap-HEADER');
13      if (wrapHeader.length === 0) return;
14  
15      /*function getHeaderHeight() {
16        return wrapHeader.outerHeight();
17      }*/
18
19    function getHeaderHeight() {
20        let totalHeight = 0;
21        
22        const header = $('.wrap-HEADER');
23        const nav = $('.wrap-NAV');
24        
25        if (header.length && header.is(':visible') && header.css('position') === 'fixed') {
26            totalHeight += header.outerHeight();
27        }
28        
29        if (nav.length && nav.is(':visible') && nav.css('position') === 'fixed') {
30            totalHeight += nav.outerHeight();
31        }
32        
33        return totalHeight;
34        }
35  
36      const modulos = $('.MODULO');
37  
38      handleScroll = function () {
39        const headerHeight = getHeaderHeight();
40  
41        modulos.each(function () {
42          const modulo = $(this);
43          const adWrap = modulo.find('.sec-wrap, .third-wrap');
44          if (adWrap.length === 0) return;
45  
46          const bn = adWrap.find('.BN');
47          if (bn.length === 0) return;
48  
49          let adContent = bn.find('div[id^="div-gpt-ad"]').first();
50          if (adContent.length === 0) {
51            adContent = bn.children(':not(script)').first();
52          }
53          if (adContent.length === 0) return;
54  
55          const bnRect = bn[0].getBoundingClientRect();
56          const contentHeight = adContent.outerHeight();
57          const topDistance = bnRect.top;
58          const bottomDistance = bnRect.bottom;
59  
60          const containerHeight = bn[0].scrollHeight;
61          const espacioScroll = containerHeight - contentHeight;
62  
63          if (espacioScroll < 80) {
64            adContent.removeClass('fixed_add stick-bottom').css({
65              position: 'static',
66              top: 'auto',
67              bottom: 'auto',
68            });
69            return;
70          }
71  
72          adContent.removeClass('fixed_add stick-bottom').css({
73            position: 'static',
74            top: 'auto',
75            bottom: 'auto',
76          });
77  
78          const isHeaderFixed = wrapHeader.css('position') === 'fixed';
79  
80          if (isHeaderFixed && topDistance <= headerHeight && (bottomDistance - headerHeight) > contentHeight) {
81            adContent.addClass('fixed_add').css({
82              position: 'fixed',
83              top: `${headerHeight}px`,
84            });
85          } else if ((bottomDistance - headerHeight) <= contentHeight) {
86            adContent.addClass('stick-bottom').css({
87              position: 'absolute',
88              bottom: '0',
89            });
90          }
91        });
92      };
93  
94      // 🕒 Configuración de tiempo de espera optimizada
95      let attempts = 0;
96      const maxAttempts = 10;     // Antes: 50
97      const intervalTime = 150;   // Antes: 300
98  
99      const interval = setInterval(() => {
100        const ready = $('.BN').toArray().every(bn =>
101          $(bn).children(':not(script)').first().outerHeight() > 0
102        );
103  
104        if (ready || attempts >= maxAttempts) {
105          clearInterval(interval);
106          handleScroll();
107          $(window).on('scroll resize', handleScroll);
108        }
109        attempts++;
110      }, intervalTime);
111  
112      // Backup por si no se resuelve
113      setTimeout(() => {
114        clearInterval(interval);
115        handleScroll();
116        $(window).on('scroll resize', handleScroll);
117      }, maxAttempts * intervalTime);
118    }
119  
120    $(document).ready(function () {
121      iniciarStickyAds();
122    });
123  })();

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.