@wildebeest/touch
Advanced tools
Comparing version 0.2.0 to 0.2.1
@@ -5,7 +5,7 @@ import { Emitter } from "@wildebeest/common"; | ||
protected emitter: Emitter; | ||
protected touch: any; | ||
protected touch: TouchEvent; | ||
constructor(element: any, emitter: Emitter); | ||
getEmitter(): Emitter; | ||
protected setTouch(event: any): void; | ||
protected onMove(event: any): void; | ||
protected getFingerPosition(event: TouchEvent): any; | ||
protected onMove(event: TouchEvent): void; | ||
} |
@@ -6,6 +6,7 @@ "use strict"; | ||
var _this = this; | ||
this.touch = null; | ||
this.element = element; | ||
this.emitter = emitter; | ||
this.element.addEventListener('touchstart', this.setTouch.bind(this)); | ||
this.element.addEventListener('touchstart', function (event) { | ||
_this.touch = event; | ||
}); | ||
this.element.addEventListener('touchend', function () { | ||
@@ -19,8 +20,6 @@ _this.touch = null; | ||
}; | ||
TouchElement.prototype.setTouch = function (event) { | ||
this.touch = { | ||
position: { | ||
x: event.changedTouches[0].pageX, | ||
y: event.changedTouches[0].pageY | ||
} | ||
TouchElement.prototype.getFingerPosition = function (event) { | ||
return { | ||
x: event.changedTouches[0].clientX, | ||
y: event.changedTouches[0].clientY | ||
}; | ||
@@ -32,9 +31,10 @@ }; | ||
} | ||
var prevTouch = this.touch; | ||
this.setTouch(event); | ||
var lastPosition = this.getFingerPosition(this.touch); | ||
var currentPosition = this.getFingerPosition(event); | ||
var diff = { | ||
horizontal: prevTouch.position.x - this.touch.position.x, | ||
vertical: prevTouch.position.y - this.touch.position.y, | ||
horizontal: lastPosition.x - currentPosition.x, | ||
vertical: lastPosition.y - currentPosition.y, | ||
}; | ||
this.emitter.emit('touchScroll', diff); | ||
this.touch = event; | ||
this.emitter.emit('wbTouchscroll', diff); | ||
}; | ||
@@ -41,0 +41,0 @@ return TouchElement; |
{ | ||
"name": "@wildebeest/touch", | ||
"version": "0.2.0", | ||
"version": "0.2.1", | ||
"description": "Touch event module", | ||
@@ -9,3 +9,4 @@ "main": "dist/index.js", | ||
"build": "tsc --declaration", | ||
"test": "jest" | ||
"test": "jest", | ||
"deploy": "npm run test && npm run build && git add -A && git commit -m 'deploy' && git push origin master" | ||
}, | ||
@@ -12,0 +13,0 @@ "repository": { |
Sorry, the diff of this file is not supported yet
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
10726