PageSourceSearch

https://www.drewno.pl/assets/js/sidebar-sticky.js?v=1790123207

js drewno.pl collected 2026-09-24 21:22:09 UTC 3,328 bytes, 97 lines download raw bytes

1/**
2 * sidebar-sticky.js
3 * Smart scroll-direction-aware sticky sidebar.
4 * Usage: add data-smart-sticky attribute to any aside element.
5 * Optional: data-sticky-min-width="1024" — wyłącza sticky poniżej tej szerokości
6 * (jak /gieldadrzewna/); bez atrybutu działa przy każdej szerokości, gdy aside jest widoczny.
7 */
8(function () {
9    'use strict';
10
11    var BOTTOM_PAD = 16;
12
13    function readHeaderOffset() {
14        var cs     = getComputedStyle(document.documentElement);
15        var ticker = parseFloat(cs.getPropertyValue('--ticker-height')) || 36;
16        var header = parseFloat(cs.getPropertyValue('--header-height')) || 100;
17        return ticker + header + 16;
18    }
19
20    function initSidebar(sidebar) {
21        var lastScrollY = window.scrollY;
22        var currentTop  = 0;
23        var headerOff   = 0;
24        var active      = false;
25        var minWidthAttr = sidebar.getAttribute('data-sticky-min-width');
26        var minWidthPx   = minWidthAttr !== null && minWidthAttr !== '' ? parseInt(minWidthAttr, 10) : NaN;
27        var hasMinWidth  = Number.isFinite(minWidthPx) && minWidthPx > 0;
28
29        function isVisible() {
30            return sidebar.offsetParent !== null || sidebar === document.body;
31        }
32
33        function init() {
34            if (hasMinWidth && window.innerWidth < minWidthPx) {
35                sidebar.style.top = '';
36                active = false;
37                return;
38            }
39            if (!isVisible()) {
40                sidebar.style.top = '';
41                active = false;
42                return;
43            }
44            headerOff  = readHeaderOffset();
45            var vh     = window.innerHeight;
46            var sh     = sidebar.offsetHeight;
47            var avail  = vh - headerOff - BOTTOM_PAD;
48
49            currentTop = (sh <= avail)
50                ? headerOff
51                : (vh - sh - BOTTOM_PAD);
52            /* Ujemne top + sticky powoduje nakładanie sidebara na treść powyżej (np. mobile / karta ogłoszenia). */
53            currentTop = Math.max(headerOff, currentTop);
54
55            sidebar.style.top = currentTop + 'px';
56            lastScrollY = window.scrollY;
57            active = true;
58        }
59
60        function onScroll() {
61            if (!active) return;
62            var scrollY = window.scrollY;
63            var delta   = scrollY - lastScrollY;
64            lastScrollY = scrollY;
65
66            var vh     = window.innerHeight;
67            var sh     = sidebar.offsetHeight;
68            var topMin = vh - sh - BOTTOM_PAD;
69            var topMax = headerOff;
70
71            currentTop = Math.min(topMax, Math.max(topMin, currentTop - delta));
72            sidebar.style.top = currentTop + 'px';
73        }
74
75        init();
76        window.addEventListener('scroll', onScroll, { passive: true });
77        window.addEventListener('resize', init);
78        window.addEventListener('load',   init);
79
80        if (typeof ResizeObserver !== 'undefined') {
81            new ResizeObserver(function () {
82                if (active) init();
83            }).observe(sidebar);
84        }
85    }
86
87    function boot() {
88        document.querySelectorAll('[data-smart-sticky]').forEach(initSidebar);
89    }
90
91    if (document.readyState === 'loading') {
92        document.addEventListener('DOMContentLoaded', boot);
93    } else {
94        boot();
95    }
96
97}());

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.