Skip to content

Instantly share code, notes, and snippets.

@ada-lovecraft
Last active August 29, 2015 14:20
Show Gist options
  • Save ada-lovecraft/780a8afeff60751d656c to your computer and use it in GitHub Desktop.
Save ada-lovecraft/780a8afeff60751d656c to your computer and use it in GitHub Desktop.
event mapping for touch and mouse
var EventTypes = {
START: {
handler: onDocumentMouseDown,
events: ['mousedown', 'touchstart']
},
MOVE: {
handler: onDocumentMouseMove,
events: ['mousemove', 'touchmove']
},
END: {
handler: onDocumentMouseUp,
events: ['mouseup','touchend','touchcancel','touchleave']
}
};
function addListeners(context, eventType) {
eventType.events.each(function(evt) {
context.addEventListener(evt, eventType.handler, false);
});
};
function removeListeners(context, eventType) {
eventType.events.each(function(evt) {
context.removeEventListener(evt, eventType.handler, false);
});
};
---
addListeners(document, EventTypes.START);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment