Key binding selectors match events on descendants

This commit is contained in:
Nathan Sobo
2012-01-09 17:18:53 -08:00
committed by Corey Johnson & Nathan Sobo
parent 18e614e88d
commit 9c98e971fc
2 changed files with 41 additions and 15 deletions

View File

@@ -15,7 +15,7 @@ class BindingSet
constructor: (@selector, @bindings) ->
commandForEvent: (event) ->
if $(event.target).is(@selector)
if @selectorMatchesEvent(event)
for pattern, command of @bindings
return command if @eventMatchesPattern(event, pattern)
null
@@ -44,3 +44,10 @@ class BindingSet
which: charCode
key: key
selectorMatchesEvent: (event) ->
currentNode = event.target
while currentNode
return true if $(currentNode).is(@selector)
currentNode = currentNode.parentNode
false