From 546620dd032cc72f06100cc589c7880611829e9e Mon Sep 17 00:00:00 2001 From: yurayarosh Date: Tue, 24 Sep 2019 12:24:30 +0300 Subject: [PATCH 1/2] Add vs passiveoption support --- index.js | 5 +++-- package-lock.json | 30 ++++++++++++++++++++++-------- smooth-scrolling.js | 5 +++-- 3 files changed, 28 insertions(+), 12 deletions(-) diff --git a/index.js b/index.js index b3c8e30..f7a7ec8 100644 --- a/index.js +++ b/index.js @@ -32,11 +32,12 @@ export default class Smooth { ticking: false } this.vs = this.vars.native ? null : new vs({ - limitInertia: this.options.vs && this.options.vs.limitInertia || false, + limitInertia: this.options.vs && this.options.vs.hasOwnProperty('limitInertia') ? this.options.vs.limitInertia : false, mouseMultiplier: this.options.vs && this.options.vs.mouseMultiplier || 1, touchMultiplier: this.options.vs && this.options.vs.touchMultiplier || 1.5, firefoxMultiplier: this.options.vs && this.options.vs.firefoxMultiplier || 30, - preventTouch: this.options.vs && this.options.vs.preventTouch || true + preventTouch: this.options.vs && this.options.vs.hasOwnProperty('preventTouch') ? this.options.vs.preventTouch : true, + passive: this.options.vs && this.options.vs.hasOwnProperty('passive') ? this.options.vs.passive : undefined, }) this.dom = { listener: this.options.listener || document.body, diff --git a/package-lock.json b/package-lock.json index 8c29e5b..d372d65 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,6 +1,6 @@ { "name": "smooth-scrolling", - "version": "2.3.11", + "version": "2.3.12", "lockfileVersion": 1, "requires": true, "dependencies": { @@ -1980,12 +1980,14 @@ "balanced-match": { "version": "1.0.0", "bundled": true, - "dev": true + "dev": true, + "optional": true }, "brace-expansion": { "version": "1.1.11", "bundled": true, "dev": true, + "optional": true, "requires": { "balanced-match": "^1.0.0", "concat-map": "0.0.1" @@ -2000,17 +2002,20 @@ "code-point-at": { "version": "1.1.0", "bundled": true, - "dev": true + "dev": true, + "optional": true }, "concat-map": { "version": "0.0.1", "bundled": true, - "dev": true + "dev": true, + "optional": true }, "console-control-strings": { "version": "1.1.0", "bundled": true, - "dev": true + "dev": true, + "optional": true }, "core-util-is": { "version": "1.0.2", @@ -2127,7 +2132,8 @@ "inherits": { "version": "2.0.3", "bundled": true, - "dev": true + "dev": true, + "optional": true }, "ini": { "version": "1.3.5", @@ -2139,6 +2145,7 @@ "version": "1.0.0", "bundled": true, "dev": true, + "optional": true, "requires": { "number-is-nan": "^1.0.0" } @@ -2153,6 +2160,7 @@ "version": "3.0.4", "bundled": true, "dev": true, + "optional": true, "requires": { "brace-expansion": "^1.1.7" } @@ -2160,12 +2168,14 @@ "minimist": { "version": "0.0.8", "bundled": true, - "dev": true + "dev": true, + "optional": true }, "minipass": { "version": "2.3.5", "bundled": true, "dev": true, + "optional": true, "requires": { "safe-buffer": "^5.1.2", "yallist": "^3.0.0" @@ -2184,6 +2194,7 @@ "version": "0.5.1", "bundled": true, "dev": true, + "optional": true, "requires": { "minimist": "0.0.8" } @@ -2264,7 +2275,8 @@ "number-is-nan": { "version": "1.0.1", "bundled": true, - "dev": true + "dev": true, + "optional": true }, "object-assign": { "version": "4.1.1", @@ -2276,6 +2288,7 @@ "version": "1.4.0", "bundled": true, "dev": true, + "optional": true, "requires": { "wrappy": "1" } @@ -2397,6 +2410,7 @@ "version": "1.0.2", "bundled": true, "dev": true, + "optional": true, "requires": { "code-point-at": "^1.0.0", "is-fullwidth-code-point": "^1.0.0", diff --git a/smooth-scrolling.js b/smooth-scrolling.js index 1522109..6d569ba 100644 --- a/smooth-scrolling.js +++ b/smooth-scrolling.js @@ -57,11 +57,12 @@ function () { ticking: false }; this.vs = this.vars["native"] ? null : new _virtualScroll["default"]({ - limitInertia: this.options.vs && this.options.vs.limitInertia || false, + limitInertia: this.options.vs && this.options.vs.hasOwnProperty('limitInertia') ? this.options.vs.limitInertia : false, mouseMultiplier: this.options.vs && this.options.vs.mouseMultiplier || 1, touchMultiplier: this.options.vs && this.options.vs.touchMultiplier || 1.5, firefoxMultiplier: this.options.vs && this.options.vs.firefoxMultiplier || 30, - preventTouch: this.options.vs && this.options.vs.preventTouch || true + preventTouch: this.options.vs && this.options.vs.hasOwnProperty('preventTouch') ? this.options.vs.preventTouch : true, + passive: this.options.vs && this.options.vs.hasOwnProperty('passive') ? this.options.vs.passive : undefined }); this.dom = { listener: this.options.listener || document.body, From ca021e9594cc46697b2a6309df817a244a4a6906 Mon Sep 17 00:00:00 2001 From: yurayarosh Date: Tue, 24 Sep 2019 17:42:59 +0300 Subject: [PATCH 2/2] update virtual-scroll version, add useKeyboard vs option --- index.js | 1 + package-lock.json | 40 +++++++++++++--------------------------- package.json | 2 +- smooth-scrolling.js | 11 +++++++---- 4 files changed, 22 insertions(+), 32 deletions(-) diff --git a/index.js b/index.js index f7a7ec8..2ae81c8 100644 --- a/index.js +++ b/index.js @@ -36,6 +36,7 @@ export default class Smooth { mouseMultiplier: this.options.vs && this.options.vs.mouseMultiplier || 1, touchMultiplier: this.options.vs && this.options.vs.touchMultiplier || 1.5, firefoxMultiplier: this.options.vs && this.options.vs.firefoxMultiplier || 30, + useKeyboard: this.options.vs && this.options.vs.hasOwnProperty('useKeyboard') ? this.options.vs.useKeyboard : true, preventTouch: this.options.vs && this.options.vs.hasOwnProperty('preventTouch') ? this.options.vs.preventTouch : true, passive: this.options.vs && this.options.vs.hasOwnProperty('passive') ? this.options.vs.passive : undefined, }) diff --git a/package-lock.json b/package-lock.json index d372d65..04f5b2a 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1980,14 +1980,12 @@ "balanced-match": { "version": "1.0.0", "bundled": true, - "dev": true, - "optional": true + "dev": true }, "brace-expansion": { "version": "1.1.11", "bundled": true, "dev": true, - "optional": true, "requires": { "balanced-match": "^1.0.0", "concat-map": "0.0.1" @@ -2002,20 +2000,17 @@ "code-point-at": { "version": "1.1.0", "bundled": true, - "dev": true, - "optional": true + "dev": true }, "concat-map": { "version": "0.0.1", "bundled": true, - "dev": true, - "optional": true + "dev": true }, "console-control-strings": { "version": "1.1.0", "bundled": true, - "dev": true, - "optional": true + "dev": true }, "core-util-is": { "version": "1.0.2", @@ -2132,8 +2127,7 @@ "inherits": { "version": "2.0.3", "bundled": true, - "dev": true, - "optional": true + "dev": true }, "ini": { "version": "1.3.5", @@ -2145,7 +2139,6 @@ "version": "1.0.0", "bundled": true, "dev": true, - "optional": true, "requires": { "number-is-nan": "^1.0.0" } @@ -2160,7 +2153,6 @@ "version": "3.0.4", "bundled": true, "dev": true, - "optional": true, "requires": { "brace-expansion": "^1.1.7" } @@ -2168,14 +2160,12 @@ "minimist": { "version": "0.0.8", "bundled": true, - "dev": true, - "optional": true + "dev": true }, "minipass": { "version": "2.3.5", "bundled": true, "dev": true, - "optional": true, "requires": { "safe-buffer": "^5.1.2", "yallist": "^3.0.0" @@ -2194,7 +2184,6 @@ "version": "0.5.1", "bundled": true, "dev": true, - "optional": true, "requires": { "minimist": "0.0.8" } @@ -2275,8 +2264,7 @@ "number-is-nan": { "version": "1.0.1", "bundled": true, - "dev": true, - "optional": true + "dev": true }, "object-assign": { "version": "4.1.1", @@ -2288,7 +2276,6 @@ "version": "1.4.0", "bundled": true, "dev": true, - "optional": true, "requires": { "wrappy": "1" } @@ -2410,7 +2397,6 @@ "version": "1.0.2", "bundled": true, "dev": true, - "optional": true, "requires": { "code-point-at": "^1.0.0", "is-fullwidth-code-point": "^1.0.0", @@ -2907,9 +2893,9 @@ } }, "lethargy": { - "version": "1.0.4", - "resolved": "https://registry.npmjs.org/lethargy/-/lethargy-1.0.4.tgz", - "integrity": "sha1-RZ38WqSaEO+QVjALkOwDqI47mK8=" + "version": "1.0.7", + "resolved": "https://registry.npmjs.org/lethargy/-/lethargy-1.0.7.tgz", + "integrity": "sha512-+IhiyZpw27A0KrtlfsrC1DcCgUYHqtWTqoa4CuJPyX7dmwF0b9bInWVkLrvn7yE88sEq86NxOSVtPhaVmE7C6A==" }, "lodash": { "version": "4.17.11", @@ -4182,9 +4168,9 @@ "dev": true }, "virtual-scroll": { - "version": "1.3.1", - "resolved": "https://registry.npmjs.org/virtual-scroll/-/virtual-scroll-1.3.1.tgz", - "integrity": "sha1-emwK+ZEEG9+hTqCnkZARV1vmBgE=", + "version": "1.5.1", + "resolved": "https://registry.npmjs.org/virtual-scroll/-/virtual-scroll-1.5.1.tgz", + "integrity": "sha512-QD6wnfbziuRjpRuEFFXCacR/uCzikc5mflGDggN9iVyzJm5//32YnvQ+Bh48RR6io5GW6HqQhAHMR4ILLTY1uQ==", "requires": { "bindall-standalone": "^1.0.5", "lethargy": "^1.0.2", diff --git a/package.json b/package.json index 1d3a922..7b2bb1a 100644 --- a/package.json +++ b/package.json @@ -8,7 +8,7 @@ "dom-create-element": "^1.0.2", "dom-events": "^0.1.1", "prefix": "^1.0.0", - "virtual-scroll": "^1.2.1" + "virtual-scroll": "^1.5.1" }, "devDependencies": { "@babel/core": "^7.4.4", diff --git a/smooth-scrolling.js b/smooth-scrolling.js index 6d569ba..d172ca8 100644 --- a/smooth-scrolling.js +++ b/smooth-scrolling.js @@ -61,6 +61,7 @@ function () { mouseMultiplier: this.options.vs && this.options.vs.mouseMultiplier || 1, touchMultiplier: this.options.vs && this.options.vs.touchMultiplier || 1.5, firefoxMultiplier: this.options.vs && this.options.vs.firefoxMultiplier || 30, + useKeyboard: this.options.vs && this.options.vs.hasOwnProperty('useKeyboard') ? this.options.vs.useKeyboard : true, preventTouch: this.options.vs && this.options.vs.hasOwnProperty('preventTouch') ? this.options.vs.preventTouch : true, passive: this.options.vs && this.options.vs.hasOwnProperty('passive') ? this.options.vs.passive : undefined }); @@ -1247,7 +1248,9 @@ function VirtualScroll(options) { keyStep: 120, preventTouch: false, unpreventTouchClass: 'vs-touchmove-allowed', - limitInertia: false + limitInertia: false, + useKeyboard: true, + useTouch: true }, options); if (this.options.limitInertia) this._lethargy = new Lethargy(); @@ -1374,7 +1377,7 @@ VirtualScroll.prototype._bind = function() { if(support.hasWheelEvent) this.el.addEventListener('wheel', this._onWheel, this.listenerOptions); if(support.hasMouseWheelEvent) this.el.addEventListener('mousewheel', this._onMouseWheel, this.listenerOptions); - if(support.hasTouch) { + if(support.hasTouch && this.options.useTouch) { this.el.addEventListener('touchstart', this._onTouchStart, this.listenerOptions); this.el.addEventListener('touchmove', this._onTouchMove, this.listenerOptions); } @@ -1386,7 +1389,7 @@ VirtualScroll.prototype._bind = function() { this.el.addEventListener('MSPointerMove', this._onTouchMove, true); } - if(support.hasKeyDown) document.addEventListener('keydown', this._onKeyDown); + if(support.hasKeyDown && this.options.useKeyboard) document.addEventListener('keydown', this._onKeyDown); }; VirtualScroll.prototype._unbind = function() { @@ -1404,7 +1407,7 @@ VirtualScroll.prototype._unbind = function() { this.el.removeEventListener('MSPointerMove', this._onTouchMove, true); } - if(support.hasKeyDown) document.removeEventListener('keydown', this._onKeyDown); + if(support.hasKeyDown && this.options.useKeyboard) document.removeEventListener('keydown', this._onKeyDown); }; VirtualScroll.prototype.on = function(cb, ctx) {