vendor: 4,631 bytes, lines 1-166
1/**handles:jquery-scrollto**/ 2/*! 3 * jQuery.scrollTo 4 * Copyright (c) 2007-2015 Ariel Flesler - aflesler<a>gmail<d>com | http://flesler.blogspot.com 5 * Licensed under MIT 6 * http://flesler.blogspot.com/2007/10/jqueryscrollto.html 7 * @projectDescription Lightweight, cross-browser and highly customizable animated scrolling with jQuery 8 * @author Ariel Flesler 9 * @version 2.1.2 10 */ 11;(function(factory) { 12 'use strict'; 13 if (typeof define === 'function' && define.amd) { 14 // AMD 15 define( ['jquery'], factory ); 16 } else if (typeof module !== 'undefined' && module.exports) { 17 // CommonJS 18 module.exports = factory( require( 'jquery' ) ); 19 } else { 20 // Global 21 factory( jQuery ); 22 } 23})(function($) { 24 'use strict'; 25 26 var $scrollTo = $.scrollTo = function(target, duration, settings) { 27 return $( window ).scrollTo( target, duration, settings ); 28 }; 29 30 $scrollTo.defaults = { 31 axis:'xy', 32 duration: 0, 33 limit:true 34 }; 35 36 function isWin(elem) { 37 return ! elem.nodeName || 38 $.inArray( elem.nodeName.toLowerCase(), ['iframe','#document','html','body'] ) !== -1; 39 } 40 41 $.fn.scrollTo = function(target, duration, settings) { 42 if (typeof duration === 'object') { 43 settings = duration; 44 duration = 0; 45 } 46 if (typeof settings === 'function') { 47 settings = { onAfter:settings }; 48 } 49 if (target === 'max') { 50 target = 9e9; 51 } 52 53 settings = $.extend( {}, $scrollTo.defaults, settings ); 54 // Speed is still recognized for backwards compatibility 55 duration = duration || settings.duration; 56 // Make sure the settings are given right 57 var queue = settings.queue && settings.axis.length > 1; 58 if (queue) { 59 // Let's keep the overall duration 60 duration /= 2; 61 } 62 settings.offset = both( settings.offset ); 63 settings.over = both( settings.over ); 64 65 return this.each(function() { 66 // Null target yields nothing, just like jQuery does 67 if (target === null) { return; } 68 69 var win = isWin( this ), 70 elem = win ? this.contentWindow || window : this, 71 $elem = $( elem ), 72 targ = target, 73 attr = {}, 74 toff; 75 76 switch (typeof targ) { 77 // A number will pass the regex 78 case 'number': 79 case 'string': 80 if (/^([+-]=?)?\d+(\.\d+)?(px|%)?$/.test( targ )) { 81 targ = both( targ ); 82 // We are done 83 break; 84 } 85 // Relative/Absolute selector 86 targ = win ? $( targ ) : $( targ, elem ); 87 /* falls through */ 88 case 'object': 89 if (targ.length === 0) { return; } 90 // DOMElement / jQuery 91 if (targ.is || targ.style) { 92 // Get the real position of the target 93 toff = (targ = $( targ )).offset(); 94 } 95 } 96 97 var offset = $.isFunction( settings.offset ) && settings.offset( elem, targ ) || settings.offset; 98 99 $.each(settings.axis.split( '' ), function(i, axis) { 100 var Pos = axis === 'x' ? 'Left' : 'Top', 101 pos = Pos.toLowerCase(), 102 key = 'scroll' + Pos, 103 prev = $elem[key](), 104 max = $scrollTo.max( elem, axis ); 105 106 if (toff) {// jQuery / DOMElement 107 attr[key] = toff[pos] + (win ? 0 : prev - $elem.offset()[pos]); 108 109 // If it's a dom element, reduce the margin 110 if (settings.margin) { 111 attr[key] -= parseInt( targ.css( 'margin' + Pos ), 10 ) || 0; 112 attr[key] -= parseInt( targ.css( 'border' + Pos + 'Width' ), 10 ) || 0; 113 } 114 115 attr[key] += offset[pos] || 0; 116 117 if (settings.over[pos]) { 118 // Scroll to a fraction of its width/height 119 attr[key] += targ[axis === 'x'?'width':'height']() * settings.over[pos]; 120 } 121 } else { 122 var val = targ[pos]; 123 // Handle percentage values 124 attr[key] = val.slice && val.slice( -1 ) === '%' ? 125 parseFloat( val ) / 100 * max 126 : val; 127 } 128 129 // Number or 'number' 130 if (settings.limit && /^\d+$/.test( attr[key] )) { 131 // Check the limits 132 attr[key] = attr[key] <= 0 ? 0 : Math.min( attr[key], max ); 133 } 134 135 // Don't waste time animating, if there's no need. 136 if ( ! i && settings.axis.length > 1) { 137 if (prev === attr[key]) { 138 // No animation needed 139 attr = {}; 140 } else if (queue) { 141 // Intermediate animation 142 animate( settings.onAfterFirst ); 143 // Don't animate this axis again in the next iteration. 144 attr = {}; 145 } 146 } 147 }); 148 149 animate( settings.onAfter ); 150 151 function animate(callback) { 152 var opts = $.extend({}, settings, { 153 // The queue setting conflicts with animate() 154 // Force it to always be true 155 queue: true, 156 duration: duration, 157 complete: callback && function() { 158 callback.call( elem, targ, settings ); 159 } 160 }); 161 $elem.animate( attr, opts ); 162 } 163 }); 164 }; 165 166 // Max scrolling position, works on quirks mode
167 // It only fails (not too badly) on IE, quirks mode. 168 $scrollTo.max = function(elem, axis) { 169 var Dim = axis === 'x' ? 'Width' : 'Height', 170 scroll = 'scroll' + Dim; 171 172 if ( ! isWin( elem )) { 173 return elem[scroll] - $( elem )[Dim.toLowerCase()](); } 174 175 var size = 'client' + Dim, 176 doc = elem.ownerDocument || elem.document, 177 html = doc.documentElement, 178 body = doc.body; 179 180 return Math.max( html[scroll], body[scroll] ) - Math.min( html[size], body[size] ); 181 }; 182 183 function both(val) { 184 return $.isFunction( val ) || $.isPlainObject( val ) ? val : { top:val, left:val }; 185 } 186 187 // Add special hooks so that window scroll properties can be animated 188 $.Tween.propHooks.scrollLeft = $.Tween.propHooks.scrollTop = { 189 get: function(t) { 190 return $( t.elem )[t.prop](); 191 }, 192 set: function(t) { 193 var curr = this.get( t ); 194 // If interrupt is true and user scrolled, stop animating 195 if (t.options.interrupt && t._last && t._last !== curr) { 196 return $( t.elem ).stop(); 197 } 198 var next = Math.round( t.now ); 199 // Don't waste CPU 200 // Browsers don't render floating point scroll 201 if (curr !== next) { 202 $( t.elem )[t.prop](next); 203 t._last = this.get( t ); 204 } 205 } 206 }; 207 208 // AMD requirement 209 return $scrollTo; 210});
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.