Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Backbone.js click event doesn't work with touch

events: 
    'click' : 'select'

When using this event on Mobile Safari the event gets triggered twice when touched. Is this a known bug or something that I am causing on my own?

I've since changed it to

events: 
    'touchstart' : 'select'

and it works great but means that it will not work in normal browsers anymore.

Thanks for any info.

like image 903
fancy Avatar asked Oct 19 '11 21:10

fancy


1 Answers

Try this code:

TouchView = Backbone.View.extend({
  events: function() {
    return MOBILE ? 
       {
         "touchstart": 'select'
       } : 
       {
         "mousedown": 'select'
       }
  }
}

See it in action: http://jsfiddle.net/dira/Ke2px/2/

like image 87
dira Avatar answered Sep 22 '22 22:09

dira