1/*! 2 * jQuery.ScrollTo 3 * Copyright (c) 2007-2014 Ariel Flesler - aflesler<a>gmail<d>com | http://flesler.blogspot.com 4 * Licensed under MIT 5 * http://flesler.blogspot.com/2007/10/jqueryscrollto.html 6 * @projectDescription Easy element scrolling using jQuery. 7 * @author Ariel Flesler 8 * @version 1.4.11 9 */ 10 11;(function(plugin) { 12 // AMD Support 13 if (typeof define === 'function' && define.amd) { 14 define(['jquery'], plugin); 15 } else { 16 plugin(jQuery); 17 } 18}(function($) { 19 20 var $scrollTo = $.scrollTo = function( target, duration, settings ) { 21 return $(window).scrollTo( target, duration, settings ); 22 }; 23 24 $scrollTo.defaults = { 25 axis:'xy', 26 duration: parseFloat($.fn.jquery) >= 1.3 ? 0 : 1, 27 limit:true 28 }; 29 30 // Returns the element that needs to be animated to scroll the window. 31 // Kept for backwards compatibility (specially for localScroll & serialScroll) 32 $scrollTo.window = function( scope ) { 33 return $(window)._scrollable(); 34 }; 35 36 // Hack, hack, hack :) 37 // Returns the real elements to scroll (supports window/iframes, documents and regular nodes) 38 $.fn._scrollable = function() { 39 return this.map(function() { 40 var elem = this, 41 isWin = !elem.nodeName || $.inArray( elem.nodeName.toLowerCase(), ['iframe','#document','html','body'] ) != -1; 42 43 if (!isWin) 44 return elem; 45 46 var doc = (elem.contentWindow || elem).document || elem.ownerDocument || elem; 47 48 return /webkit/i.test(navigator.userAgent) || doc.compatMode == 'BackCompat' ? 49 doc.body : 50 doc.documentElement; 51 }); 52 }; 53 54 $.fn.scrollTo = function( target, duration, settings ) { 55 if (typeof duration == 'object') { 56 settings = duration; 57 duration = 0; 58 } 59 if (typeof settings == 'function') 60 settings = { onAfter:settings }; 61 62 if (target == 'max') 63 target = 9e9; 64 65 settings = $.extend( {}, $scrollTo.defaults, settings ); 66 // Speed is still recognized for backwards compatibility 67 duration = duration || settings.duration; 68 // Make sure the settings are given right 69 settings.queue = settings.queue && settings.axis.length > 1; 70 71 if (settings.queue) 72 // Let's keep the overall duration 73 duration /= 2; 74 settings.offset = both( settings.offset ); 75 settings.over = both( settings.over ); 76 77 return this._scrollable().each(function() { 78 // Null target yields nothing, just like jQuery does 79 if (target == null) return; 80 81 var elem = this, 82 $elem = $(elem), 83 targ = target, toff, attr = {}, 84 win = $elem.is('html,body'); 85 86 switch (typeof targ) { 87 // A number will pass the regex 88 case 'number': 89 case 'string': 90 if (/^([+-]=?)?\d+(\.\d+)?(px|%)?$/.test(targ)) { 91 targ = both( targ ); 92 // We are done 93 break; 94 } 95 // Relative selector, no break! 96 targ = $(targ,this); 97 if (!targ.length) return; 98 case 'object': 99 // DOMElement / jQuery 100 if (targ.is || targ.style) 101 // Get the real position of the target 102 toff = (targ = $(targ)).offset(); 103 } 104 105 var offset = $.isFunction(settings.offset) && settings.offset(elem, targ) || settings.offset; 106 107 $.each( settings.axis.split(''), function( i, axis ) { 108 var Pos = axis == 'x' ? 'Left' : 'Top', 109 pos = Pos.toLowerCase(), 110 key = 'scroll' + Pos, 111 old = elem[key], 112 max = $scrollTo.max(elem, axis); 113 114 if (toff) {// jQuery / DOMElement 115 attr[key] = toff[pos] + ( win ? 0 : old - $elem.offset()[pos] ); 116 117 // If it's a dom element, reduce the margin 118 if (settings.margin) { 119 attr[key] -= parseInt(targ.css('margin'+Pos)) || 0; 120 attr[key] -= parseInt(targ.css('border'+Pos+'Width')) || 0; 121 } 122 123 attr[key] += offset[pos] || 0; 124 125 if(settings.over[pos]) 126 // Scroll to a fraction of its width/height 127 attr[key] += targ[axis=='x'?'width':'height']() * settings.over[pos]; 128 } else { 129 var val = targ[pos]; 130 // Handle percentage values 131 attr[key] = val.slice && val.slice(-1) == '%' ? 132 parseFloat(val) / 100 * max 133 : val; 134 } 135 136 // Number or 'number' 137 if (settings.limit && /^\d+$/.test(attr[key])) 138 // Check the limits 139 attr[key] = attr[key] <= 0 ? 0 : Math.min( attr[key], max ); 140 141 // Queueing axes 142 if (!i && settings.queue) { 143 // Don't waste time animating, if there's no need. 144 if (old != attr[key]) 145 // Intermediate animation 146 animate( settings.onAfterFirst ); 147 // Don't animate this axis again in the next iteration. 148 delete attr[key]; 149 } 150 }); 151 152 animate( settings.onAfter ); 153 154 function animate( callback ) { 155 $elem.animate( attr, duration, settings.easing, callback && function() { 156 callback.call(this, targ, settings); 157 }); 158 }; 159 160 }).end(); 161 }; 162 163 // Max scrolling position, works on quirks mode
164 // It only fails (not too badly) on IE, quirks mode. 165 $scrollTo.max = function( elem, axis ) { 166 var Dim = axis == 'x' ? 'Width' : 'Height', 167 scroll = 'scroll'+Dim; 168 169 if (!$(elem).is('html,body')) 170 return elem[scroll] - $(elem)[Dim.toLowerCase()](); 171 172 var size = 'client' + Dim, 173 html = elem.ownerDocument.documentElement, 174 body = elem.ownerDocument.body; 175 176 return Math.max( html[scroll], body[scroll] ) 177 - Math.min( html[size] , body[size] ); 178 }; 179 180 function both( val ) { 181 return $.isFunction(val) || typeof val == 'object' ? val : { top:val, left:val }; 182 }; 183 184 // AMD requirement 185 return $scrollTo; 186}));
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.