PageSourceSearch

https://www.jobscardiffcouncil.co.uk/wp-content/plugins/wp-jobhunt/assets/scripts/jquery.sticky.js?ver=5.9.9

js jobscardiffcouncil.co.uk collected 2026-10-08 05:41:57 UTC 7,405 bytes, 219 lines download raw bytes

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

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.