campagne-adhesion-2014-www/javascripts/jquery.scrollTo.js

10 lines
2.3 KiB
JavaScript

/*!
* jQuery.ScrollTo
* Copyright (c) 2007-2014 Ariel Flesler - aflesler<a>gmail<d>com | http://flesler.blogspot.com
* Licensed under MIT
* http://flesler.blogspot.com/2007/10/jqueryscrollto.html
* @projectDescription Easy element scrolling using jQuery.
* @author Ariel Flesler
* @version 1.4.8
*/
!function(e){"function"==typeof define&&define.amd?define(["jquery"],e):e(jQuery)}(function(e){function t(e){return"object"==typeof e?e:{top:e,left:e}}var n=e.scrollTo=function(t,n,o){return e(window).scrollTo(t,n,o)};return n.defaults={axis:"xy",duration:parseFloat(e.fn.jquery)>=1.3?0:1,limit:!0},n.window=function(){return e(window)._scrollable()},e.fn._scrollable=function(){return this.map(function(){var t=this,n=!t.nodeName||-1!=e.inArray(t.nodeName.toLowerCase(),["iframe","#document","html","body"]);if(!n)return t;var o=(t.contentWindow||t).document||t.ownerDocument||t;return/webkit/i.test(navigator.userAgent)||"BackCompat"==o.compatMode?o.body:o.documentElement})},e.fn.scrollTo=function(o,r,i){return"object"==typeof r&&(i=r,r=0),"function"==typeof i&&(i={onAfter:i}),"max"==o&&(o=9e9),i=e.extend({},n.defaults,i),r=r||i.duration,i.queue=i.queue&&i.axis.length>1,i.queue&&(r/=2),i.offset=t(i.offset),i.over=t(i.over),this._scrollable().each(function(){function a(e){f.animate(l,r,i.easing,e&&function(){e.call(this,c,i)})}if(null!=o){var s,u=this,f=e(u),c=o,l={},d=f.is("html,body");switch(typeof c){case"number":case"string":if(/^([+-]=?)?\d+(\.\d+)?(px|%)?$/.test(c)){c=t(c);break}if(c=e(c,this),!c.length)return;case"object":(c.is||c.style)&&(s=(c=e(c)).offset())}e.each(i.axis.split(""),function(e,t){var o="x"==t?"Left":"Top",r=o.toLowerCase(),m="scroll"+o,h=u[m],p=n.max(u,t);if(s)l[m]=s[r]+(d?0:h-f.offset()[r]),i.margin&&(l[m]-=parseInt(c.css("margin"+o))||0,l[m]-=parseInt(c.css("border"+o+"Width"))||0),l[m]+=i.offset[r]||0,i.over[r]&&(l[m]+=c["x"==t?"width":"height"]()*i.over[r]);else{var w=c[r];l[m]=w.slice&&"%"==w.slice(-1)?parseFloat(w)/100*p:w}i.limit&&/^\d+$/.test(l[m])&&(l[m]=l[m]<=0?0:Math.min(l[m],p)),!e&&i.queue&&(h!=l[m]&&a(i.onAfterFirst),delete l[m])}),a(i.onAfter)}}).end()},n.max=function(t,n){var o="x"==n?"Width":"Height",r="scroll"+o;if(!e(t).is("html,body"))return t[r]-e(t)[o.toLowerCase()]();var i="client"+o,a=t.ownerDocument.documentElement,s=t.ownerDocument.body;return Math.max(a[r],s[r])-Math.min(a[i],s[i])},n});