Created
July 17, 2012 00:56
-
-
Save F1LT3R/3126226 to your computer and use it in GitHub Desktop.
Adding iOS TouchStart Events to Farbtastic Color Picker
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
/** | |
* 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