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$( document ).ready( function(){ 14 var $menue = $( '#menu' ); 15 if( $menue.length && !($menue.hasClass('col-xs-12') || $menue.hasClass('col-md-12')) ) 16 { 17 var originalLeft = $menue.position().left; 18 19 $( window ).scroll( function(){ 20 var $this = $( this ); 21 22 if( $menue ) 23 { 24 if( !$menue.parent().hasClass( 'is-sticky' ) ) 25 { 26 $menue.css( 'left', 0 ); 27 } 28 else if( $menue.parent().hasClass( 'is-sticky' ) && $menue.width() > $this.width() ) 29 { 30 $menue.css( 'left', originalLeft - $this.scrollLeft() ); 31 } 32 else 33 { 34 $menue.css( 'left', originalLeft ); 35 } 36 } 37 } ); 38 } 39} ); 40 41(function( factory ){ 42 43 if( typeof define === 'function' && define.amd ) 44 { 45 // AMD. Register as an anonymous module. 46 define( ['jquery'], factory ); 47 } 48 else if( typeof module === 'object' && module.exports ) 49 { 50 // Node/CommonJS 51 module.exports = factory( require( 'jquery' ) ); 52 } 53 else 54 { 55 // Browser globals 56 factory( jQuery ); 57 } 58}( function( $ ){ 59 var addedActionTime = null; 60 var blockSticky = false; 61 var slice = Array.prototype.slice; // save ref to original slice() 62 var splice = Array.prototype.splice; // save ref to original slice() 63 64 var defaults = { 65 topSpacing: 0, 66 bottomSpacing: 0, 67 className: 'is-sticky', 68 wrapperClassName: 'sticky-wrapper', 69 center: false, 70 getWidthFrom: '', 71 widthFromWrapper: true, // works only when .getWidthFrom is empty 72 responsiveWidth: false 73 }, 74 $window = $( window ), 75 $document = $( document ), 76 sticked = [], 77 windowHeight = $window.height(), 78 scroller = function(){ 79 if( 0&&blockSticky ) 80 { 81 return false; 82 } 83 var scrollTop = $window.scrollTop(), 84 documentHeight = $document.height(), 85 dwh = documentHeight - windowHeight, 86 extra = (scrollTop > dwh) ? dwh - scrollTop : 0; 87 88 for( var i = 0, l = sticked.length; i < l; i++ ) 89 { 90 var s = sticked[i], 91 elementTop = s.stickyWrapper.offset().top, 92 etse = elementTop - s.topSpacing - extra; 93 94 if( etse < 0 ) 95 { 96 etse = 0; 97 } 98 99 //update height in case of dynamic content 100 s.stickyWrapper.css( 'height', s.stickyElement.outerHeight() ); 101 102 if( scrollTop <= etse ) 103 { 104 if( s.currentTop !== null ) 105 { 106 if( addedActionTime > Date.now() - 300 ) 107 { 108 blockSticky = true; 109 } 110 s.stickyElement 111 .css( { 112 'width': '', 113 'position': '', 114 'top': '' 115 } ); 116 addedActionTime = Date.now(); 117 s.stickyElement.parent().removeClass( s.className ); 118 s.stickyWrapper.css( 'height', s.stickyElement.outerHeight() ); 119 120 s.stickyElement.trigger( 'sticky-end', [s] ); 121 s.currentTop = null; 122 } 123 } 124 else 125 { 126 var newTop = documentHeight - s.stickyElement.outerHeight() 127 - s.topSpacing - s.bottomSpacing - scrollTop - extra; 128 if( newTop < 0 ) 129 { 130 newTop = newTop + s.topSpacing; 131 } 132 else 133 { 134 newTop = s.topSpacing; 135 } 136 if( s.currentTop !== newTop ) 137 { 138 var newWidth; 139 if( s.getWidthFrom ) 140 { 141 newWidth = $( s.getWidthFrom ).width() || null; 142 } 143 else if( s.widthFromWrapper ) 144 { 145 newWidth = s.stickyWrapper.width(); 146 } 147 if( newWidth == null ) 148 { 149 newWidth = s.stickyElement.width(); 150 } 151 s.stickyElement 152 .css( 'width', newWidth ) 153 .css( 'position', 'fixed' )
vendor: 9,285 bytes, lines 154-404
154 .css( 'top', newTop ); 155 156 addedActionTime = Date.now(); 157 s.stickyElement.parent().addClass( s.className ); 158 159 if( s.currentTop === null ) 160 { 161 s.stickyElement.trigger( 'sticky-start', [s] ); 162 } 163 else 164 { 165 // sticky is started but it have to be repositioned 166 s.stickyElement.trigger( 'sticky-update', [s] ); 167 } 168 169 if( s.currentTop === s.topSpacing && s.currentTop > newTop || s.currentTop === null && newTop < s.topSpacing ) 170 { 171 // just reached bottom || just started to stick but bottom is already reached 172 s.stickyElement.trigger( 'sticky-bottom-reached', [s] ); 173 } 174 else if( s.currentTop !== null && newTop === s.topSpacing && s.currentTop < newTop ) 175 { 176 // sticky is started && sticked at topSpacing && overflowing from top just finished 177 s.stickyElement.trigger( 'sticky-bottom-unreached', [s] ); 178 } 179 180 s.currentTop = newTop; 181 } 182 183 // Check if sticky has reached end of container and stop sticking 184 var stickyWrapperContainer = s.stickyWrapper.parent(); 185 var unstick = (s.stickyElement.offset().top + s.stickyElement.outerHeight() >= stickyWrapperContainer.offset().top + stickyWrapperContainer.outerHeight()) && (s.stickyElement.offset().top <= s.topSpacing); 186 187 if( unstick ) 188 { 189 s.stickyElement 190 .css( 'position', 'absolute' ) 191 .css( 'top', '' ) 192 .css( 'bottom', 0 ); 193 } 194 else 195 { 196 s.stickyElement 197 .css( 'position', 'fixed' ) 198 .css( 'top', newTop ) 199 .css( 'bottom', '' ); 200 } 201 } 202 } 203 204 }, 205 resizer = function(){ 206 blockSticky = false; 207 208 windowHeight = $window.height(); 209 210 for( var i = 0, l = sticked.length; i < l; i++ ) 211 { 212 var s = sticked[i]; 213 var newWidth = null; 214 if( s.getWidthFrom ) 215 { 216 if( s.responsiveWidth ) 217 { 218 newWidth = $( s.getWidthFrom ).width(); 219 } 220 } 221 else if( s.widthFromWrapper ) 222 { 223 newWidth = s.stickyWrapper.width(); 224 } 225 if( newWidth != null ) 226 { 227 s.stickyElement.css( 'width', newWidth ); 228 } 229 } 230 }, 231 methods = { 232 init: function( options ){ 233 var o = $.extend( {}, defaults, options ); 234 return this.each( function(){ 235 var stickyElement = $( this ); 236 237 var stickyId = stickyElement.attr( 'id' ); 238 var wrapperId = stickyId ? stickyId + '-' + defaults.wrapperClassName : defaults.wrapperClassName; 239 var wrapper = $( '<div></div>' ) 240 .attr( 'id', wrapperId ) 241 .addClass( o.wrapperClassName ); 242 243 stickyElement.wrapAll( wrapper ); 244 245 var stickyWrapper = stickyElement.parent(); 246 247 if( o.center ) 248 { 249 stickyWrapper.css( {width: stickyElement.outerWidth(), marginLeft: "auto", marginRight: "auto"} ); 250 } 251 252 if( stickyElement.css( "float" ) === "right" ) 253 { 254 stickyElement.css( {"float": "none"} ).parent().css( {"float": "right"} ); 255 } 256 257 var maxUpdate = 1000, 258 updateInterval = null; 259 260 var updateHeight = function(){ 261 stickyWrapper.css( 'height', stickyElement.outerHeight() ); 262 }; 263 264 var updateEnd = function(){ 265 updateHeight(); 266 updateInterval && window.clearInterval( updateInterval ); 267 }; 268 269 stickyElement.bind( 'transitionstart', function(){ 270 var updateEndTimestamp = $.now() + maxUpdate; 271 updateEnd(); 272 273 updateInterval = window.setInterval( function(){ 274 if( $.now() > updateEndTimestamp ) 275 { 276 updateEnd(); 277 278 return false; 279 } 280 281 updateHeight(); 282 }, 10 ); 283 } ); 284 285 stickyElement.bind( 'transitionend', function(){ 286 updateEnd(); 287 } ); 288 289 o.stickyElement = stickyElement; 290 o.stickyWrapper = stickyWrapper; 291 o.currentTop = null; 292 293 sticked.push( o ); 294 295 methods.setWrapperHeight( this ); 296 methods.setupChangeListeners( this ); 297 } ); 298 }, 299 300 setWrapperHeight: function( stickyElement ){ 301 var element = $( stickyElement ); 302 var stickyWrapper = element.parent(); 303 if( stickyWrapper ) 304 { 305 stickyWrapper.css( 'height', element.outerHeight() ); 306 } 307 }, 308 309 setupChangeListeners: function( stickyElement ){ 310 if( window.MutationObserver ) 311 { 312 var mutationObserver = new window.MutationObserver( function( mutations ){ 313 if( mutations[0].addedNodes.length || mutations[0].removedNodes.length ) 314 { 315 methods.setWrapperHeight( stickyElement ); 316 } 317 } ); 318 mutationObserver.observe( stickyElement, {subtree: true, childList: true} ); 319 } 320 }, 321 update: scroller, 322 unstick: function( options ){ 323 return this.each( function(){ 324 var that = this; 325 var unstickyElement = $( that ); 326 327 var removeIdx = -1; 328 var i = sticked.length; 329 while( i-- > 0 ) 330 { 331 if( sticked[i].stickyElement.get( 0 ) === that ) 332 { 333 splice.call( sticked, i, 1 ); 334 removeIdx = i; 335 } 336 } 337 if( removeIdx !== -1 ) 338 { 339 unstickyElement.unwrap(); 340 unstickyElement 341 .css( { 342 'width': '', 343 'position': '', 344 'top': '', 345 'float': '' 346 } ) 347 ; 348 } 349 } ); 350 } 351 }; 352 353 // should be more efficient than using $window.scroll(scroller) and $window.resize(resizer): 354 if( window.addEventListener ) 355 { 356 window.addEventListener( 'scroll', scroller, false ); 357 358 window.addEventListener( 'resize', resizer, false ); 359 } 360 else if( window.attachEvent ) 361 { 362 window.attachEvent( 'onscroll', scroller ); 363 window.attachEvent( 'onresize', resizer ); 364 } 365 366 $.fn.sticky = function( method ){ 367 var $menue = $( '#menu' ); 368 369 if( methods[method] ) 370 { 371 return methods[method].apply( this, slice.call( arguments, 1 ) ); 372 } 373 else if( typeof method === 'object' || !method ) 374 { 375 return methods.init.apply( this, arguments ); 376 } 377 else 378 { 379 $.on('error', function(){ 380 console.log('Method ' + method + ' does not exist on jQuery.sticky' ) 381 }); 382 } 383 }; 384 385 $.fn.unstick = function( method ){ 386 if( methods[method] ) 387 { 388 return methods[method].apply( this, slice.call( arguments, 1 ) ); 389 } 390 else if( typeof method === 'object' || !method ) 391 { 392 return methods.unstick.apply( this, arguments ); 393 } 394 else 395 { 396 $.on('error', function(){ 397 $.trigger('error','Method ' + method + ' does not exist on jQuery.sticky' ) 398 }); 399 } 400 }; 401 $( function(){ 402 setTimeout( scroller, 0 ); 403 } ); 404} ));
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.