gesture-helper
Advanced tools
Comparing version 0.1.6 to 0.1.7
@@ -441,3 +441,3 @@ (function webpackUniversalModuleDefinition(root, factory) { | ||
if (this.directionCount < this.options.startDirectionLoopCount) { | ||
if (this.directionCount <= this.options.startDirectionLoopCount) { | ||
this.directionCount++; | ||
@@ -467,2 +467,3 @@ return null; | ||
this.clearVelocityStats(); | ||
this.emit('pan.prestart', { sourceEvent: e }); | ||
}; | ||
@@ -501,5 +502,3 @@ | ||
deltaX < 0 ? this.emit('pan.x.left', { delta: deltaX, sourceEvent: e }) : this.emit('pan.x.right', { delta: deltaX, sourceEvent: e }); | ||
} | ||
if (this.startDirection === 'vertical') { | ||
} else if (this.startDirection === 'vertical') { | ||
deltaY < 0 ? this.emit('pan.y.up', { delta: deltaY, sourceEvent: e }) : this.emit('pan.y.down', { delta: deltaY, sourceEvent: e }); | ||
@@ -506,0 +505,0 @@ } |
{ | ||
"name": "gesture-helper", | ||
"version": "0.1.6", | ||
"version": "0.1.7", | ||
"description": "a *tiny* touch & mouse library to help make tracking touch interactions more simple.", | ||
@@ -22,3 +22,3 @@ "main": "dist/index.js", | ||
"build": "webpack --config ./webpack.config.js", | ||
"prepublish": "webpack --config ./webpack.config.js" | ||
"prepublish": "yarn build" | ||
}, | ||
@@ -25,0 +25,0 @@ "dependencies": { |
@@ -5,23 +5,26 @@ # gesture-helper | ||
Gesture helper extends https://github.com/asyncly/EventEmitter2, and returns an event emitter. | ||
Events can be name spaced, per EventEmitter2. This means that you can bind to the following events: | ||
Events can be namespaced, per EventEmitter2. This means that you can bind to events like: | ||
```javascript | ||
tap | ||
pan.** | ||
pan.start | ||
pan.end | ||
pan.y.up | ||
pan.y.down | ||
pan.y.** | ||
pan.x.left | ||
pan.x.right | ||
pan.x.** | ||
tap // (for simple tap / click events) | ||
pan.** // (wildcard for all pan-related events) | ||
pan.prestart // (immediate touchStart event - mainly useful for immediately blocking browser behaviour) | ||
pan.start // (the beginning of a discernable drag event) | ||
pan.end // (the end of a detected drag event) | ||
pan.y.up // (a progress event as the finger moves up) | ||
pan.y.down // (a progress event as the finger moves down) | ||
pan.y.** // (wildcard for both up and down movement progress events) | ||
pan.x.left // (a progress event as the finger moves left) | ||
pan.x.right // (a progress event as the finger moves right) | ||
pan.x.** // (wildcard for both left and right movement progress events) | ||
``` | ||
In the interest of keeping the library small, versatile and uncomplicated - all source touch/mouse events are returned inside EE2 event payloads, as follows: | ||
In the interest of keeping the library small, unopinionated, and versatile - any preventDefault / stopPropogation / event bubbling related functionality is left untouched. This can be added to each application, depending on what you need. | ||
All source touch/mouse events are returned inside all EE2 event payloads, as follows | ||
```javascript | ||
{ ..., sourceEvent: e } | ||
``` | ||
This allows you to add ```preventDefault()``` and other native event functionality, as you need it. | ||
Eg. you can call ```ev.sourceEvent.preventDefault()``` as well as other native browser event functionality, as you need it. | ||
Per EE2, the event handler name (eg. ```pan.x.up```, ```pan.all```) is also returned to the listener function's scope as the property ```this.event```. | ||
Per EE2, the event handler name (eg. ```pan.x.up```, ```pan.all```) is also bound to the listener function's scope as the property ```this.event```. | ||
*Note: If you plan to access this property, please avoid defining handlers using arrow functions. | ||
@@ -28,0 +31,0 @@ |
@@ -118,3 +118,3 @@ 'use strict'; | ||
getStartDirection({x=0,y=0}) { | ||
if (this.directionCount < this.options.startDirectionLoopCount) { | ||
if (this.directionCount <= this.options.startDirectionLoopCount) { | ||
this.directionCount++; | ||
@@ -137,2 +137,3 @@ return null; | ||
this.clearVelocityStats(); | ||
this.emit('pan.prestart', { sourceEvent: e }); | ||
} | ||
@@ -146,4 +147,5 @@ | ||
this.startDirection = this.getStartDirection({ x:deltaX, y:deltaY }); | ||
} else if (!this.panning && (Math.abs(deltaX) > this.options.sensitivity | ||
|| Math.abs(deltaY) > this.options.sensitivity)) { | ||
} else if (!this.panning | ||
&& (Math.abs(deltaX) > this.options.sensitivity | ||
|| Math.abs(deltaY) > this.options.sensitivity)) { | ||
@@ -168,5 +170,3 @@ this.panning = true; | ||
: this.emit('pan.x.right', { delta: deltaX, sourceEvent: e }); | ||
} | ||
if (this.startDirection === 'vertical') { | ||
} else if (this.startDirection === 'vertical') { | ||
deltaY < 0 | ||
@@ -173,0 +173,0 @@ ? this.emit('pan.y.up', { delta: deltaY, sourceEvent: e }) |
72546
1723
65