Created
July 25, 2011 15:16
-
-
Save eklimcz-zz/1104360 to your computer and use it in GitHub Desktop.
JS Touch Event Handlers
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//Check for touch | |
var _eventType = ('ontouchstart' in window) ? "touch" : "mouse"; | |
this.addEventHandlers = function(eventType) { | |
if (eventType === 'mouse') { | |
this._dragStartEvt = "mousedown"; | |
this._dragStartCB = function(e) { | |
return self.OnMouseDown(e, e.clientX, e.clientY); | |
}; | |
this._dragMoveEvt = "mousemove"; | |
this._dragMoveCB = function(e) { | |
return self.OnMouseMove(e, e.clientX, e.clientY); | |
}; | |
this._dragStopEvt = "mouseup"; | |
this._dragStopCB = function(e) { | |
return self.OnMouseUp(e); | |
}; | |
this._dragOutEvt = 'mouseout'; | |
this._dragOutCB = function(e) { | |
return self.OnMouseUp(e); | |
} | |
$(window).bind(this._dragOutEvt, this._dragOutCB, true); | |
$('document').bind('mousedown', this.PreventSelection) | |
} else { | |
this._dragStartEvt = "touchstart"; | |
this._dragStartCB = function(e) { | |
var t = e.touches[0]; | |
return self.OnMouseDown(e, t.pageX, t.pageY); | |
}; | |
this._dragMoveEvt = "touchmove"; | |
this._dragMoveCB = function(e) { | |
var t = e.touches[0]; | |
return self.OnMouseMove(e, t.pageX, t.pageY); | |
}; | |
this._dragStopEvt = "touchend"; | |
this._dragStopCB = function(e) { | |
return self.OnMouseUp(e); | |
}; | |
} | |
} | |
this.PreventSelection = function(mouseEvent) { | |
mouseEvent.preventDefault(); | |
} | |
this.OnMouseLost = function(mouseEvent) { | |
this.OnMouseUp(mouseEvent); | |
} | |
this.OnMouseDown = function(e, ex, ey) { | |
//Do Stuff Here | |
} | |
this.OnMouseMove = function(e, ex, ey) { | |
//Do Stuff Here | |
} | |
this.OnMouseUp = function(e) { | |
//Do Stuff Here | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment