PageSourceSearch

https://autonomia.hu/wp-content/themes/autonomiasablon/js/jquery.smooth-scroll.min.js?ver=6.3.1

js autonomia.hu collected 2026-10-02 04:41:41 UTC 9,099 bytes, 311 lines download raw bytes

vendor: 5,128 bytes, lines 1-171
1/*!
2 * jQuery Smooth Scroll - v1.7.2 - 2016-01-23
3 * https://github.com/kswedberg/jquery-smooth-scroll
4 * Copyright (c) 2016 Karl Swedberg
5 * Licensed MIT
6 */
7
8(function(factory) {
9  if (typeof define === 'function' && define.amd) {
10    // AMD. Register as an anonymous module.
11    define(['jquery'], factory);
12  } else if (typeof module === 'object' && module.exports) {
13    // CommonJS
14    factory(require('jquery'));
15  } else {
16    // Browser globals
17    factory(jQuery);
18  }
19}(function($) {
20
21  var version = '1.7.2';
22  var optionOverrides = {};
23  var defaults = {
24    exclude: [],
25    excludeWithin: [],
26    offset: 0,
27
28    // one of 'top' or 'left'
29    direction: 'top',
30
31    // if set, bind click events through delegation
32    //  supported since jQuery 1.4.2
33    delegateSelector: null,
34
35    // jQuery set of elements you wish to scroll (for $.smoothScroll).
36    //  if null (default), $('html, body').firstScrollable() is used.
37    scrollElement: null,
38
39    // only use if you want to override default behavior
40    scrollTarget: null,
41
42    // fn(opts) function to be called before scrolling occurs.
43    // `this` is the element(s) being scrolled
44    beforeScroll: function() {},
45
46    // fn(opts) function to be called after scrolling occurs.
47    // `this` is the triggering element
48    afterScroll: function() {},
49    easing: 'swing',
50    speed: 400,
51
52    // coefficient for "auto" speed
53    autoCoefficient: 2,
54
55    // $.fn.smoothScroll only: whether to prevent the default click action
56    preventDefault: true
57  };
58
59  var getScrollable = function(opts) {
60    var scrollable = [];
61    var scrolled = false;
62    var dir = opts.dir && opts.dir === 'left' ? 'scrollLeft' : 'scrollTop';
63
64    this.each(function() {
65      var el = $(this);
66
67      if (this === document || this === window) {
68        return;
69      }
70
71      if (document.scrollingElement && (this === document.documentElement || this === document.body)) {
72        scrollable.push(document.scrollingElement);
73
74        return false;
75      }
76
77      if (el[dir]() > 0) {
78        scrollable.push(this);
79      } else {
80        // if scroll(Top|Left) === 0, nudge the element 1px and see if it moves
81        el[dir](1);
82        scrolled = el[dir]() > 0;
83
84        if (scrolled) {
85          scrollable.push(this);
86        }
87        // then put it back, of course
88        el[dir](0);
89      }
90    });
91
92    if (!scrollable.length) {
93      this.each(function() {
94        // If no scrollable elements and <html> has scroll-behavior:smooth because
95        // "When this property is specified on the root element, it applies to the viewport instead."
96        // and "The scroll-behavior property of the … body element is *not* propagated to the viewport."
97        // → https://drafts.csswg.org/cssom-view/#propdef-scroll-behavior
98        if (this === document.documentElement && $(this).css('scrollBehavior') === 'smooth') {
99          scrollable = [this];
100        }
101
102        // If still no scrollable elements, fall back to <body>,
103        // if it's in the jQuery collection
104        // (doing this because Safari sets scrollTop async,
105        // so can't set it to 1 and immediately get the value.)
106        if (!scrollable.length && this.nodeName === 'BODY') {
107          scrollable = [this];
108        }
109      });
110    }
111
112    // Use the first scrollable element if we're calling firstScrollable()
113    if (opts.el === 'first' && scrollable.length > 1) {
114      scrollable = [scrollable[0]];
115    }
116
117    return scrollable;
118  };
119
120  $.fn.extend({
121    scrollable: function(dir) {
122      var scrl = getScrollable.call(this, {dir: dir});
123
124      return this.pushStack(scrl);
125    },
126    firstScrollable: function(dir) {
127      var scrl = getScrollable.call(this, {el: 'first', dir: dir});
128
129      return this.pushStack(scrl);
130    },
131
132    smoothScroll: function(options, extra) {
133      options = options || {};
134
135      if (options === 'options') {
136        if (!extra) {
137          return this.first().data('ssOpts');
138        }
139
140        return this.each(function() {
141          var $this = $(this);
142          var opts = $.extend($this.data('ssOpts') || {}, extra);
143
144          $(this).data('ssOpts', opts);
145        });
146      }
147
148      var opts = $.extend({}, $.fn.smoothScroll.defaults, options);
149
150      var clickHandler = function(event) {
151        var escapeSelector = function(str) {
152          return str.replace(/(:|\.|\/)/g, '\\$1');
153        };
154
155        var link = this;
156        var $link = $(this);
157        var thisOpts = $.extend({}, opts, $link.data('ssOpts') || {});
158        var exclude = opts.exclude;
159        var excludeWithin = thisOpts.excludeWithin;
160        var elCounter = 0;
161        var ewlCounter = 0;
162        var include = true;
163        var clickOpts = {};
164        var locationPath = $.smoothScroll.filterPath(location.pathname);
165        var linkPath = $.smoothScroll.filterPath(link.pathname);
166        var hostMatch = location.hostname === link.hostname || !link.hostname;
167        var pathMatch = thisOpts.scrollTarget || (linkPath === locationPath);
168        var thisHash = escapeSelector(link.hash);
169
170        if (thisHash && !$(thisHash).length) {
171          include = false;
172        }
173
174        if (!thisOpts.scrollTarget && (!hostMatch || !pathMatch || !thisHash)) {
175          include = false;
176        } else {
177          while (include && elCounter < exclude.length) {
178            if ($link.is(escapeSelector(exclude[elCounter++]))) {
179              include = false;
180            }
181          }
182
183          while (include && ewlCounter < excludeWithin.length) {
184            if ($link.closest(excludeWithin[ewlCounter++]).length) {
185              include = false;
186            }
187          }
188        }
189
190        if (include) {
191          if (thisOpts.preventDefault) {
192            event.preventDefault();
193          }
194
195          $.extend(clickOpts, thisOpts, {
196            scrollTarget: thisOpts.scrollTarget || thisHash,
197            link: link
198          });
199
200          $.smoothScroll(clickOpts);
201        }
202      };
203
204      if (options.delegateSelector !== null) {
205        this
206        .undelegate(options.delegateSelector, 'click.smoothscroll')
207        .delegate(options.delegateSelector, 'click.smoothscroll', clickHandler);
208      } else {
209        this
210        .unbind('click.smoothscroll')
211        .bind('click.smoothscroll', clickHandler);
212      }
213
214      return this;
215    }
216  });
217
218  $.smoothScroll = function(options, px) {
219    if (options === 'options' && typeof px === 'object') {
220      return $.extend(optionOverrides, px);
221    }
222    var opts, $scroller, scrollTargetOffset, speed, delta;
223    var scrollerOffset = 0;
224    var offPos = 'offset';
225    var scrollDir = 'scrollTop';
226    var aniProps = {};
227    var aniOpts = {};
228
229    if (typeof options === 'number') {
230      opts = $.extend({link: null}, $.fn.smoothScroll.defaults, optionOverrides);
231      scrollTargetOffset = options;
232    } else {
233      opts = $.extend({link: null}, $.fn.smoothScroll.defaults, options || {}, optionOverrides);
234
235      if (opts.scrollElement) {
236        offPos = 'position';
237
238        if (opts.scrollElement.css('position') === 'static') {
239          opts.scrollElement.css('position', 'relative');
240        }
241      }
242    }
243
244    scrollDir = opts.direction === 'left' ? 'scrollLeft' : scrollDir;
245
246    if (opts.scrollElement) {
247      $scroller = opts.scrollElement;
248
249      if (!(/^(?:HTML|BODY)$/).test($scroller[0].nodeName)) {
250        scrollerOffset = $scroller[scrollDir]();
251      }
252    } else {
253      $scroller = $('html, body').firstScrollable(opts.direction);
254    }
255
256    // beforeScroll callback function must fire before calculating offset
257    opts.beforeScroll.call($scroller, opts);
258
259    scrollTargetOffset = (typeof options === 'number') ? options :
260                          px ||
261                          ($(opts.scrollTarget)[offPos]() &&
262                          $(opts.scrollTarget)[offPos]()[opts.direction]) ||
263                          0;
264
265    aniProps[scrollDir] = scrollTargetOffset + scrollerOffset + opts.offset;
266    speed = opts.speed;
267
268    // automatically calculate the speed of the scroll based on distance / coefficient
269    if (speed === 'auto') {
270
271      // $scroller[scrollDir]() is position before scroll, aniProps[scrollDir] is position after
272      // When delta is greater, speed will be greater.
273      delta = Math.abs(aniProps[scrollDir] - $scroller[scrollDir]());
274
275      // Divide the delta by the coefficient
276      speed = delta / opts.autoCoefficient;
277    }
278
279    aniOpts = {
280      duration: speed,
281      easing: opts.easing,
282      complete: function() {
283        opts.afterScroll.call(opts.link, opts);
284      }
285    };
286
287    if (opts.step) {
288      aniOpts.step = opts.step;
289    }
290
291    if ($scroller.length) {
292      $scroller.stop().animate(aniProps, aniOpts);
293    } else {
294      opts.afterScroll.call(opts.link, opts);
295    }
296  };
297
298  $.smoothScroll.version = version;
299  $.smoothScroll.filterPath = function(string) {
300    string = string || '';
301
302    return string
303      .replace(/^\//, '')
304      .replace(/(?:index|default).[a-zA-Z]{3,4}$/, '')
305      .replace(/\/$/, '');
306  };
307
308  // default options
309  $.fn.smoothScroll.defaults = defaults;
310
311}));

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.