Skip to content

Instantly share code, notes, and snippets.

@Neferetheka
Created August 10, 2012 08:27
Show Gist options
  • Save Neferetheka/3312598 to your computer and use it in GitHub Desktop.
Save Neferetheka/3312598 to your computer and use it in GitHub Desktop.
Swype gestures for Windows 8
/*
*Add an event handler to an element to detect pointer down
*Ensure that is a touch event
*MSPointerDown and MSPointerUp are Windows 8/IE10 events. You should look at another code to handle gestures on other browsers
*/
this._element.addEventListener("MSPointerDown", function (e) {
//Touch event
if (e.pointerType == 2) {
context._gestureInfos = new Object();
context._gestureInfos.started = true;
context._gestureInfos.position = new Object();
context._gestureInfos.position.x = e.x;
context._gestureInfos.position.y = e.y;
context._gestureInfos.startTime = Math.round(new Date().getTime() / 1000); //Unix Timestamp
}
});
/*
*Add event handler to detect finger up on the element, and maybe raise the gesture event
*/
this._element.addEventListener("MSPointerUp", function (e) {
if (e.pointerType == 2 && context._gestureInfos
&& context._gestureInfos.started) {
var ts = Math.round(new Date().getTime() / 1000);
if (Math.abs(e.y - context._gestureInfos.position.y) < 50
&& ts - context._gestureInfos.startTime <= 1 &&
Math.abs(e.x - context._gestureInfos.position.x) > window.screen.availWidth * 0.4) {
//Gesture done !
if (e.x > context._gestureInfos.position.x)
swypeRight();
else
swypeLeft();
}
context._gestureInfos.started = false;
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment