PageSourceSearch

https://www.scampparnashop.hu/wa_script/js/bs_fixed_bar.js?_=2026-09-11-00-00

js scampparnashop.hu collected 2026-10-03 21:37:29 UTC 10,740 bytes, 410 lines download raw bytes

1var BS = BS || {};
2(function(BS) {
3  'use strict';
4
5  var _consts = {
6    direction: {
7      DOWN: 0,
8      UP: 1
9    },
10    method: {
11      ADD: "add",
12      REMOVE: "remove"
13    }
14  };
15
16  var FixedBar = function(options)
17  {
18
19    this._settings = {};
20    this._vars = {
21      bar: null,
22      paddingEl: null,
23      enabled: true,
24      isFixed: false,
25      stepEnabled: false,
26      stepOffset: 0,
27      stepReached: false,
28      barOffset: 0,
29      previousScroll: 0,
30      barHeight: 0,
31      padding: null,
32      scrollDirection: null,
33      directionChangedAt: null
34    };
35
36    this._init(options);
37  };
38
39  FixedBar.prototype._init = function(options) {
40    if(typeof options === "object"
41      && options !== null)
42    {
43      this._settings = this._getOptions(BS.FixedBar.defaults, options);
44      if(this._settings.selector
45        && this._settings.selector !== "")
46      {
47        var el = document.querySelector(this._settings.selector);
48        if(el !== null)
49        {
50          this._vars.bar = el;
51          this._initOffsets();
52          this._registerEvents();
53          this._checkWindowWidth();
54        }
55      }
56      else
57      {
58        console.error("No element to select");
59      }
60    }
61    else
62    {
63      console.error("Options not set");
64    }
65  };
66
67  FixedBar.prototype._getOptions = function(defaults, options) {
68    var temp = {};
69    for(var key in defaults)
70    {
71      if(defaults.hasOwnProperty(key))
72      {
73        if(options.hasOwnProperty(key))
74        {
75          if(typeof defaults[key] === "object")
76          {
77            temp[key] = this._getOptions(defaults[key], options[key]);
78          }
79          else
80          {
81            temp[key] = options[key];
82          }
83        }
84        else
85        {
86          temp[key] = defaults[key];
87        }
88      }
89    }
90
91    return Object.keys(temp).length ? temp : false;
92  };
93
94  FixedBar.prototype._initOffsets = function() {
95    this._vars.barHeight = this._getBarHeight();
96    this._vars.barOffset = this._getBarOffset();
97    if(this._settings.step
98      && this._settings.step.enable)
99    {
100      this._vars.stepEnabled = true;
101      this._vars.stepOffset = this._getStepOffset(this._vars.barOffset, this._vars.barHeight);
102    }
103  };
104
105  FixedBar.prototype._getBarOffset = function() {
106    return this._vars.bar.getBoundingClientRect().top + window.pageYOffset;
107  };
108
109  FixedBar.prototype._getStepOffset = function(barOffset, barHeight) {
110    var offset = 0,
111        regex = /^([0-9]+)(px|%)?$/,
112        match;
113    if(match = regex.exec(this._settings.step.offset))
114    {
115      //zadaná hodnota (px nebo %)
116      if(match[2] === "%")
117      {
118        //% z výšky lišty
119        offset = barHeight * (parseInt(match[1]) / 100);
120      }
121      else
122      {
123        //px + horní hranice
124        offset = barOffset + parseInt(match[1]);
125      }
126    }
127    else if(this._settings.step.offset === "bottom")
128    {
129      //dolní hranice lišty
130      offset = barOffset + barHeight;
131    }
132
133    return offset;
134  };
135
136  FixedBar.prototype._getWindowWidth = function() {
137    return window.innerWidth || document.body.clientWidth;
138  };
139
140  FixedBar.prototype._checkWindowWidth = function() {
141    var regex = /^([0-9]+)(?:px)?$/,
142        match;
143    if(match = regex.exec(this._settings.minWidth))
144    {
145      var windowWidth = this._getWindowWidth();
146      var minWidth = parseInt(match[1]);
147      this._vars.enabled = windowWidth >= minWidth;
148
149      //případně ještě odstraníme "fixed" css třídu
150      if(!this._vars.enabled
151        && this._vars.bar.classList.contains(this._settings.fixedClass))
152      {
153        this._updateFixedStatus(_consts.method.REMOVE);
154        if(this._vars.stepEnabled)
155        {
156          this._updateStepStatus(_consts.method.REMOVE);
157        }
158        if(this._settings.scrollDirection.enable)
159        {
160          this._updateDirectionClasses(_consts.method.REMOVE, _consts.method.REMOVE);
161        }
162      }
163    }
164  };
165
166  FixedBar.prototype._registerEvents = function() {
167    window.addEventListener("scroll", this._pageScroll.bind(this), false);
168    //změna velikosti okna
169    window.addEventListener("resize", this._windowResize.bind(this), false);
170  };
171
172  FixedBar.prototype._pageScroll = function() {
173    if(this._vars.enabled)
174    {
175      var scroll = window.pageYOffset;
176      var direction = scroll > this._vars.previousScroll ? _consts.direction.DOWN : _consts.direction.UP;
177      if(direction === _consts.direction.DOWN)
178      {
179        //scrollujeme dolů
180        if(scroll > this._vars.barOffset)
181        {
182          if(!this._vars.isFixed)
183          {
184            //vycpávka
185            this._setPadding();
186            this._updateFixedStatus(_consts.method.ADD);
187          }
188        }
189
190        if(this._vars.stepEnabled)
191        {
192          if(scroll > this._vars.stepOffset)
193          {
194            if(!this._vars.stepReached)
195            {
196              this._updateStepStatus(_consts.method.ADD);
197            }
198          }
199        }
200      }
201      else if(direction === _consts.direction.UP)
202      {
203        //scrollujeme nahoru
204        if(this._vars.stepEnabled)
205        {
206          if(scroll <= this._vars.stepOffset)
207          {
208            if(this._vars.stepReached)
209            {
210              this._updateStepStatus(_consts.method.REMOVE);
211            }
212          }
213        }
214
215        if(scroll <= this._vars.barOffset)
216        {
217          if(this._vars.isFixed)
218          {
219            this._removePadding();
220            this._updateFixedStatus(_consts.method.REMOVE);
221          }
222        }
223      }
224      if(this._settings.scrollDirection.enable)
225      {
226        this._scrollDirection(direction, scroll, this._vars.isFixed)
227      }
228      this._vars.previousScroll = scroll;
229    }
230  };
231
232  FixedBar.prototype._scrollDirection = function(direction, scroll, isFixed) {
233    var deadzone = Math.abs(parseInt(this._settings.scrollDirection.deadzone));
234    if(direction === _consts.direction.DOWN)
235    {
236      if(isFixed)
237      {
238        if(this._vars.scrollDirection === null)
239        {
240          this._vars.scrollDirection = _consts.direction.DOWN;
241          this._vars.directionChangedAt = scroll;
242          this._updateDirectionClasses(_consts.method.ADD, _consts.method.REMOVE);
243        }
244        else
245        {
246          if(this._vars.scrollDirection === _consts.direction.UP)
247          {
248            //změna směru
249            this._vars.directionChangedAt = scroll;
250            this._vars.scrollDirection = _consts.direction.DOWN;
251          }
252
253          if(scroll > (this._vars.directionChangedAt + deadzone))
254          {
255            this._updateDirectionClasses(_consts.method.ADD, _consts.method.REMOVE);
256          }
257        }
258      }
259    }
260    else if(direction === _consts.direction.UP)
261    {
262      if(!isFixed)
263      {
264        //lišta je ukotvena
265        this._vars.scrollDirection = null;
266        this._vars.directionChangedAt = null;
267        this._updateDirectionClasses(_consts.method.REMOVE, _consts.method.REMOVE);
268      }
269      else
270      {
271        if(this._vars.scrollDirection === _consts.direction.DOWN)
272        {
273          //změna směru
274          this._vars.directionChangedAt = scroll;
275          this._vars.scrollDirection = _consts.direction.UP;
276        }
277
278        if(scroll < (this._vars.directionChangedAt - deadzone))
279        {
280          this._updateDirectionClasses(_consts.method.REMOVE, _consts.method.ADD);
281        }
282      }
283    }
284  };
285
286  FixedBar.prototype._setPadding = function() {
287    if(this._settings.padding
288      && this._settings.padding.enable === true)
289    {
290      var padding = this._vars.barHeight;
291      var property = this._settings.padding.property.toCamelCase();
292
293      if(!this._vars.paddingEl)
294      {
295        this._vars.paddingEl = this._getPaddingElement();
296      }
297
298      //existuje zadaná vlastnost?
299      if(this._vars.paddingEl.style.hasOwnProperty(property))
300      {
301        this._vars.paddingEl.style[property] = padding + "px";
302        this._vars.padding = padding;
303      }
304    }
305  };
306
307  FixedBar.prototype._removePadding = function() {
308    if(this._settings.padding
309      && this._settings.padding.enable === true
310      && this._vars.paddingEl
311      && !!this._vars.padding)
312    {
313      var property = this._settings.padding.property.toCamelCase();
314      if(this._vars.paddingEl.style.hasOwnProperty(property))
315      {
316        this._vars.paddingEl.style[property] = '';
317        this._vars.padding = null;
318      }
319    }
320  };
321
322  FixedBar.prototype._getPaddingElement = function() {
323    var el = null;
324    if(this._settings.padding.element === "parent")
325    {
326      el = this._vars.bar.parentElement;
327    }
328    else
329    {
330      el = document.querySelector(this._settings.padding.element);
331    }
332    return el;
333  };
334
335  FixedBar.prototype._getBarHeight = function() {
336    return this._vars.bar.offsetHeight;
337  };
338
339  FixedBar.prototype._windowResize = function(e) {
340    this._checkWindowWidth();
341    this._vars.barHeight = this._getBarHeight();
342    if(this._vars.stepEnabled)
343    {
344      this._vars.stepOffset = this._getStepOffset(this._vars.barOffset, this._vars.barHeight);
345    }
346  };
347
348  FixedBar.prototype._updateFixedStatus = function(method) {
349    this._vars.bar.classList[method](this._settings.fixedClass);
350    if(this._settings.bodyClass
351      && this._settings.bodyClass !== "")
352    {
353      document.body.classList[method](this._settings.bodyClass);
354    }
355    this._vars.isFixed = method === _consts.method.ADD;
356  };
357
358  FixedBar.prototype._updateStepStatus = function(method) {
359    if(this._settings.step.stepClass)
360    {
361      this._vars.bar.classList[method](this._settings.step.stepClass);
362    }
363    this._vars.stepReached = method === _consts.method.ADD;
364  };
365
366  FixedBar.prototype._updateDirectionClasses = function(down, up) {
367    if(this._settings.scrollDirection.scrollDClass !== "")
368    {
369      this._vars.bar.classList[down](this._settings.scrollDirection.scrollDClass);
370    }
371    if(this._settings.scrollDirection.scrollUClass)
372    {
373      this._vars.bar.classList[up](this._settings.scrollDirection.scrollUClass);
374    }
375  };
376
377  BS.FixedBar = FixedBar;
378  BS.FixedBar.consts = {
379    padding: {
380      PADDING_TOP: "padding-top",
381      PADDING_BOTTOM: "padding-bottom",
382      MARGIN_TOP: "margin-top",
383      MARGIN_BOTTOM: "margin-bottom"
384    }
385  };
386  BS.FixedBar.defaults = {
387    selector: "",
388    minWidth: 0,
389    scrollDirection: {
390      enable: true,
391      scrollUClass: "fb-scroll-u",
392      scrollDClass: "fb-scroll-d",
393      deadzone: 25
394    },
395    padding: {
396      enable: false,
397      property: BS.FixedBar.consts.padding.PADDING_TOP,
398      element: ""
399    },
400    step: {
401      enable: false,
402      offset: 0,
403      stepClass: "fb-step"
404    },
405    fixedClass: "is-fixed",
406    bodyClass: "fb-is-fixed"
407  };
408
409})(BS);
410

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.