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