aboutsummaryrefslogtreecommitdiffstats
path: root/src/js/listeners.js
diff options
context:
space:
mode:
authorSam Potts <sam@potts.es>2018-06-21 09:11:05 +1000
committerSam Potts <sam@potts.es>2018-06-21 09:11:05 +1000
commit17dcb63c26e22ea8848056555a7c0ff19f779bf8 (patch)
tree8dd41ad9fd6d8bcfe6c2e2db583424f9df8e2524 /src/js/listeners.js
parentf62e1da01a1a3cf78def1002a5cbe47db5cc9361 (diff)
parente04b90c9c030bf5629e034f616a636245770a8d1 (diff)
downloadplyr-17dcb63c26e22ea8848056555a7c0ff19f779bf8.tar.lz
plyr-17dcb63c26e22ea8848056555a7c0ff19f779bf8.tar.xz
plyr-17dcb63c26e22ea8848056555a7c0ff19f779bf8.zip
Merge branch 'develop'
# Conflicts: # dist/plyr.js.map # dist/plyr.min.js # dist/plyr.min.js.map # dist/plyr.polyfilled.js.map # dist/plyr.polyfilled.min.js # dist/plyr.polyfilled.min.js.map
Diffstat (limited to 'src/js/listeners.js')
-rw-r--r--src/js/listeners.js38
1 files changed, 11 insertions, 27 deletions
diff --git a/src/js/listeners.js b/src/js/listeners.js
index 9d987508..d9811dd1 100644
--- a/src/js/listeners.js
+++ b/src/js/listeners.js
@@ -665,36 +665,20 @@ class Listeners {
// Detect "natural" scroll - suppored on OS X Safari only
// Other browsers on OS X will be inverted until support improves
const inverted = event.webkitDirectionInvertedFromDevice;
- const step = 1 / 50;
- let direction = 0;
-
- // Scroll down (or up on natural) to decrease
- if (event.deltaY < 0 || event.deltaX > 0) {
- if (inverted) {
- this.player.decreaseVolume(step);
- direction = -1;
- } else {
- this.player.increaseVolume(step);
- direction = 1;
- }
- }
- // Scroll up (or down on natural) to increase
- if (event.deltaY > 0 || event.deltaX < 0) {
- if (inverted) {
- this.player.increaseVolume(step);
- direction = 1;
- } else {
- this.player.decreaseVolume(step);
- direction = -1;
- }
- }
+ // Get delta from event. Invert if `inverted` is true
+ const [x, y] = [event.deltaX, -event.deltaY]
+ .map(value => inverted ? -value : value);
+
+ // Using the biggest delta, normalize to 1 or -1 (or 0 if no delta)
+ const direction = Math.sign(Math.abs(x) > Math.abs(y) ? x : y);
+
+ // Change the volume by 2%
+ this.player.increaseVolume(direction / 50);
// Don't break page scrolling at max and min
- if (
- (direction === 1 && this.player.media.volume < 1) ||
- (direction === -1 && this.player.media.volume > 0)
- ) {
+ const { volume } = this.player.media;
+ if ((direction === 1 && volume < 1) || (direction === -1 && volume > 0)) {
event.preventDefault();
}
},