PageSourceSearch

https://www.drewno.pl/assets/js/card-lead-clamp.js?v=1790123207

js drewno.pl collected 2026-09-24 21:22:07 UTC 1,903 bytes, 51 lines download raw bytes

1/**
2 * Dynamiczny clamp leadów kart artykułów.
3 *
4 * Cel: wielokropek „…" w leadzie ma się pojawiać DOKŁADNIE wtedy, gdy lead nie
5 * mieści się w dostępnej (zmiennej) przestrzeni karty — nie po sztywnych N wierszach.
6 *
7 * Karta ma stałą wysokość, a `.card__lead` ma `flex:1`, więc jego wysokość renderowana
8 * (`clientHeight`) = miejsce, które realnie zostało po tytule (1–4 wiersze) i miniaturze.
9 * Liczymy ile pełnych wierszy się tam mieści i ustawiamy `-webkit-line-clamp` na tę liczbę.
10 *
11 * Fallback bez JS: CSS `.card__lead { -webkit-line-clamp: 3 }` (zachowanie dotychczasowe).
12 * Progresywne ulepszenie — nie psuje renderu, gdy skrypt się nie wykona.
13 */
14(() => {
15  if (typeof document === 'undefined') return;
16  // Brak wsparcia line-clamp → zostawiamy CSS-owy fallback.
17  if (!('webkitLineClamp' in document.documentElement.style)) return;
18
19  const SELECTOR = '.card__lead, .card--hero-style__lead';
20
21  const clampOne = (lead) => {
22    const cs = getComputedStyle(lead);
23    const lineHeight = parseFloat(cs.lineHeight);
24    if (!lineHeight || Number.isNaN(lineHeight)) return;
25
26    // clientHeight = wysokość przydzielona przez flex (= dostępne miejsce w karcie).
27    const avail = lead.clientHeight;
28    if (avail <= 0) return;
29
30    const lines = Math.max(1, Math.floor(avail / lineHeight));
31    lead.style.webkitLineClamp = String(lines);
32  };
33
34  const clampAll = () => {
35    document.querySelectorAll(SELECTOR).forEach(clampOne);
36  };
37
38  const onReady = () => requestAnimationFrame(clampAll);
39
40  if (document.readyState === 'loading') {
41    document.addEventListener('DOMContentLoaded', onReady, { once: true });
42  } else {
43    onReady();
44  }
45
46  let resizeTimer = null;
47  window.addEventListener('resize', () => {
48    if (resizeTimer) clearTimeout(resizeTimer);
49    resizeTimer = setTimeout(() => requestAnimationFrame(clampAll), 150);
50  });
51})();

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.