Skip to content

Instantly share code, notes, and snippets.

@F1LT3R
Created July 17, 2012 00:56
Show Gist options
  • Save F1LT3R/3126226 to your computer and use it in GitHub Desktop.
Save F1LT3R/3126226 to your computer and use it in GitHub Desktop.
Adding iOS TouchStart Events to Farbtastic Color Picker
/**
* TouchConvert: Converts touch co-ordinates to mouse co-ordinates
*/
fb.touchconvert = function (e) {
var e = e.originalEvent.touches.item(0);
return e;
}
/**
* Touchmove handler for iPad, iPhone etc
*/
fb.touchmove = function (e) {
fb.mousemove( fb.touchconvert(e) );
event.preventDefault();
return false;
}
/**
* Touchend handler for iPad, iPhone etc
*/
fb.touchend = function (event) {
$(document).unbind('touchmove', fb.touchmove);
$(document).unbind('touchend', fb.touchend);
document.dragging = false;
event.preventDefault();
return false;
}
// TouchStart bound, calls conversion of touchpoints to mousepoints
$('*', e).bind("touchstart", function (e) {
// Capture mouse
if (!document.dragging) {
$(document).bind('touchmove', fb.touchmove).bind('touchend', fb.touchend);
document.dragging = true;
}
fb.mousedown( fb.touchconvert(e) );
e.preventDefault();
return false;
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment