@better-scroll/wheel
Advanced tools
Comparing version 2.0.3 to 2.0.4
@@ -179,4 +179,14 @@ /*! | ||
var actionsHandler = scroller.actionsHandler, scrollBehaviorX = scroller.scrollBehaviorX, scrollBehaviorY = scroller.scrollBehaviorY, animater = scroller.animater; | ||
var prevContent = scroller.content; | ||
// BScroll | ||
this.scroll.hooks.on(this.scroll.hooks.eventTypes.refresh, function (content) { | ||
if (content !== prevContent) { | ||
prevContent = content; | ||
_this.handleSelectedIndex(); | ||
} | ||
// check we are stop at a disable item | ||
_this.wheelTo(_this.selectedIndex, 0); | ||
}); | ||
this.scroll.hooks.on(this.scroll.hooks.eventTypes.beforeInitialScrollTo, function (position) { | ||
// selectedIndex has a better priority than bs.options.startY | ||
position.x = 0; | ||
@@ -273,5 +283,5 @@ position.y = -(_this.selectedIndex * _this.itemHeight); | ||
Wheel.prototype.refreshBoundary = function () { | ||
var _a = this.scroll.scroller, scrollBehaviorX = _a.scrollBehaviorX, scrollBehaviorY = _a.scrollBehaviorY; | ||
scrollBehaviorX.refresh(); | ||
scrollBehaviorY.refresh(); | ||
var _a = this.scroll.scroller, scrollBehaviorX = _a.scrollBehaviorX, scrollBehaviorY = _a.scrollBehaviorY, content = _a.content; | ||
scrollBehaviorX.refresh(content); | ||
scrollBehaviorY.refresh(content); | ||
}; | ||
@@ -278,0 +288,0 @@ Wheel.prototype.handleSelectedIndex = function () { |
@@ -185,4 +185,14 @@ /*! | ||
var actionsHandler = scroller.actionsHandler, scrollBehaviorX = scroller.scrollBehaviorX, scrollBehaviorY = scroller.scrollBehaviorY, animater = scroller.animater; | ||
var prevContent = scroller.content; | ||
// BScroll | ||
this.scroll.hooks.on(this.scroll.hooks.eventTypes.refresh, function (content) { | ||
if (content !== prevContent) { | ||
prevContent = content; | ||
_this.handleSelectedIndex(); | ||
} | ||
// check we are stop at a disable item | ||
_this.wheelTo(_this.selectedIndex, 0); | ||
}); | ||
this.scroll.hooks.on(this.scroll.hooks.eventTypes.beforeInitialScrollTo, function (position) { | ||
// selectedIndex has a better priority than bs.options.startY | ||
position.x = 0; | ||
@@ -279,5 +289,5 @@ position.y = -(_this.selectedIndex * _this.itemHeight); | ||
Wheel.prototype.refreshBoundary = function () { | ||
var _a = this.scroll.scroller, scrollBehaviorX = _a.scrollBehaviorX, scrollBehaviorY = _a.scrollBehaviorY; | ||
scrollBehaviorX.refresh(); | ||
scrollBehaviorY.refresh(); | ||
var _a = this.scroll.scroller, scrollBehaviorX = _a.scrollBehaviorX, scrollBehaviorY = _a.scrollBehaviorY, content = _a.content; | ||
scrollBehaviorX.refresh(content); | ||
scrollBehaviorY.refresh(content); | ||
}; | ||
@@ -284,0 +294,0 @@ Wheel.prototype.handleSelectedIndex = function () { |
@@ -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).Wheel=t()}(this,function(){"use strict";var n="undefined"!=typeof window,o=n&&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]}(),n&&document.createElement("div").style),t=function(){if(!n)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)}t&&"standard"!==t&&t.toLowerCase();var s=e("transform"),r=(e("transition"),n&&e("perspective")in i,s),l=e("transitionTimingFunction"),a=e("transitionDuration");e("transitionDelay"),e("transformOrigin"),e("transitionEnd"),e("transitionProperty");function h(e,t){return new RegExp("(^|\\s)"+t+"(\\s|$)").test(e.className)}var c={style:"cubic-bezier(0.23, 1, 0.32, 1)",fn:function(e){return 1+--e*e*e*e*e}},d=[{key:"wheelTo",name:"wheelTo"},{key:"getSelectedIndex",name:"getSelectedIndex"}].map(function(e){return{key:e.key,sourceKey:"plugins.wheel."+e.name}}),u=4;function f(e){this.scroll=e,this.init()}return f.prototype.init=function(){this.handleBScroll(),this.handleOptions(),this.handleHooks(),this.refreshBoundary(),this.handleSelectedIndex()},f.prototype.handleBScroll=function(){this.scroll.proxy(d)},f.prototype.handleOptions=function(){var e=!0===this.scroll.options.wheel?{}:this.scroll.options.wheel;this.options=function(e,t){for(var o in t)e[o]=t[o];return e}({wheelWrapperClass:"wheel-scroll",wheelItemClass:"wheel-item",rotate:25,adjustTime:400,selectedIndex:0,wheelDisabledItemClass:"wheel-disabled-item"},e)},f.prototype.handleHooks=function(){var o=this,e=this.scroll.scroller,t=e.actionsHandler,n=e.scrollBehaviorX,i=e.scrollBehaviorY,s=e.animater;this.scroll.hooks.on(this.scroll.hooks.eventTypes.beforeInitialScrollTo,function(e){e.x=0,e.y=-(o.selectedIndex*o.itemHeight)}),e.hooks.on(e.hooks.eventTypes.checkClick,function(){var e=Array.prototype.slice.call(o.items,0).indexOf(o.target);return-1===e||o.wheelToAfterClick(e,o.options.adjustTime,c),!0}),e.hooks.on(e.hooks.eventTypes.scrollTo,function(e){e.y=o.findNearestValidWheel(e.y).y}),e.hooks.on(e.hooks.eventTypes.scrollToElement,function(e,t){return!h(e,o.options.wheelItemClass)||void(t.top=o.findNearestValidWheel(t.top).y)}),t.hooks.on(t.hooks.eventTypes.beforeStart,function(e){o.target=e.target}),n.hooks.on(n.hooks.eventTypes.computeBoundary,function(e){e.maxScrollPos=0,e.minScrollPos=0}),i.hooks.on(i.hooks.eventTypes.computeBoundary,function(e){o.items=o.scroll.scroller.content.children,o.checkWheelAllDisabled(),o.itemHeight=0<o.items.length?i.contentSize/o.items.length:0,e.maxScrollPos=-o.itemHeight*(o.items.length-1),e.minScrollPos=0}),i.hooks.on(i.hooks.eventTypes.momentum,function(e,t){e.rate=u,e.destination=o.findNearestValidWheel(e.destination).y;t<1e3&&(e.duration=Math.max(800,t/1e3*o.scroll.options.swipeTime))}),i.hooks.on(i.hooks.eventTypes.end,function(e){var t=o.findNearestValidWheel(i.currentPos);e.destination=t.y,e.duration=o.options.adjustTime,o.selectedIndex=t.index}),s.hooks.on(s.hooks.eventTypes.time,function(e){o.transitionDuration(e)}),s.hooks.on(s.hooks.eventTypes.timeFunction,function(e){o.timeFunction(e)}),s.hooks.on(s.hooks.eventTypes.beforeForceStop,function(e){var t=e.y;return o.target=o.items[o.findNearestValidWheel(t).index],!0}),s.hooks.on(s.hooks.eventTypes.callStop,function(){var e,t=Array.prototype.slice.call(o.items,0).indexOf(o.target);0<t&&(e=-(t*o.itemHeight),s.translate({x:0,y:e}))}),s.translater.hooks.on(s.translater.hooks.eventTypes.translate,function(e){o.rotateX(e.y),o.selectedIndex=o.findNearestValidWheel(e.y).index})},f.prototype.refreshBoundary=function(){var e=this.scroll.scroller,t=e.scrollBehaviorX,o=e.scrollBehaviorY;t.refresh(),o.refresh()},f.prototype.handleSelectedIndex=function(){this.selectedIndex=this.options.selectedIndex},f.prototype.getSelectedIndex=function(){return this.selectedIndex},f.prototype.wheelTo=function(e,t,o){void 0===e&&(e=0),void 0===t&&(t=0);var n=-e*this.itemHeight,i=Math.round(this.scroll.y);return this.scroll.scrollTo(0,n,t,o),n===i},f.prototype.wheelToAfterClick=function(e,t,o){var n;void 0===e&&(e=0),void 0===t&&(t=0),this.wheelTo(e,t,o)&&(n=this.scroll.scroller.hooks).trigger(n.eventTypes.scrollEnd)},f.prototype.transitionDuration=function(e){for(var t=0;t<this.items.length;t++)this.items[t].style[a]=e+"ms"},f.prototype.timeFunction=function(e){for(var t=0;t<this.items.length;t++)this.items[t].style[l]=e},f.prototype.rotateX=function(e){for(var t=this.options.rotate,o=void 0===t?25:t,n=0;n<this.items.length;n++){var i=(o*(e/this.itemHeight+n)).toFixed(3);this.items[n].style[r]="rotateX("+i+"deg)"}},f.prototype.findNearestValidWheel=function(e){e=0<e?0:e<this.scroll.maxScrollY?this.scroll.maxScrollY:e;for(var t=Math.abs(Math.round(-e/this.itemHeight)),o=t,n=this.items,i=this.options.wheelDisabledItemClass;0<=t&&h(n[t],i);)t--;if(t<0)for(t=o;t<=n.length-1&&h(n[t],i);)t++;return t===n.length&&(t=o),{index:this.wheelItemsAllDisabled?-1:t,y:-t*this.itemHeight}},f.prototype.checkWheelAllDisabled=function(){var e=this.options.wheelDisabledItemClass,t=this.items;this.wheelItemsAllDisabled=!0;for(var o=0;o<t.length;o++)if(!h(t[o],e)){this.wheelItemsAllDisabled=!1;break}},f.pluginName="wheel",f}); | ||
!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).Wheel=t()}(this,function(){"use strict";var n="undefined"!=typeof window,o=n&&navigator.userAgent.toLowerCase(),s=(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]}(),n&&document.createElement("div").style),t=function(){if(!n)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!==s[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)}t&&"standard"!==t&&t.toLowerCase();var i=e("transform"),r=(e("transition"),n&&e("perspective")in s,i),l=e("transitionTimingFunction"),a=e("transitionDuration");e("transitionDelay"),e("transformOrigin"),e("transitionEnd"),e("transitionProperty");function h(e,t){return new RegExp("(^|\\s)"+t+"(\\s|$)").test(e.className)}var c={style:"cubic-bezier(0.23, 1, 0.32, 1)",fn:function(e){return 1+--e*e*e*e*e}},d=[{key:"wheelTo",name:"wheelTo"},{key:"getSelectedIndex",name:"getSelectedIndex"}].map(function(e){return{key:e.key,sourceKey:"plugins.wheel."+e.name}}),u=4;function f(e){this.scroll=e,this.init()}return f.prototype.init=function(){this.handleBScroll(),this.handleOptions(),this.handleHooks(),this.refreshBoundary(),this.handleSelectedIndex()},f.prototype.handleBScroll=function(){this.scroll.proxy(d)},f.prototype.handleOptions=function(){var e=!0===this.scroll.options.wheel?{}:this.scroll.options.wheel;this.options=function(e,t){for(var o in t)e[o]=t[o];return e}({wheelWrapperClass:"wheel-scroll",wheelItemClass:"wheel-item",rotate:25,adjustTime:400,selectedIndex:0,wheelDisabledItemClass:"wheel-disabled-item"},e)},f.prototype.handleHooks=function(){var o=this,e=this.scroll.scroller,t=e.actionsHandler,n=e.scrollBehaviorX,s=e.scrollBehaviorY,i=e.animater,r=e.content;this.scroll.hooks.on(this.scroll.hooks.eventTypes.refresh,function(e){e!==r&&(r=e,o.handleSelectedIndex()),o.wheelTo(o.selectedIndex,0)}),this.scroll.hooks.on(this.scroll.hooks.eventTypes.beforeInitialScrollTo,function(e){e.x=0,e.y=-(o.selectedIndex*o.itemHeight)}),e.hooks.on(e.hooks.eventTypes.checkClick,function(){var e=Array.prototype.slice.call(o.items,0).indexOf(o.target);return-1===e||o.wheelToAfterClick(e,o.options.adjustTime,c),!0}),e.hooks.on(e.hooks.eventTypes.scrollTo,function(e){e.y=o.findNearestValidWheel(e.y).y}),e.hooks.on(e.hooks.eventTypes.scrollToElement,function(e,t){return!h(e,o.options.wheelItemClass)||void(t.top=o.findNearestValidWheel(t.top).y)}),t.hooks.on(t.hooks.eventTypes.beforeStart,function(e){o.target=e.target}),n.hooks.on(n.hooks.eventTypes.computeBoundary,function(e){e.maxScrollPos=0,e.minScrollPos=0}),s.hooks.on(s.hooks.eventTypes.computeBoundary,function(e){o.items=o.scroll.scroller.content.children,o.checkWheelAllDisabled(),o.itemHeight=0<o.items.length?s.contentSize/o.items.length:0,e.maxScrollPos=-o.itemHeight*(o.items.length-1),e.minScrollPos=0}),s.hooks.on(s.hooks.eventTypes.momentum,function(e,t){e.rate=u,e.destination=o.findNearestValidWheel(e.destination).y;t<1e3&&(e.duration=Math.max(800,t/1e3*o.scroll.options.swipeTime))}),s.hooks.on(s.hooks.eventTypes.end,function(e){var t=o.findNearestValidWheel(s.currentPos);e.destination=t.y,e.duration=o.options.adjustTime,o.selectedIndex=t.index}),i.hooks.on(i.hooks.eventTypes.time,function(e){o.transitionDuration(e)}),i.hooks.on(i.hooks.eventTypes.timeFunction,function(e){o.timeFunction(e)}),i.hooks.on(i.hooks.eventTypes.beforeForceStop,function(e){var t=e.y;return o.target=o.items[o.findNearestValidWheel(t).index],!0}),i.hooks.on(i.hooks.eventTypes.callStop,function(){var e,t=Array.prototype.slice.call(o.items,0).indexOf(o.target);0<t&&(e=-(t*o.itemHeight),i.translate({x:0,y:e}))}),i.translater.hooks.on(i.translater.hooks.eventTypes.translate,function(e){o.rotateX(e.y),o.selectedIndex=o.findNearestValidWheel(e.y).index})},f.prototype.refreshBoundary=function(){var e=this.scroll.scroller,t=e.scrollBehaviorX,o=e.scrollBehaviorY,n=e.content;t.refresh(n),o.refresh(n)},f.prototype.handleSelectedIndex=function(){this.selectedIndex=this.options.selectedIndex},f.prototype.getSelectedIndex=function(){return this.selectedIndex},f.prototype.wheelTo=function(e,t,o){void 0===e&&(e=0),void 0===t&&(t=0);var n=-e*this.itemHeight,s=Math.round(this.scroll.y);return this.scroll.scrollTo(0,n,t,o),n===s},f.prototype.wheelToAfterClick=function(e,t,o){var n;void 0===e&&(e=0),void 0===t&&(t=0),this.wheelTo(e,t,o)&&(n=this.scroll.scroller.hooks).trigger(n.eventTypes.scrollEnd)},f.prototype.transitionDuration=function(e){for(var t=0;t<this.items.length;t++)this.items[t].style[a]=e+"ms"},f.prototype.timeFunction=function(e){for(var t=0;t<this.items.length;t++)this.items[t].style[l]=e},f.prototype.rotateX=function(e){for(var t=this.options.rotate,o=void 0===t?25:t,n=0;n<this.items.length;n++){var s=(o*(e/this.itemHeight+n)).toFixed(3);this.items[n].style[r]="rotateX("+s+"deg)"}},f.prototype.findNearestValidWheel=function(e){e=0<e?0:e<this.scroll.maxScrollY?this.scroll.maxScrollY:e;for(var t=Math.abs(Math.round(-e/this.itemHeight)),o=t,n=this.items,s=this.options.wheelDisabledItemClass;0<=t&&h(n[t],s);)t--;if(t<0)for(t=o;t<=n.length-1&&h(n[t],s);)t++;return t===n.length&&(t=o),{index:this.wheelItemsAllDisabled?-1:t,y:-t*this.itemHeight}},f.prototype.checkWheelAllDisabled=function(){var e=this.options.wheelDisabledItemClass,t=this.items;this.wheelItemsAllDisabled=!0;for(var o=0;o<t.length;o++)if(!h(t[o],e)){this.wheelItemsAllDisabled=!1;break}},f.pluginName="wheel",f}); |
{ | ||
"name": "@better-scroll/wheel", | ||
"version": "2.0.3", | ||
"version": "2.0.4", | ||
"description": "a BetterScroll plugin to imitate IOS Picker", | ||
@@ -32,5 +32,5 @@ "author": { | ||
"dependencies": { | ||
"@better-scroll/core": "^2.0.3" | ||
"@better-scroll/core": "^2.0.4" | ||
}, | ||
"gitHead": "e8192135b353685a0f527afc197c21c77a86515c" | ||
"gitHead": "5a305c565dc81458a4140a572463bb872e67384a" | ||
} |
@@ -88,6 +88,20 @@ import BScroll, { Boundary } from '@better-scroll/core' | ||
} = scroller | ||
let prevContent = scroller.content | ||
// BScroll | ||
this.scroll.hooks.on( | ||
this.scroll.hooks.eventTypes.refresh, | ||
(content: HTMLElement) => { | ||
if (content !== prevContent) { | ||
prevContent = content | ||
this.handleSelectedIndex() | ||
} | ||
// check we are stop at a disable item | ||
this.wheelTo(this.selectedIndex, 0) | ||
} | ||
) | ||
this.scroll.hooks.on( | ||
this.scroll.hooks.eventTypes.beforeInitialScrollTo, | ||
(position: { x: number; y: number }) => { | ||
// selectedIndex has a better priority than bs.options.startY | ||
position.x = 0 | ||
@@ -234,5 +248,5 @@ position.y = -(this.selectedIndex * this.itemHeight) | ||
private refreshBoundary() { | ||
const { scrollBehaviorX, scrollBehaviorY } = this.scroll.scroller | ||
scrollBehaviorX.refresh() | ||
scrollBehaviorY.refresh() | ||
const { scrollBehaviorX, scrollBehaviorY, content } = this.scroll.scroller | ||
scrollBehaviorX.refresh(content) | ||
scrollBehaviorY.refresh(content) | ||
} | ||
@@ -239,0 +253,0 @@ |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
58364
1421
Updated@better-scroll/core@^2.0.4