PageSourceSearch

https://www.sintkatelijnewaver.be/Scripts/jquery.sticky.js

js sintkatelijnewaver.be collected 2026-09-24 10:15:36 UTC 7,592 bytes, 226 lines download raw bytes

vendor: 7,592 bytes, lines 1-226
1// Sticky Plugin v1.0.3 for jQuery
2// =============
3// Author: Anthony Garand
4// Improvements by German M. Bravo (Kronuz) and Ruud Kamphuis (ruudk)
5// Improvements by Leonardo C. Daronco (daronco)
6// Created: 02/14/2011
7// Date: 07/20/2015
8// Website: http://stickyjs.com/
9// Description: Makes an element on the page stick on the screen as you scroll
10//              It will only set the 'top' and 'position' of your element, you
11//              might need to adjust the width in some cases.
12
13(function (factory) {
14    if (typeof define === 'function' && define.amd) {
15        // AMD. Register as an anonymous module.
16        define(['jquery'], factory);
17    } else if (typeof module === 'object' && module.exports) {
18        // Node/CommonJS
19        module.exports = factory(require('jquery'));
20    } else {
21        // Browser globals
22        factory(jQuery);
23    }
24}(function ($) {
25    var slice = Array.prototype.slice; // save ref to original slice()
26    var splice = Array.prototype.splice; // save ref to original slice()
27
28  var defaults = {
29      topSpacing: 0,
30      bottomSpacing: 0,
31      className: 'is-sticky',
32      wrapperClassName: 'sticky-wrapper',
33      center: false,
34      getWidthFrom: '',
35      widthFromWrapper: true, // works only when .getWidthFrom is empty
36      responsiveWidth: false
37    },
38    $window = $(window),
39    $document = $(document),
40    sticked = [],
41    windowHeight = $window.height(),
42    scroller = function() {
43      var scrollTop = $window.scrollTop(),
44        documentHeight = $document.height(),
45        dwh = documentHeight - windowHeight,
46        extra = (scrollTop > dwh) ? dwh - scrollTop : 0;
47
48      for (var i = 0, l = sticked.length; i < l; i++) {
49        var s = sticked[i],
50          elementTop = s.stickyWrapper.offset().top,
51          etse = elementTop - s.topSpacing - extra;
52
53	//update height in case of dynamic content
54	s.stickyWrapper.css('height', s.stickyElement.outerHeight());
55
56        if (scrollTop <= etse) {
57          if (s.currentTop !== null) {
58            s.stickyElement
59              .css({
60                'width': '',
61                'position': '',
62                'top': ''
63              });
64            s.stickyElement.parent().removeClass(s.className);
65            s.stickyElement.trigger('sticky-end', [s]);
66            s.currentTop = null;
67          }
68        }
69        else {
70          var newTop = documentHeight - s.stickyElement.outerHeight()
71            - s.topSpacing - s.bottomSpacing - scrollTop - extra;
72          if (newTop < 0) {
73            newTop = newTop + s.topSpacing;
74          } else {
75            newTop = s.topSpacing;
76          }
77          if (s.currentTop !== newTop) {
78            var newWidth;
79            if (s.getWidthFrom) {
80                newWidth = $(s.getWidthFrom).width() || null;
81            } else if (s.widthFromWrapper) {
82                newWidth = s.stickyWrapper.width();
83            }
84            if (newWidth == null) {
85                newWidth = s.stickyElement.width();
86            }
87            s.stickyElement
88              .css('width', newWidth)
89              .css('position', 'fixed')
90              .css('top', newTop);
91
92            s.stickyElement.parent().addClass(s.className);
93
94            if (s.currentTop === null) {
95              s.stickyElement.trigger('sticky-start', [s]);
96            } else {
97              // sticky is started but it have to be repositioned
98              s.stickyElement.trigger('sticky-update', [s]);
99            }
100
101            if (s.currentTop === s.topSpacing && s.currentTop > newTop || s.currentTop === null && newTop < s.topSpacing) {
102              // just reached bottom || just started to stick but bottom is already reached
103              s.stickyElement.trigger('sticky-bottom-reached', [s]);
104            } else if(s.currentTop !== null && newTop === s.topSpacing && s.currentTop < newTop) {
105              // sticky is started && sticked at topSpacing && overflowing from top just finished
106              s.stickyElement.trigger('sticky-bottom-unreached', [s]);
107            }
108
109            s.currentTop = newTop;
110          }
111        }
112      }
113    },
114    resizer = function() {
115      windowHeight = $window.height();
116
117      for (var i = 0, l = sticked.length; i < l; i++) {
118        var s = sticked[i];
119        var newWidth = null;
120        if (s.getWidthFrom) {
121            if (s.responsiveWidth) {
122                newWidth = $(s.getWidthFrom).width();
123            }
124        } else if(s.widthFromWrapper) {
125            newWidth = s.stickyWrapper.width();
126        }
127        if (newWidth != null) {
128            s.stickyElement.css('width', newWidth);
129        }
130      }
131    },
132    methods = {
133      init: function(options) {
134        var o = $.extend({}, defaults, options);
135        return this.each(function() {
136          var stickyElement = $(this);
137
138          var stickyId = stickyElement.attr('id');
139          var stickyHeight = stickyElement.outerHeight();
140          var wrapperId = stickyId ? stickyId + '-' + defaults.wrapperClassName : defaults.wrapperClassName;
141          var wrapper = $('<div></div>')
142            .attr('id', wrapperId)
143            .addClass(o.wrapperClassName);
144
145          stickyElement.wrapAll(wrapper);
146
147          var stickyWrapper = stickyElement.parent();
148
149          if (o.center) {
150            stickyWrapper.css({width:stickyElement.outerWidth(),marginLeft:"auto",marginRight:"auto"});
151          }
152
153          if (stickyElement.css("float") === "right") {
154            stickyElement.css({"float":"none"}).parent().css({"float":"right"});
155          }
156
157          stickyWrapper.css('height', stickyHeight);
158
159          o.stickyElement = stickyElement;
160          o.stickyWrapper = stickyWrapper;
161          o.currentTop    = null;
162
163          sticked.push(o);
164        });
165      },
166      update: scroller,
167      unstick: function(options) {
168        return this.each(function() {
169          var that = this;
170          var unstickyElement = $(that);
171
172          var removeIdx = -1;
173          var i = sticked.length;
174          while (i-- > 0) {
175            if (sticked[i].stickyElement.get(0) === that) {
176                splice.call(sticked,i,1);
177                removeIdx = i;
178            }
179          }
180          if(removeIdx !== -1) {
181            unstickyElement.unwrap();
182            unstickyElement
183              .css({
184                'width': '',
185                'position': '',
186                'top': '',
187                'float': ''
188              })
189            ;
190          }
191        });
192      }
193    };
194
195  // should be more efficient than using $window.scroll(scroller) and $window.resize(resizer):
196  if (window.addEventListener) {
197    window.addEventListener('scroll', scroller, false);
198    window.addEventListener('resize', resizer, false);
199  } else if (window.attachEvent) {
200    window.attachEvent('onscroll', scroller);
201    window.attachEvent('onresize', resizer);
202  }
203
204  $.fn.sticky = function(method) {
205    if (methods[method]) {
206      return methods[method].apply(this, slice.call(arguments, 1));
207    } else if (typeof method === 'object' || !method ) {
208      return methods.init.apply( this, arguments );
209    } else {
210      $.error('Method ' + method + ' does not exist on jQuery.sticky');
211    }
212  };
213
214  $.fn.unstick = function(method) {
215    if (methods[method]) {
216      return methods[method].apply(this, slice.call(arguments, 1));
217    } else if (typeof method === 'object' || !method ) {
218      return methods.unstick.apply( this, arguments );
219    } else {
220      $.error('Method ' + method + ' does not exist on jQuery.sticky');
221    }
222  };
223  $(function() {
224    setTimeout(scroller, 0);
225  });
226}));

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.