mirror of
https://github.com/atom/atom.git
synced 2026-04-28 03:01:47 -04:00
Add $.fn.bindKey, which works on any jquery-wrapped element.
If given a string as an action, it attempts to call a method by that name on the element's view object. If given a function, it calls it directly.
This commit is contained in:
@@ -89,3 +89,26 @@ describe "Template", ->
|
||||
expect(view.subview.view()).toBe view.subview
|
||||
expect(view.subview.header.view()).toBe view.subview
|
||||
|
||||
describe "$.fn.bindKey", ->
|
||||
describe "when passed a key pattern and a method name", ->
|
||||
it "calls the named method on the parent view when a keydown event matches the pattern", ->
|
||||
view.someMethod = jasmine.createSpy('someMethod')
|
||||
view.li1.bindKey 'ctrl+m', 'someMethod'
|
||||
|
||||
view.li1.trigger window.createKeyEvent('meta+z')
|
||||
expect(view.someMethod).not.toHaveBeenCalled()
|
||||
|
||||
view.li1.trigger window.createKeyEvent('ctrl+m')
|
||||
expect(view.someMethod).toHaveBeenCalled()
|
||||
|
||||
describe "when passed a key pattern and a function", ->
|
||||
it "calls the given function when a keydown event matches the pattern", ->
|
||||
action = jasmine.createSpy('someMethod')
|
||||
view.li1.bindKey 'ctrl+m', action
|
||||
|
||||
view.li1.trigger window.createKeyEvent('meta+z')
|
||||
expect(action).not.toHaveBeenCalled()
|
||||
|
||||
view.li1.trigger window.createKeyEvent('ctrl+m')
|
||||
expect(action).toHaveBeenCalled()
|
||||
|
||||
|
||||
Reference in New Issue
Block a user