@better-scroll/mouse-wheel
Advanced tools
Comparing version 2.4.0 to 2.4.1
@@ -13,6 +13,6 @@ /*! | ||
var ua = inBrowser && navigator.userAgent.toLowerCase(); | ||
var isWeChatDevTools = !!(ua && /wechatdevtools/.test(ua)); | ||
var isAndroid = ua && ua.indexOf('android') > 0; | ||
!!(ua && /wechatdevtools/.test(ua)); | ||
ua && ua.indexOf('android') > 0; | ||
/* istanbul ignore next */ | ||
var isIOSBadVersion = (function () { | ||
((function () { | ||
if (typeof ua === 'string') { | ||
@@ -30,3 +30,3 @@ var regex = /os (\d\d?_\d(_\d)?)/; | ||
return false; | ||
})(); | ||
}))(); | ||
/* istanbul ignore next */ | ||
@@ -121,7 +121,7 @@ var supportsPassive = false; | ||
} | ||
var cssVendor = vendor && vendor !== 'standard' ? '-' + vendor.toLowerCase() + '-' : ''; | ||
vendor && vendor !== 'standard' ? '-' + vendor.toLowerCase() + '-' : ''; | ||
var transform = prefixStyle('transform'); | ||
var transition = prefixStyle('transition'); | ||
var hasPerspective = inBrowser && prefixStyle('perspective') in elementStyle; | ||
var style = { | ||
inBrowser && prefixStyle('perspective') in elementStyle; | ||
({ | ||
transform: transform, | ||
@@ -135,3 +135,3 @@ transition: transition, | ||
transitionProperty: prefixStyle('transitionProperty'), | ||
}; | ||
}); | ||
function preventDefaultExceptionFn(el, exceptions) { | ||
@@ -138,0 +138,0 @@ for (var i in exceptions) { |
@@ -19,6 +19,6 @@ /*! | ||
var ua = inBrowser && navigator.userAgent.toLowerCase(); | ||
var isWeChatDevTools = !!(ua && /wechatdevtools/.test(ua)); | ||
var isAndroid = ua && ua.indexOf('android') > 0; | ||
!!(ua && /wechatdevtools/.test(ua)); | ||
ua && ua.indexOf('android') > 0; | ||
/* istanbul ignore next */ | ||
var isIOSBadVersion = (function () { | ||
((function () { | ||
if (typeof ua === 'string') { | ||
@@ -36,3 +36,3 @@ var regex = /os (\d\d?_\d(_\d)?)/; | ||
return false; | ||
})(); | ||
}))(); | ||
/* istanbul ignore next */ | ||
@@ -127,7 +127,7 @@ var supportsPassive = false; | ||
} | ||
var cssVendor = vendor && vendor !== 'standard' ? '-' + vendor.toLowerCase() + '-' : ''; | ||
vendor && vendor !== 'standard' ? '-' + vendor.toLowerCase() + '-' : ''; | ||
var transform = prefixStyle('transform'); | ||
var transition = prefixStyle('transition'); | ||
var hasPerspective = inBrowser && prefixStyle('perspective') in elementStyle; | ||
var style = { | ||
inBrowser && prefixStyle('perspective') in elementStyle; | ||
({ | ||
transform: transform, | ||
@@ -141,3 +141,3 @@ transition: transition, | ||
transitionProperty: prefixStyle('transitionProperty'), | ||
}; | ||
}); | ||
function preventDefaultExceptionFn(el, exceptions) { | ||
@@ -144,0 +144,0 @@ for (var i in exceptions) { |
@@ -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(),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}); | ||
!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 i="undefined"!=typeof window,t=i&&navigator.userAgent.toLowerCase();t&&/wechatdevtools/.test(t),t&&t.indexOf("android"),function(){if("string"==typeof t){var e=/os (\d\d?_\d(_\d)?)/.exec(t);if(!e)return;e=e[1].split("_").map(function(e){return parseInt(e,10)});13===e[0]&&e[1]}}();var r=!1;if(i)try{var e={};Object.defineProperty(e,"passive",{get:function(){r=!0}}),window.addEventListener("test-passive",function(){},e)}catch(e){}var n=i&&document.createElement("div").style,o=function(){if(!i)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!==n[o.value])return o.key}return!1}();function s(e){return!1===o?e:"standard"===o?"transitionEnd"===e?"transitionend":e:o+e.charAt(0).toUpperCase()+e.substr(1)}function l(e,t,o,i){i=r?{passive:!1,capture:!!i}:!!i;e.addEventListener(t,o,i)}function a(e,t,o,i){e.removeEventListener(t,o,{capture:!!i})}o&&"standard"!==o&&o.toLowerCase();s("transform"),s("transition");i&&s("perspective")in n,s("transitionTimingFunction"),s("transitionDuration"),s("transitionDelay"),s("transformOrigin"),s("transitionEnd"),s("transitionProperty");var h=(c.prototype.destroy=function(){this.removeDOMEvents(),this.events=[]},c.prototype.addDOMEvents=function(){this.handleDOMEvents(l)},c.prototype.removeDOMEvents=function(){this.handleDOMEvents(a)},c.prototype.handleDOMEvents=function(t){var o=this,i=this.wrapper;this.events.forEach(function(e){t(i,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){this.scroll.enabled&&(this.beforeHandler(e),this.wheelStart||(this.wheelStartHandler(e),this.wheelStart=!0),e=this.getWheelDelta(e),this.wheelMoveHandler(e),this.wheelEndDetector(e))},d.prototype.wheelStartHandler=function(e){this.cleanCache();var t=this.scroll.scroller,o=t.scrollBehaviorX,t=t.scrollBehaviorY;o.setMovingDirection(0),t.setMovingDirection(0),o.setDirection(0),t.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,i=this,r=this.mouseWheelOpt,n=r.throttleTime,s=r.dampingFactor;n&&this.wheelMoveTimer?this.deltaCache.push(e):(o=this.deltaCache.reduce(function(e,t){return{x:e.x+t.x,y:e.y+t.y}},{x:0,y:0}),this.cleanCache(),r=(t=this.scroll.scroller).scrollBehaviorX,t=t.scrollBehaviorY,r.setMovingDirection(-e.directionX),t.setMovingDirection(-e.directionY),r.setDirection(e.x),t.setDirection(e.y),r=r.performDampingAlgorithm(Math.round(e.x)+o.x,s),o=t.performDampingAlgorithm(Math.round(e.y)+o.x,s),this.scroll.trigger(this.scroll.eventTypes.mousewheelMove,{x:r,y:o})||(s=this.getEaseTime(),r===this.scroll.x&&o===this.scroll.y||this.scroll.scrollTo(r,o,s)),n&&(this.wheelMoveTimer=window.setTimeout(function(){i.wheelMoveTimer=0},n)))},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,i=0,r=0,t=t.invert?-1:1;switch(!0){case"deltaX"in e:r=1===e.deltaMode?(i=-e.deltaX*o,-e.deltaY*o):(i=-e.deltaX,-e.deltaY);break;case"wheelDeltaX"in e:i=e.wheelDeltaX/120*o,r=e.wheelDeltaY/120*o;break;case"wheelDelta"in e:i=r=e.wheelDelta/120*o;break;case"detail"in e:i=r=-e.detail/3*o}return i*=t,r*=t,this.scroll.hasVerticalScroll||(i=r,r=0),{x:i=!this.scroll.hasHorizontalScroll?0:i,y:r,directionX:0<i?-1:i<0?1:0,directionY:0<r?-1:r<0?1:0}},d.prototype.beforeHandler=function(e){var t=this.scroll.options,o=t.preventDefault,i=t.stopPropagation,t=t.preventDefaultException;o&&!function(e,t){for(var o in t)if(t[o].test(e[o]))return 1}(e.target,t)&&e.preventDefault(),i&&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],e=e[2];t.off(o,e)})},d.pluginName="mouseWheel",d.applyOrder="pre",d}); |
{ | ||
"name": "@better-scroll/mouse-wheel", | ||
"version": "2.4.0", | ||
"version": "2.4.1", | ||
"description": "support for MouseWheel in PC", | ||
@@ -33,5 +33,5 @@ "author": { | ||
"dependencies": { | ||
"@better-scroll/core": "^2.4.0" | ||
"@better-scroll/core": "^2.4.1" | ||
}, | ||
"gitHead": "a33d24e10d2d6cb431a29f9b356274845f3c3787" | ||
"gitHead": "60637c0ad50b0810156f9bfb8a2c7306493e5026" | ||
} |
56552
Updated@better-scroll/core@^2.4.1