You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

4 lines
10 KiB

/*! jQuery asHoverScroll - v0.2.3 - 2015-12-17
* https://github.com/amazingSurge/jquery-asHoverScroll
* Copyright (c) 2015 amazingSurge; Licensed GPL */
!function(a){"use strict";var b="asHoverScroll",c=0,d=a[b]=function(b,e){this.element=b,this.$element=a(b),this.options=a.extend({},d.defaults,e,this.$element.data()),this.$list=a(this.options.list,this.$element),this.classes={disabled:this.options.namespace+"-disabled"},"vertical"===this.options.direction?this.attributes={page:"pageY",axis:"Y",position:"top",length:"height",offset:"offsetTop",client:"clientY",clientLength:"clientHeight"}:"horizontal"===this.options.direction&&(this.attributes={page:"pageX",axis:"X",position:"left",length:"width",offset:"offsetLeft",client:"clientX",clientLength:"clientWidth"}),this._states={},this._scroll={time:null,pointer:null},this.instanceId=++c,this._trigger("init"),this.init()};d.defaults={namespace:b,list:"> ul",item:"> li",exception:null,direction:"vertical",fixed:!1,mouseMove:!0,touchScroll:!0,pointerScroll:!0,useCssTransforms:!0,useCssTransforms3d:!0,boundary:10,throttle:20,onEnter:function(){a(this).siblings().removeClass("is-active"),a(this).addClass("is-active")},onLeave:function(){a(this).removeClass("is-active")}};var e={};d.support=e,function(b){function c(b,c){var d=!1,g=b.charAt(0).toUpperCase()+b.slice(1);return a.each((b+" "+f.join(g+" ")+g).split(" "),function(a,b){return void 0!==e[b]?(d=c?b:!0,!1):void 0}),d}function d(a){return c(a,!0)}var e=a("<support>").get(0).style,f=["webkit","Moz","O","ms"],g={transition:{end:{WebkitTransition:"webkitTransitionEnd",MozTransition:"transitionend",OTransition:"oTransitionEnd",transition:"transitionend"}},animation:{end:{WebkitAnimation:"webkitAnimationEnd",MozAnimation:"animationend",OAnimation:"oAnimationEnd",animation:"animationend"}}},h={csstransforms:function(){return!!c("transform")},csstransforms3d:function(){return!!c("perspective")},csstransitions:function(){return!!c("transition")},cssanimations:function(){return!!c("animation")}};h.csstransitions()&&(b.transition=new String(d("transition")),b.transition.end=g.transition.end[b.transition]),h.cssanimations()&&(b.animation=new String(d("animation")),b.animation.end=g.animation.end[b.animation]),h.csstransforms()&&(b.transform=new String(d("transform")),b.transform3d=h.csstransforms3d()),b.touch="ontouchstart"in window||window.DocumentTouch&&document instanceof window.DocumentTouch?!0:!1,b.pointer=window.PointerEvent||window.MSPointerEvent?!0:!1,b.convertMatrixToArray=function(a){return a&&"matrix"==a.substr(0,6)?a.replace(/^.*\((.*)\)$/g,"$1").replace(/px/g,"").split(/, +/):!1},b.prefixPointerEvent=function(a){return window.MSPointerEvent?"MSPointer"+a.charAt(9).toUpperCase()+a.substr(10):a}}(e),d.prototype={constructor:d,init:function(){this.initPosition(),this.updateLength(),this.bindEvents()},bindEvents:function(){var b=this,c=["enter"],d=[];this.options.mouseMove&&(this.$element.on(this.eventName("mousemove"),a.proxy(this.onMove,this)),c.push("mouseenter"),d.push("mouseleave")),this.options.touchScroll&&e.touch&&(this.$element.on(this.eventName("touchstart"),a.proxy(this.onScrollStart,this)),this.$element.on(this.eventName("touchcancel"),a.proxy(this.onScrollEnd,this))),this.options.pointerScroll&&e.pointer&&(this.$element.on(this.eventName(e.prefixPointerEvent("pointerdown")),a.proxy(this.onScrollStart,this)),this.$element.on(this.eventName(e.prefixPointerEvent("pointercancel")),a.proxy(this.onScrollEnd,this))),this.$list.on(this.eventName(c.join(" ")),this.options.item,function(){b.is("scrolling")||b.options.onEnter.call(this)}),this.$list.on(this.eventName(d.join(" ")),this.options.item,function(){b.is("scrolling")||b.options.onLeave.call(this)}),a(window).on(this.eventNameWithId("orientationchange"),function(){b.update.call(b)}),a(window).on(this.eventNameWithId("resize"),this.throttle(function(){b.update.call(b)},this.options.throttle))},unbindEvents:function(){this.$element.off(this.eventName()),this.$list.off(this.eventName()),a(window).off(this.eventNameWithId())},onScrollStart:function(b){var c=this;if(3!==b.which&&!(a(b.target).closest(this.options.exception).length>0)){this._scroll.time=(new Date).getTime(),this._scroll.pointer=this.pointer(b),this._scro