Prelim caveat: I am very new to js and have mainly gotten by through doing web searches for examples/tutorials.
I am writing js which should run both on web and on mobile devices (e.g. iPad).
We have a library to help abstract away the differences between mouse
and touch
:
if (navigator.userAgent.search('Mobile') > 0) {
window.FLAGS = {
start: 'touchstart',
end: 'touchend',
move: 'touchmove',
click: 'click',
touchScreen: true
};
} else {
window.FLAGS = {
start: 'mousedown',
end: 'mouseup',
move: 'mousemove',
click: 'click',
touchScreen: false
};
}
Then in code you can do things like:
widget.view.bind(FLAGS.start, function(e) {
I am trying to find a touch
equivalent for mouseleave
so I can do a similar trick.
I can imagine ways to catch a leave
event by tracking the position on move
and comparing that to bounding box of widget in question, but I'm hoping there's a little one-liner like the touchstart
/mousedown
relationship.