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