@better-scroll/mouse-wheel
Advanced tools
Comparing version 2.2.0 to 2.2.1
@@ -30,2 +30,18 @@ /*! | ||
})(); | ||
/* istanbul ignore next */ | ||
var supportsPassive = false; | ||
/* istanbul ignore next */ | ||
if (inBrowser) { | ||
var EventName = 'test-passive'; | ||
try { | ||
var opts = {}; | ||
Object.defineProperty(opts, 'passive', { | ||
get: function () { | ||
supportsPassive = true; | ||
}, | ||
}); // https://github.com/facebook/flow/issues/285 | ||
window.addEventListener(EventName, function () { }, opts); | ||
} | ||
catch (e) { } | ||
} | ||
@@ -91,6 +107,9 @@ var extend = function (target, source) { | ||
function addEvent(el, type, fn, capture) { | ||
el.addEventListener(type, fn, { | ||
passive: false, | ||
capture: !!capture, | ||
}); | ||
var useCapture = supportsPassive | ||
? { | ||
passive: false, | ||
capture: !!capture, | ||
} | ||
: !!capture; | ||
el.addEventListener(type, fn, useCapture); | ||
} | ||
@@ -97,0 +116,0 @@ function removeEvent(el, type, fn, capture) { |
@@ -36,2 +36,18 @@ /*! | ||
})(); | ||
/* istanbul ignore next */ | ||
var supportsPassive = false; | ||
/* istanbul ignore next */ | ||
if (inBrowser) { | ||
var EventName = 'test-passive'; | ||
try { | ||
var opts = {}; | ||
Object.defineProperty(opts, 'passive', { | ||
get: function () { | ||
supportsPassive = true; | ||
}, | ||
}); // https://github.com/facebook/flow/issues/285 | ||
window.addEventListener(EventName, function () { }, opts); | ||
} | ||
catch (e) { } | ||
} | ||
@@ -97,6 +113,9 @@ var extend = function (target, source) { | ||
function addEvent(el, type, fn, capture) { | ||
el.addEventListener(type, fn, { | ||
passive: false, | ||
capture: !!capture, | ||
}); | ||
var useCapture = supportsPassive | ||
? { | ||
passive: false, | ||
capture: !!capture, | ||
} | ||
: !!capture; | ||
el.addEventListener(type, fn, useCapture); | ||
} | ||
@@ -103,0 +122,0 @@ function removeEvent(el, type, fn, capture) { |
@@ -1,1 +0,1 @@ | ||
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?module.exports=t():"function"==typeof define&&define.amd?define(t):(e="undefined"!=typeof globalThis?globalThis:e||self).MouseWheel=t()}(this,function(){"use strict";var r="undefined"!=typeof window,o=r&&navigator.userAgent.toLowerCase(),i=(o&&/wechatdevtools/.test(o),o&&o.indexOf("android"),function(){if("string"!=typeof o)return;var e=/os (\d\d?_\d(_\d)?)/.exec(o);if(!e)return;var t=e[1].split("_").map(function(e){return parseInt(e,10)});13===t[0]&&t[1]}(),r&&document.createElement("div").style),t=function(){if(!r)return!1;for(var e=0,t=[{key:"standard",value:"transform"},{key:"webkit",value:"webkitTransform"},{key:"Moz",value:"MozTransform"},{key:"O",value:"OTransform"},{key:"ms",value:"msTransform"}];e<t.length;e++){var o=t[e];if(void 0!==i[o.value])return o.key}return!1}();function e(e){return!1===t?e:"standard"===t?"transitionEnd"===e?"transitionend":e:t+e.charAt(0).toUpperCase()+e.substr(1)}function n(e,t,o,r){e.addEventListener(t,o,{passive:!1,capture:!!r})}function s(e,t,o,r){e.removeEventListener(t,o,{capture:!!r})}t&&"standard"!==t&&t.toLowerCase();var l=e("transform"),a=e("transition");r&&e("perspective")in i,e("transitionTimingFunction"),e("transitionDuration"),e("transitionDelay"),e("transformOrigin"),e("transitionEnd"),e("transitionProperty");var h=(c.prototype.destroy=function(){this.removeDOMEvents(),this.events=[]},c.prototype.addDOMEvents=function(){this.handleDOMEvents(n)},c.prototype.removeDOMEvents=function(){this.handleDOMEvents(s)},c.prototype.handleDOMEvents=function(t){var o=this,r=this.wrapper;this.events.forEach(function(e){t(r,e.name,o,!!e.capture)})},c.prototype.handleEvent=function(t){var o=t.type;this.events.some(function(e){return e.name===o&&(e.handler(t),!0)})},c);function c(e,t){this.wrapper=e,this.events=t,this.addDOMEvents()}function d(e){this.scroll=e,this.wheelEndTimer=0,this.wheelMoveTimer=0,this.wheelStart=!1,this.init()}return d.prototype.init=function(){this.handleBScroll(),this.handleOptions(),this.handleHooks(),this.registerEvent()},d.prototype.handleBScroll=function(){this.scroll.registerType(["alterOptions","mousewheelStart","mousewheelMove","mousewheelEnd"])},d.prototype.handleOptions=function(){var e=!0===this.scroll.options.mouseWheel?{}:this.scroll.options.mouseWheel;this.mouseWheelOpt=function(e,t){for(var o in t)e[o]=t[o];return e}({speed:20,invert:!1,easeTime:300,discreteTime:400,throttleTime:0,dampingFactor:.1},e)},d.prototype.handleHooks=function(){this.hooksFn=[],this.registerHooks(this.scroll.hooks,"destroy",this.destroy)},d.prototype.registerEvent=function(){this.eventRegister=new h(this.scroll.scroller.wrapper,[{name:"wheel",handler:this.wheelHandler.bind(this)},{name:"mousewheel",handler:this.wheelHandler.bind(this)},{name:"DOMMouseScroll",handler:this.wheelHandler.bind(this)}])},d.prototype.registerHooks=function(e,t,o){e.on(t,o,this),this.hooksFn.push([e,t,o])},d.prototype.wheelHandler=function(e){var t;this.scroll.enabled&&(this.beforeHandler(e),this.wheelStart||(this.wheelStartHandler(e),this.wheelStart=!0),t=this.getWheelDelta(e),this.wheelMoveHandler(t),this.wheelEndDetector(t))},d.prototype.wheelStartHandler=function(e){this.cleanCache();var t=this.scroll.scroller,o=t.scrollBehaviorX,r=t.scrollBehaviorY;o.setMovingDirection(0),r.setMovingDirection(0),o.setDirection(0),r.setDirection(0),this.scroll.trigger(this.scroll.eventTypes.alterOptions,this.mouseWheelOpt),this.scroll.trigger(this.scroll.eventTypes.mousewheelStart)},d.prototype.cleanCache=function(){this.deltaCache=[]},d.prototype.wheelMoveHandler=function(e){var t,o,r,i,n,s,l,a=this,h=this.mouseWheelOpt,c=h.throttleTime,d=h.dampingFactor;c&&this.wheelMoveTimer?this.deltaCache.push(e):(t=this.deltaCache.reduce(function(e,t){return{x:e.x+t.x,y:e.y+t.y}},{x:0,y:0}),this.cleanCache(),r=(o=this.scroll.scroller).scrollBehaviorX,i=o.scrollBehaviorY,r.setMovingDirection(-e.directionX),i.setMovingDirection(-e.directionY),r.setDirection(e.x),i.setDirection(e.y),n=r.performDampingAlgorithm(Math.round(e.x)+t.x,d),s=i.performDampingAlgorithm(Math.round(e.y)+t.x,d),this.scroll.trigger(this.scroll.eventTypes.mousewheelMove,{x:n,y:s})||(l=this.getEaseTime(),n===this.scroll.x&&s===this.scroll.y||this.scroll.scrollTo(n,s,l)),c&&(this.wheelMoveTimer=window.setTimeout(function(){a.wheelMoveTimer=0},c)))},d.prototype.wheelEndDetector=function(e){var t=this;window.clearTimeout(this.wheelEndTimer),this.wheelEndTimer=window.setTimeout(function(){t.wheelStart=!1,window.clearTimeout(t.wheelMoveTimer),t.wheelMoveTimer=0,t.scroll.trigger(t.scroll.eventTypes.mousewheelEnd,e)},this.mouseWheelOpt.discreteTime)},d.prototype.getWheelDelta=function(e){var t=this.mouseWheelOpt,o=t.speed,r=0,i=0,n=t.invert?-1:1;switch(!0){case"deltaX"in e:i=1===e.deltaMode?(r=-e.deltaX*o,-e.deltaY*o):(r=-e.deltaX,-e.deltaY);break;case"wheelDeltaX"in e:r=e.wheelDeltaX/120*o,i=e.wheelDeltaY/120*o;break;case"wheelDelta"in e:r=i=e.wheelDelta/120*o;break;case"detail"in e:r=i=-e.detail/3*o}return r*=n,i*=n,this.scroll.hasVerticalScroll||(r=i,i=0),this.scroll.hasHorizontalScroll||(r=0),{x:r,y:i,directionX:0<r?-1:r<0?1:0,directionY:0<i?-1:i<0?1:0}},d.prototype.beforeHandler=function(e){var t=this.scroll.options,o=t.preventDefault,r=t.stopPropagation,i=t.preventDefaultException;o&&!function(e,t){for(var o in t)if(t[o].test(e[o]))return 1}(e.target,i)&&e.preventDefault(),r&&e.stopPropagation()},d.prototype.getEaseTime=function(){var e=this.mouseWheelOpt.easeTime;return e<100&&console.error("[BScroll warn]: easeTime should be greater than 100.If mouseWheel easeTime is too small,scrollEnd will be triggered many times."),Math.max(e,100)},d.prototype.destroy=function(){this.eventRegister.destroy(),window.clearTimeout(this.wheelEndTimer),window.clearTimeout(this.wheelMoveTimer),this.hooksFn.forEach(function(e){var t=e[0],o=e[1],r=e[2];t.off(o,r)})},d.pluginName="mouseWheel",d.applyOrder="pre",d}); | ||
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?module.exports=t():"function"==typeof define&&define.amd?define(t):(e="undefined"!=typeof globalThis?globalThis:e||self).MouseWheel=t()}(this,function(){"use strict";var r="undefined"!=typeof window,o=r&&navigator.userAgent.toLowerCase(),n=(o&&/wechatdevtools/.test(o),o&&o.indexOf("android"),function(){if("string"!=typeof o)return;var e=/os (\d\d?_\d(_\d)?)/.exec(o);if(!e)return;var t=e[1].split("_").map(function(e){return parseInt(e,10)});13===t[0]&&t[1]}(),!1);if(r){try{var e={};Object.defineProperty(e,"passive",{get:function(){n=!0}}),window.addEventListener("test-passive",function(){},e)}catch(e){}}var i=r&&document.createElement("div").style,t=function(){if(!r)return!1;for(var e=0,t=[{key:"standard",value:"transform"},{key:"webkit",value:"webkitTransform"},{key:"Moz",value:"MozTransform"},{key:"O",value:"OTransform"},{key:"ms",value:"msTransform"}];e<t.length;e++){var o=t[e];if(void 0!==i[o.value])return o.key}return!1}();function s(e){return!1===t?e:"standard"===t?"transitionEnd"===e?"transitionend":e:t+e.charAt(0).toUpperCase()+e.substr(1)}function l(e,t,o,r){var i=n?{passive:!1,capture:!!r}:!!r;e.addEventListener(t,o,i)}function a(e,t,o,r){e.removeEventListener(t,o,{capture:!!r})}t&&"standard"!==t&&t.toLowerCase();var h=s("transform"),c=s("transition");r&&s("perspective")in i,s("transitionTimingFunction"),s("transitionDuration"),s("transitionDelay"),s("transformOrigin"),s("transitionEnd"),s("transitionProperty");var d=(p.prototype.destroy=function(){this.removeDOMEvents(),this.events=[]},p.prototype.addDOMEvents=function(){this.handleDOMEvents(l)},p.prototype.removeDOMEvents=function(){this.handleDOMEvents(a)},p.prototype.handleDOMEvents=function(t){var o=this,r=this.wrapper;this.events.forEach(function(e){t(r,e.name,o,!!e.capture)})},p.prototype.handleEvent=function(t){var o=t.type;this.events.some(function(e){return e.name===o&&(e.handler(t),!0)})},p);function p(e,t){this.wrapper=e,this.events=t,this.addDOMEvents()}function u(e){this.scroll=e,this.wheelEndTimer=0,this.wheelMoveTimer=0,this.wheelStart=!1,this.init()}return u.prototype.init=function(){this.handleBScroll(),this.handleOptions(),this.handleHooks(),this.registerEvent()},u.prototype.handleBScroll=function(){this.scroll.registerType(["alterOptions","mousewheelStart","mousewheelMove","mousewheelEnd"])},u.prototype.handleOptions=function(){var e=!0===this.scroll.options.mouseWheel?{}:this.scroll.options.mouseWheel;this.mouseWheelOpt=function(e,t){for(var o in t)e[o]=t[o];return e}({speed:20,invert:!1,easeTime:300,discreteTime:400,throttleTime:0,dampingFactor:.1},e)},u.prototype.handleHooks=function(){this.hooksFn=[],this.registerHooks(this.scroll.hooks,"destroy",this.destroy)},u.prototype.registerEvent=function(){this.eventRegister=new d(this.scroll.scroller.wrapper,[{name:"wheel",handler:this.wheelHandler.bind(this)},{name:"mousewheel",handler:this.wheelHandler.bind(this)},{name:"DOMMouseScroll",handler:this.wheelHandler.bind(this)}])},u.prototype.registerHooks=function(e,t,o){e.on(t,o,this),this.hooksFn.push([e,t,o])},u.prototype.wheelHandler=function(e){var t;this.scroll.enabled&&(this.beforeHandler(e),this.wheelStart||(this.wheelStartHandler(e),this.wheelStart=!0),t=this.getWheelDelta(e),this.wheelMoveHandler(t),this.wheelEndDetector(t))},u.prototype.wheelStartHandler=function(e){this.cleanCache();var t=this.scroll.scroller,o=t.scrollBehaviorX,r=t.scrollBehaviorY;o.setMovingDirection(0),r.setMovingDirection(0),o.setDirection(0),r.setDirection(0),this.scroll.trigger(this.scroll.eventTypes.alterOptions,this.mouseWheelOpt),this.scroll.trigger(this.scroll.eventTypes.mousewheelStart)},u.prototype.cleanCache=function(){this.deltaCache=[]},u.prototype.wheelMoveHandler=function(e){var t,o,r,i,n,s,l,a=this,h=this.mouseWheelOpt,c=h.throttleTime,d=h.dampingFactor;c&&this.wheelMoveTimer?this.deltaCache.push(e):(t=this.deltaCache.reduce(function(e,t){return{x:e.x+t.x,y:e.y+t.y}},{x:0,y:0}),this.cleanCache(),r=(o=this.scroll.scroller).scrollBehaviorX,i=o.scrollBehaviorY,r.setMovingDirection(-e.directionX),i.setMovingDirection(-e.directionY),r.setDirection(e.x),i.setDirection(e.y),n=r.performDampingAlgorithm(Math.round(e.x)+t.x,d),s=i.performDampingAlgorithm(Math.round(e.y)+t.x,d),this.scroll.trigger(this.scroll.eventTypes.mousewheelMove,{x:n,y:s})||(l=this.getEaseTime(),n===this.scroll.x&&s===this.scroll.y||this.scroll.scrollTo(n,s,l)),c&&(this.wheelMoveTimer=window.setTimeout(function(){a.wheelMoveTimer=0},c)))},u.prototype.wheelEndDetector=function(e){var t=this;window.clearTimeout(this.wheelEndTimer),this.wheelEndTimer=window.setTimeout(function(){t.wheelStart=!1,window.clearTimeout(t.wheelMoveTimer),t.wheelMoveTimer=0,t.scroll.trigger(t.scroll.eventTypes.mousewheelEnd,e)},this.mouseWheelOpt.discreteTime)},u.prototype.getWheelDelta=function(e){var t=this.mouseWheelOpt,o=t.speed,r=0,i=0,n=t.invert?-1:1;switch(!0){case"deltaX"in e:i=1===e.deltaMode?(r=-e.deltaX*o,-e.deltaY*o):(r=-e.deltaX,-e.deltaY);break;case"wheelDeltaX"in e:r=e.wheelDeltaX/120*o,i=e.wheelDeltaY/120*o;break;case"wheelDelta"in e:r=i=e.wheelDelta/120*o;break;case"detail"in e:r=i=-e.detail/3*o}return r*=n,i*=n,this.scroll.hasVerticalScroll||(r=i,i=0),this.scroll.hasHorizontalScroll||(r=0),{x:r,y:i,directionX:0<r?-1:r<0?1:0,directionY:0<i?-1:i<0?1:0}},u.prototype.beforeHandler=function(e){var t=this.scroll.options,o=t.preventDefault,r=t.stopPropagation,i=t.preventDefaultException;o&&!function(e,t){for(var o in t)if(t[o].test(e[o]))return 1}(e.target,i)&&e.preventDefault(),r&&e.stopPropagation()},u.prototype.getEaseTime=function(){var e=this.mouseWheelOpt.easeTime;return e<100&&console.error("[BScroll warn]: easeTime should be greater than 100.If mouseWheel easeTime is too small,scrollEnd will be triggered many times."),Math.max(e,100)},u.prototype.destroy=function(){this.eventRegister.destroy(),window.clearTimeout(this.wheelEndTimer),window.clearTimeout(this.wheelMoveTimer),this.hooksFn.forEach(function(e){var t=e[0],o=e[1],r=e[2];t.off(o,r)})},u.pluginName="mouseWheel",u.applyOrder="pre",u}); |
{ | ||
"name": "@better-scroll/mouse-wheel", | ||
"version": "2.2.0", | ||
"version": "2.2.1", | ||
"description": "support for MouseWheel in PC", | ||
@@ -33,5 +33,5 @@ "author": { | ||
"dependencies": { | ||
"@better-scroll/core": "^2.2.0" | ||
"@better-scroll/core": "^2.2.1" | ||
}, | ||
"gitHead": "cd8ba877754670f3357f1b349be8d2266197e740" | ||
"gitHead": "d41c8c92ee01aa8f3a1beb222e8d7ebcf1a91df6" | ||
} |
56803
1450
Updated@better-scroll/core@^2.2.1