mirror of
https://github.com/atom/atom.git
synced 2026-01-24 14:28:14 -05:00
Pass the event and element to event-handling methods on the view.
This commit is contained in:
@@ -48,6 +48,14 @@ fdescribe "Template", ->
|
||||
it "binds events for elements with event name attributes", ->
|
||||
spyOn(view, 'li1Clicked')
|
||||
spyOn(view, 'li2Keypressed')
|
||||
spyOn(view, 'li1Clicked').andCallFake (event, elt) ->
|
||||
expect(event.type).toBe 'click'
|
||||
expect(elt).toMatchSelector 'li.foo:contains(one)'
|
||||
|
||||
spyOn(view, 'li2Keypressed').andCallFake (event, elt) ->
|
||||
expect(event.type).toBe 'keypress'
|
||||
expect(elt).toMatchSelector "li.bar:contains(two)"
|
||||
|
||||
view.li1.click()
|
||||
expect(view.li1Clicked).toHaveBeenCalled()
|
||||
expect(view.li2Keypressed).not.toHaveBeenCalled()
|
||||
|
||||
@@ -35,11 +35,9 @@ class Template
|
||||
view[outletName] = elt
|
||||
|
||||
bindEvents: (view) ->
|
||||
for event in this.constructor.events
|
||||
view.find("[#{event}]").each ->
|
||||
for eventName in this.constructor.events
|
||||
view.find("[#{eventName}]").each ->
|
||||
elt = $(this)
|
||||
methodName = elt.attr(event)
|
||||
elt[event](-> view[methodName]())
|
||||
|
||||
|
||||
methodName = elt.attr(eventName)
|
||||
elt[eventName]((event) -> view[methodName](event, elt))
|
||||
|
||||
|
||||
Reference in New Issue
Block a user