forked from jquery/jquery-mousewheel
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathjquery.mousewheel.min.js
4 lines (4 loc) · 2.7 KB
/
jquery.mousewheel.min.js
1
2
3
4
!/*!
* jQuery Mousewheel 3.2.2
* Copyright OpenJS Foundation and other contributors
*/function(e){"use strict";"function"==typeof define&&define.amd?define(["jquery"],e):"object"==typeof exports?module.exports=e:e(jQuery)}(function(e){"use strict";var t,n,i=!!e.fn.on,o=["wheel","mousewheel","DOMMouseScroll","MozMousePixelScroll"],l="onwheel"in window.document||window.document.documentMode>=9?["wheel"]:["mousewheel","DomMouseScroll","MozMousePixelScroll"],s=Array.prototype.slice;if(e.event.fixHooks)for(var a=o.length;a;)e.event.fixHooks[o[--a]]=e.event.mouseHooks;var h=e.event.special.mousewheel={version:"3.2.2",setup:function(){if(this.addEventListener)for(var t=l.length;t;)this.addEventListener(l[--t],r,!1);else this.onmousewheel=r;e.data(this,"mousewheel-line-height",h.getLineHeight(this)),e.data(this,"mousewheel-page-height",h.getPageHeight(this))},teardown:function(){if(this.removeEventListener)for(var t=l.length;t;)this.removeEventListener(l[--t],r,!1);else this.onmousewheel=null;e.removeData(this,"mousewheel-line-height"),e.removeData(this,"mousewheel-page-height")},getLineHeight:function(t){var n=e(t),i=n["offsetParent"in e.fn?"offsetParent":"parent"]();return i.length||(i=e("body")),parseInt(i.css("fontSize"),10)||parseInt(n.css("fontSize"),10)||16},getPageHeight:function(t){return e(t).height()},settings:{adjustOldDeltas:!0,normalizeOffset:!0}};function r(i){var o=i||window.event,l=s.call(arguments,1),a=0,r=0,f=0,d=0;if((i=e.event.fix(o)).type="mousewheel","detail"in o&&(f=-1*o.detail),"wheelDelta"in o&&(f=o.wheelDelta),"wheelDeltaY"in o&&(f=o.wheelDeltaY),"wheelDeltaX"in o&&(r=-1*o.wheelDeltaX),"axis"in o&&o.axis===o.HORIZONTAL_AXIS&&(r=-1*f,f=0),a=0===f?r:f,"deltaY"in o&&(a=f=-1*o.deltaY),"deltaX"in o&&(r=o.deltaX,0===f&&(a=-1*r)),0!==f||0!==r){if(1===o.deltaMode){var w=e.data(this,"mousewheel-line-height");a*=w,f*=w,r*=w}else if(2===o.deltaMode){var c=e.data(this,"mousewheel-page-height");a*=c,f*=c,r*=c}if(d=Math.max(Math.abs(f),Math.abs(r)),(!n||d<n)&&(n=d,u(o,d)&&(n/=40)),u(o,d)&&(a/=40,r/=40,f/=40),a=Math[a>=1?"floor":"ceil"](a/n),r=Math[r>=1?"floor":"ceil"](r/n),f=Math[f>=1?"floor":"ceil"](f/n),h.settings.normalizeOffset&&this.getBoundingClientRect){var m=this.getBoundingClientRect();i.offsetX=i.clientX-m.left,i.offsetY=i.clientY-m.top}return i.deltaX=r,i.deltaY=f,i.deltaFactor=n,i.deltaMode=0,l.unshift(i,a,r,f),t&&window.clearTimeout(t),t=window.setTimeout(function(){n=null},200),(e.event.dispatch||e.event.handle).apply(this,l)}}function u(e,t){return h.settings.adjustOldDeltas&&"mousewheel"===e.type&&t%120==0}e.fn.extend({mousewheel:function(e){return e?this[i?"on":"bind"]("mousewheel",e):this.trigger("mousewheel")},unmousewheel:function(e){return this[i?"off":"unbind"]("mousewheel",e)}})});