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