Skip to content

Commit

Permalink
fix namespaced focus & blur event delegation
Browse files Browse the repository at this point in the history
Handlers for namespaced focus & blur events weren't attached correctly
in the delegation scenario.

Closes madrobby#552
  • Loading branch information
elgerlambert authored and mislav committed Sep 27, 2012
1 parent ec030b3 commit bbb5ca1
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 7 deletions.
8 changes: 1 addition & 7 deletions src/event.js
Original file line number Diff line number Diff line change
Expand Up @@ -128,13 +128,7 @@
}

$.fn.delegate = function(selector, event, callback){
var capture = false
if(event == 'blur' || event == 'focus'){
if($.iswebkit)
event = event == 'blur' ? 'focusout' : event == 'focus' ? 'focusin' : event
else
capture = true
}
var capture = /^(?:blur|focus)(?:\..*)?$/.test(event)

return this.each(function(i, element){
add(element, event, callback, selector, function(fn){
Expand Down
23 changes: 23 additions & 0 deletions test/zepto.html
Original file line number Diff line number Diff line change
Expand Up @@ -2232,6 +2232,29 @@ <h1>Zepto DOM unit tests</h1>
t.assertEqual(4, counter)
},

testDelegateNamespacedBlurFocus: function(t) {
var counter = 0
$('#delegate_blur_test').delegate('input', 'blur.namespace_test', function(){ counter++ })

$('#delegate_blur_test').find('input').focus()
$('#delegate_blur_test').find('input').blur()
t.assertEqual(1, counter)

$('#delegate_blur_test').find('input').focus()
$('#delegate_blur_test').find('input').blur()
t.assertEqual(2, counter)

$('#delegate_focus_test').delegate('input', 'focus.namespace_test', function(){ counter++ })

$('#delegate_focus_test').find('input').focus()
$('#delegate_focus_test').find('input').blur()
t.assertEqual(3, counter)

$('#delegate_focus_test').find('input').focus()
$('#delegate_focus_test').find('input').blur()
t.assertEqual(4, counter)
},

testDelegateReturnFalse: function(t){
$(document.body).delegate('#some_element', 'click', function(){ return false })

Expand Down

0 comments on commit bbb5ca1

Please sign in to comment.