/* * SnapScroll v1.3.0 Copyright (c) 2018 AJ Savino * https://github.com/koga73/SnapScroll * MIT License */ !function(h){function t(e){var n=null,t={callbackDelay:300,_lastOrientation:window.orientation,_timeout:0},i={init:function(){window.addEventListener?(window.addEventListener("resize",i._handler_resize,!1),window.addEventListener("orientationchange",i._handler_resize,!1)):window.attachEvent&&(window.attachEvent("onresize",i._handler_resize),window.attachEvent("onorientationchange",i._handler_resize))},destroy:function(){var e=t._timeout;e&&(clearTimeout(e),t._timeout=0),n.onResize=null,window.removeEventListener?(window.removeEventListener("resize",i._handler_resize),window.removeEventListener("orientationchange",i._handler_resize)):window.detachEvent&&(window.detachEvent("onresize",i._handler_resize),window.detachEvent("onorientationchange",i._handler_resize))},getWidth:function(){return window.innerWidth||document.documentElement.clientWidth||document.body.clientWidth},getHeight:function(){return window.innerHeight||document.documentElement.clientHeight||document.body.clientHeight},_handler_resize:function(){if("onorientationchange"in window){var e=window.orientation;if(e==t._lastOrientation)return;t._lastOrientation=e}t._timeout&&clearTimeout(t._timeout),t._timeout=setTimeout(i._handler_timeout,n.callbackDelay)},_handler_timeout:function(){clearTimeout(t._timeout),t._timeout=0,n.onResize(n.getWidth(),n.getHeight())}};for(var a in n={callbackDelay:t.callbackDelay,init:i.init,destroy:i.destroy,getWidth:i.getWidth,getHeight:i.getHeight,onResize:null},e)n[a]=e[a];return n.init(),n}h.fn.SnapScroll=function(e){var r=null,n={events:!0,eventChangeActive:"snapscroll_change-active",eventChangeVisible:"snapscroll_change-visible",classes:!0,classSnap:"snap-scroll",classVisible:"snap-scroll-visible",classActive:"snap-scroll-active",hashes:!1,scrollDelay:300,wheelInterval:1e3,animateDuration:250,animateTimeBuffer:100,snapTop:!0,snapBottom:!0,snaps:[],maxWheelDeviation:100};h.fn.SnapScroll.defaults=n;var l=100,c={_$this:this,_resizer:null,_snaps:null,_currentSnapIndex:-1,_scrollTimeout:0,_lastanimateDuration:0,_wheelDir:0,_lastWheelTime:0,_wheelEventDeltas:[],_wheelEventDeltaAvg:0,_lastWheelEventTime:0},_={init:function(){r.classes&&c._$this.addClass(r.classSnap),c._resizer=new t({onResize:_._handler_resize}),_._handler_resize(),h(document).on("scroll",_._handler_document_scroll),h(document).on("keydown",_._handler_document_keydown),h(window).on("DOMMouseScroll mousewheel wheel",_._handler_window_mousewheel)},destroy:function(){h(document).off("scroll",_._handler_document_scroll),h(document).off("keydown",_._handler_document_keydown),h(window).off("DOMMouseScroll mousewheel wheel",_._handler_window_mousewheel),c._resizer&&(c._resizer.destroy(),c._resizer=null),c._snaps=null,c._currentSnapIndex=-1,c._scrollTimeout&&(clearTimeout(c._scrollTimeout),c._scrollTimeout=0),c._lastanimateDuration=0,c._wheelDir=0,c._lastWheelTime=0,c._wheelEventDeltas.splice(0,c._wheelEventDeltas.length),c._wheelEventDeltaAvg=0,c._lastWheelEventTime=0,r.classes&&c._$this.removeClass(r.classSnap)},snapClosest:function(){for(var e=_._getScrollPosition(),n=-1,t=-1,i=c._snaps,a=i.length,s=0;s=r.maxWheelDeviation&&(c._wheelEventDeltas.splice(0,a),n=!0)}else n=!0;c._lastWheelEventTime=t;var s=Math.max(-1,Math.min(1,e.originalEvent.deltaY||e.originalEvent.wheelDelta||-e.originalEvent.detail));return c._wheelDir=Math.abs(s)/s,(n||(new Date).getTime()>=c._lastWheelTime+r.wheelInterval)&&_._handler_wheel_timeout(),!1},_handler_wheel_timeout:function(){c._lastWheelTime=(new Date).getTime(),c._wheelDir<0?r.snapPrev():0