Skip to content

Commit

Permalink
silence "layerX/Y" Webkit warnings for events
Browse files Browse the repository at this point in the history
This means we can't just blindly extend all event properties onto the
event proxy object.
  • Loading branch information
mislav committed Sep 28, 2012
1 parent c49831f commit 18ba1f0
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 1 deletion.
6 changes: 5 additions & 1 deletion src/event.js
Original file line number Diff line number Diff line change
Expand Up @@ -103,13 +103,17 @@

var returnTrue = function(){return true},
returnFalse = function(){return false},
ignoreProperties = /^([A-Z]|layer[XY]$)/,
eventMethods = {
preventDefault: 'isDefaultPrevented',
stopImmediatePropagation: 'isImmediatePropagationStopped',
stopPropagation: 'isPropagationStopped'
}
function createProxy(event) {
var proxy = $.extend({originalEvent: event}, event)
var key, proxy = { originalEvent: event }
for (key in event)
if (!ignoreProperties.test(key) && event[key] !== undefined) proxy[key] = event[key]

$.each(eventMethods, function(name, predicate) {
proxy[name] = function(){
this[predicate] = returnTrue
Expand Down
11 changes: 11 additions & 0 deletions test/event.html
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,17 @@ <h1>Zepto event tests</h1>
this.el.off({ click: fn }).off({ click: fn2 }, null)
click(this.el)
t.assertEqual('a b c c', log.sort().join(' '))
},

testDelegateEventProperties: function(t){
var type, target
$(document).on('click', 'div', function(e){
type = e.type
target = e.target
})
click(this.el)
t.assertEqual('click', type)
t.assertIdentical(this.el.get(0), target)
}
})
})()
Expand Down

0 comments on commit 18ba1f0

Please sign in to comment.