Skip to content

Commit

Permalink
Populate event.timeStamp if it's 0 or missing
Browse files Browse the repository at this point in the history
Works around an iOS bug (which I couldn't reproduce).

Fixes madrobby#1160
  • Loading branch information
mislav committed Jul 13, 2016
1 parent 623b37d commit bf2f1c8
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 0 deletions.
2 changes: 2 additions & 0 deletions src/event.js
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,8 @@
event[predicate] = returnFalse
})

event.timeStamp || (event.timeStamp = Date.now())

if (source.defaultPrevented !== undefined ? source.defaultPrevented :
'returnValue' in source ? source.returnValue === false :
source.getPreventDefault && source.getPreventDefault())
Expand Down
9 changes: 9 additions & 0 deletions test/event.html
Original file line number Diff line number Diff line change
Expand Up @@ -207,6 +207,15 @@ <h1>Zepto Event unit tests</h1>
t.assertIdentical(this.el.get(0), currentTarget)
},

testDelegateEventTimestamp: function(t){
var timestamp
$(document).on('click', 'div', function(e){
timestamp = e.timeStamp
})
click($('<span>').appendTo(this.el))
t.assert(timestamp > 0, 'timestamp was ' + timestamp)
},

testPreventDefaultWithDelegatedEvent: function(t){
var isDefaultPrevented, span = $('<span>').appendTo(this.el)

Expand Down

0 comments on commit bf2f1c8

Please sign in to comment.