Backbone.js click event doesn't work with touch

后端 未结 8 1849
-上瘾入骨i
-上瘾入骨i 2020-12-16 02:46
events: 
    \'click\' : \'select\'

When using this event on Mobile Safari the event gets triggered twice when touched. Is this a known bug or some

8条回答
  •  北荒
    北荒 (楼主)
    2020-12-16 03:24

    Using coffeescript, I'd do the following, I don't ever find a reason to bring in modernizer when every mobile device these days is really a touch device, I mean when was the last time you had to really support something that didn't?

    window.isTouchDevice =  (/android|webos|iphone|ipod|ipad|blackberry|iemobile/i.test(navigator.userAgent.toLowerCase()) )
    
      events: ->
        for k, v of this when /click/.test(k) and isTouchDevice
          mobileKey = k.replace('click','touchstart')
          events[ mobileKey ] = v
          delete events[ k ]
        return events
    

    Coffeescript reads better for these type of list comprehensions imho.

提交回复
热议问题