PageSourceSearch

https://www.telemundowi.com/js/jquery.sticky.js?v1233.1

js telemundowi.com collected 2026-09-29 14:39:58 UTC 10,173 bytes, 292 lines download raw bytes

vendor: 10,173 bytes, lines 1-292
1// Sticky Plugin v1.0.4 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      if(WADS.IS_STICKING){
44          //console.log("dont unstick");
45          return;
46      }        
47        
48      var scrollTop = $window.scrollTop(),
49        documentHeight = $document.height(),
50        dwh = documentHeight - windowHeight,
51        extra = (scrollTop > dwh) ? dwh - scrollTop : 0;
52
53      for (var i = 0, l = sticked.length; i < l; i++) {
54        var s = sticked[i],
55          elementTop = s.stickyWrapper.offset().top,
56          etse = elementTop - s.topSpacing - extra;
57
58        //update height in case of dynamic content
59        s.stickyWrapper.css('height', s.stickyElement.outerHeight());
60
61        if (scrollTop <= etse) {
62          if (s.currentTop !== null) {
63            s.stickyElement
64              .css({
65                'width': '',
66                'position': '',
67                'top': '',
68                'z-index': ''
69              });
70            s.stickyElement.parent().removeClass(s.className);
71            s.stickyElement.trigger('sticky-end', [s]);
72            s.currentTop = null;
73          }
74        }
75        else {
76          var newTop = documentHeight - s.stickyElement.outerHeight()
77            - s.topSpacing - s.bottomSpacing - scrollTop - extra;
78          if (newTop < 0) {
79            newTop = newTop + s.topSpacing;
80          } else {
81            newTop = s.topSpacing;
82          }
83          if (s.currentTop !== newTop) {
84            var newWidth;
85            if (s.getWidthFrom) {
86                padding =  s.stickyElement.innerWidth() - s.stickyElement.width();
87                newWidth = $(s.getWidthFrom).width() - padding || null;
88            } else if (s.widthFromWrapper) {
89                newWidth = s.stickyWrapper.width();
90            }
91            if (newWidth == null) {
92                newWidth = s.stickyElement.width();
93            }
94            s.stickyElement
95              .css('width', newWidth)
96              .css('position', 'fixed')
97              .css('top', newTop)
98              .css('z-index', s.zIndex);
99
100            s.stickyElement.parent().addClass(s.className);
101
102            if (s.currentTop === null) {
103              s.stickyElement.trigger('sticky-start', [s]);
104            } else {
105              // sticky is started but it have to be repositioned
106              s.stickyElement.trigger('sticky-update', [s]);
107            }
108
109            if (s.currentTop === s.topSpacing && s.currentTop > newTop || s.currentTop === null && newTop < s.topSpacing) {
110              // just reached bottom || just started to stick but bottom is already reached
111              s.stickyElement.trigger('sticky-bottom-reached', [s]);
112            } else if(s.currentTop !== null && newTop === s.topSpacing && s.currentTop < newTop) {
113              // sticky is started && sticked at topSpacing && overflowing from top just finished
114              s.stickyElement.trigger('sticky-bottom-unreached', [s]);
115            }
116
117            s.currentTop = newTop;
118          }
119
120          // Check if sticky has reached end of container and stop sticking
121          var stickyWrapperContainer = s.stickyWrapper.parent();
122          var unstick = (s.stickyElement.offset().top + s.stickyElement.outerHeight() >= stickyWrapperContainer.offset().top + stickyWrapperContainer.outerHeight()) && (s.stickyElement.offset().top <= s.topSpacing);
123
124          if( unstick ) {
125            s.stickyElement
126              .css('position', 'absolute')
127              .css('top', '')
128              .css('bottom', 0)
129              .css('z-index', '');
130          } else {
131            s.stickyElement
132              .css('position', 'fixed')
133              .css('top', newTop)
134              .css('bottom', '')
135              .css('z-index', s.zIndex);
136          }
137        }
138      }
139    },
140    resizer = function() {
141      windowHeight = $window.height();
142
143      for (var i = 0, l = sticked.length; i < l; i++) {
144        var s = sticked[i];
145        var newWidth = null;
146        if (s.getWidthFrom) {
147            if (s.responsiveWidth) {
148                newWidth = $(s.getWidthFrom).width();
149            }
150        } else if(s.widthFromWrapper) {
151            newWidth = s.stickyWrapper.width();
152        }
153        if (newWidth != null) {
154            s.stickyElement.css('width', newWidth);
155        }
156      }
157    },
158    methods = {
159      init: function(options) {
160        return this.each(function() {
161          var o = $.extend({}, defaults, options);
162          var stickyElement = $(this);
163
164          var stickyId = stickyElement.attr('id');
165          var wrapperId = stickyId ? stickyId + '-' + defaults.wrapperClassName : defaults.wrapperClassName;
166          var wrapper = $('<div></div>')
167            .attr('id', wrapperId)
168            .addClass(o.wrapperClassName);
169
170          stickyElement.wrapAll(function() {
171            if ($(this).parent("#" + wrapperId).length == 0) {
172                    return wrapper;
173            }
174});
175
176          var stickyWrapper = stickyElement.parent();
177
178          if (o.center) {
179            stickyWrapper.css({width:stickyElement.outerWidth(),marginLeft:"auto",marginRight:"auto"});
180          }
181
182          if (stickyElement.css("float") === "right") {
183            stickyElement.css({"float":"none"}).parent().css({"float":"right"});
184          }
185
186          o.stickyElement = stickyElement;
187          o.stickyWrapper = stickyWrapper;
188          o.currentTop    = null;
189
190          sticked.push(o);
191
192          methods.setWrapperHeight(this);
193          methods.setupChangeListeners(this);
194        });
195      },
196
197      setWrapperHeight: function(stickyElement) {
198        var element = $(stickyElement);
199        var stickyWrapper = element.parent();
200        if (stickyWrapper) {
201          stickyWrapper.css('height', element.outerHeight());
202        }
203      },
204
205      setupChangeListeners: function(stickyElement) {
206        if (window.MutationObserver) {
207          var mutationObserver = new window.MutationObserver(function(mutations) {
208            if (mutations[0].addedNodes.length || mutations[0].removedNodes.length) {
209              methods.setWrapperHeight(stickyElement);
210            }
211          });
212          mutationObserver.observe(stickyElement, {subtree: true, childList: true});
213        } else {
214          if (window.addEventListener) {
215            stickyElement.addEventListener('DOMNodeInserted', function() {
216              methods.setWrapperHeight(stickyElement);
217            }, false);
218            stickyElement.addEventListener('DOMNodeRemoved', function() {
219              methods.setWrapperHeight(stickyElement);
220            }, false);
221          } else if (window.attachEvent) {
222            stickyElement.attachEvent('onDOMNodeInserted', function() {
223              methods.setWrapperHeight(stickyElement);
224            });
225            stickyElement.attachEvent('onDOMNodeRemoved', function() {
226              methods.setWrapperHeight(stickyElement);
227            });
228          }
229        }
230      },
231      update: scroller,
232      unstick: function(options) {
233        return this.each(function() {
234          var that = this;
235          var unstickyElement = $(that);
236
237          var removeIdx = -1;
238          var i = sticked.length;
239          while (i-- > 0) {
240            if (sticked[i].stickyElement.get(0) === that) {
241                splice.call(sticked,i,1);
242                removeIdx = i;
243            }
244          }
245          if(removeIdx !== -1) {
246            unstickyElement.unwrap();
247            unstickyElement
248              .css({
249                'width': '',
250                'position': '',
251                'top': '',
252                'float': '',
253                'z-index': ''
254              })
255            ;
256          }
257        });
258      }
259    };
260
261  // should be more efficient than using $window.scroll(scroller) and $window.resize(resizer):
262  if (window.addEventListener) {
263    window.addEventListener('scroll', scroller, false);
264    window.addEventListener('resize', resizer, false);
265  } else if (window.attachEvent) {
266    window.attachEvent('onscroll', scroller);
267    window.attachEvent('onresize', resizer);
268  }
269
270  $.fn.sticky = function(method) {
271    if (methods[method]) {
272      return methods[method].apply(this, slice.call(arguments, 1));
273    } else if (typeof method === 'object' || !method ) {
274      return methods.init.apply( this, arguments );
275    } else {
276      $.error('Method ' + method + ' does not exist on jQuery.sticky');
277    }
278  };
279
280  $.fn.unstick = function(method) {
281    if (methods[method]) {
282      return methods[method].apply(this, slice.call(arguments, 1));
283    } else if (typeof method === 'object' || !method ) {
284      return methods.unstick.apply( this, arguments );
285    } else {
286      $.error('Method ' + method + ' does not exist on jQuery.sticky');
287    }
288  };
289  $(function() {
290    setTimeout(scroller, 0);
291  });
292}));

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.