PageSourceSearch

https://www.drewno.pl/assets/js/page-loader.js?v=1790765823

js drewno.pl collected 2026-10-02 08:02:32 UTC 5,635 bytes, 200 lines download raw bytes

1(function () {
2  'use strict';
3
4  var PAGE_DELAY_MS = 2000;
5  var ELEMENT_DELAY_MS = 2000;
6  var pageLoader = document.getElementById('page-loader');
7  var pageTimer = 0;
8  var elementTimers = new Map();
9
10  function showPageLoader() {
11    if (!pageLoader) return;
12    pageLoader.classList.add('is-visible');
13    pageLoader.setAttribute('aria-hidden', 'false');
14  }
15
16  function hidePageLoader() {
17    if (!pageLoader) return;
18    pageLoader.classList.remove('is-visible');
19    pageLoader.setAttribute('aria-hidden', 'true');
20  }
21
22  function schedulePageLoader(delayMs) {
23    window.clearTimeout(pageTimer);
24    pageTimer = window.setTimeout(showPageLoader, delayMs || PAGE_DELAY_MS);
25  }
26
27  function clearPageLoaderTimer() {
28    window.clearTimeout(pageTimer);
29    pageTimer = 0;
30  }
31
32  function isTrackableElement(el) {
33    return !!(
34      el &&
35      el.nodeType === 1 &&
36      !el.matches('html, body, script, style, link, meta, path, svg')
37    );
38  }
39
40  function isLoadingElement(el) {
41    return isTrackableElement(el) && el.matches(
42      '.loading, .is-loading, .cards-grid--loading, [aria-busy="true"], [data-loading="true"]'
43    );
44  }
45
46  function activateElementLoader(el) {
47    if (!isTrackableElement(el)) return;
48    el.setAttribute('data-drewno-loader-active', 'true');
49  }
50
51  function deactivateElementLoader(el) {
52    if (!isTrackableElement(el)) return;
53    el.removeAttribute('data-drewno-loader-active');
54  }
55
56  function scheduleElementLoader(el) {
57    if (!isTrackableElement(el) || el.getAttribute('data-drewno-loader-active') === 'true') return;
58    if (elementTimers.has(el)) return;
59
60    var timer = window.setTimeout(function () {
61      elementTimers.delete(el);
62      if (document.contains(el) && isLoadingElement(el)) {
63        activateElementLoader(el);
64      }
65    }, ELEMENT_DELAY_MS);
66
67    elementTimers.set(el, timer);
68  }
69
70  function clearElementLoader(el) {
71    var timer = elementTimers.get(el);
72    if (timer) {
73      window.clearTimeout(timer);
74      elementTimers.delete(el);
75    }
76    deactivateElementLoader(el);
77  }
78
79  function syncElementLoader(el) {
80    if (!isTrackableElement(el)) return;
81    if (isLoadingElement(el)) {
82      scheduleElementLoader(el);
83      return;
84    }
85    clearElementLoader(el);
86  }
87
88  function scanLoadingElements(root) {
89    if (!isTrackableElement(root)) return;
90    syncElementLoader(root);
91    root.querySelectorAll('.loading, .is-loading, .cards-grid--loading, [aria-busy="true"], [data-loading="true"]').forEach(syncElementLoader);
92  }
93
94  function shouldTrackNavigationLink(link, event) {
95    if (!link || event.defaultPrevented) return false;
96    if (event.button !== 0 || event.metaKey || event.ctrlKey || event.shiftKey || event.altKey) return false;
97    if (link.target && link.target !== '_self') return false;
98    if (link.hasAttribute('download')) return false;
99
100    var href = link.getAttribute('href') || '';
101    if (!href || href.charAt(0) === '#') return false;
102
103    var url;
104    try {
105      url = new URL(link.href, window.location.href);
106    } catch (err) {
107      return false;
108    }
109
110    if (url.origin !== window.location.origin) return false;
111    // Nawigacja w obrębie tego samego dokumentu (różnica tylko w #fragmencie, np.
112    // /biznes#sec-section-articles klikane z /biznes) nie przeładowuje strony —
113    // zdarzenia load/pageshow się nie odpalą, więc raz pokazany pełnoekranowy loader
114    // nigdy by nie zniknął i strona wyglądałaby na „zawieszoną”.
115    if (url.href.split('#')[0] === window.location.href.split('#')[0]) return false;
116
117    return true;
118  }
119
120  if (document.readyState === 'loading') {
121    schedulePageLoader(PAGE_DELAY_MS);
122  }
123
124  document.addEventListener('DOMContentLoaded', function () {
125    clearPageLoaderTimer();
126    hidePageLoader();
127  }, { once: true });
128
129  window.addEventListener('load', function () {
130    clearPageLoaderTimer();
131    hidePageLoader();
132  }, { once: true });
133
134  window.addEventListener('pageshow', function () {
135    clearPageLoaderTimer();
136    hidePageLoader();
137  });
138
139  document.addEventListener('click', function (event) {
140    var link = event.target.closest('a[href]');
141    if (!shouldTrackNavigationLink(link, event)) return;
142    schedulePageLoader();
143  });
144
145  document.addEventListener('submit', function (event) {
146    if (event.defaultPrevented) return;
147    schedulePageLoader();
148  });
149
150  if (document.body) {
151    scanLoadingElements(document.body);
152
153    var observer = new MutationObserver(function (mutations) {
154      mutations.forEach(function (mutation) {
155        if (mutation.type === 'attributes') {
156          syncElementLoader(mutation.target);
157          return;
158        }
159
160        mutation.addedNodes.forEach(function (node) {
161          if (node.nodeType === 1) scanLoadingElements(node);
162        });
163
164        mutation.removedNodes.forEach(function (node) {
165          if (node.nodeType === 1) clearElementLoader(node);
166        });
167      });
168    });
169
170    observer.observe(document.body, {
171      subtree: true,
172      childList: true,
173      attributes: true,
174      attributeFilter: ['class', 'aria-busy', 'data-loading']
175    });
176  }
177
178  window.DrewnoLoader = {
179    showPage: function () {
180      clearPageLoaderTimer();
181      showPageLoader();
182    },
183    hidePage: function () {
184      clearPageLoaderTimer();
185      hidePageLoader();
186    },
187    mark: function (el) {
188      scheduleElementLoader(el);
189    },
190    unmark: function (el) {
191      clearElementLoader(el);
192    },
193    trackPromise: function (promise, el) {
194      scheduleElementLoader(el);
195      return Promise.resolve(promise).finally(function () {
196        clearElementLoader(el);
197      });
198    }
199  };
200}());

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.