Can trigger an event by clicking it in the list

This commit is contained in:
Nathan Sobo
2012-10-02 16:59:08 -10:00
parent 0ecdabb023
commit 389552c057
2 changed files with 31 additions and 9 deletions

View File

@@ -53,14 +53,34 @@ describe "EventPalette", ->
expect(palette.eventList.scrollTop() + palette.eventList.height()).toBe palette.eventList.prop('scrollHeight')
describe "when event-palette:select is triggered on the palette", ->
it "emits the selected event on the last focused element, then detaches the palette", ->
_.times 3, -> palette.miniEditor.trigger 'move-down'
describe "event triggering", ->
eventHandler = null
beforeEach ->
eventHandler = jasmine.createSpy 'eventHandler'
rootView.getActiveEditor().preempt palette.getSelectedEventName(), eventHandler
palette.trigger 'event-palette:select'
expect(eventHandler).toHaveBeenCalled()
expect(rootView.getActiveEditor().isFocused).toBeTruthy()
expect(palette.hasParent()).toBeFalsy()
describe "when event-palette:select is triggered on the palette", ->
it "emits the selected event on the last focused element, then detaches the palette", ->
_.times 3, -> palette.miniEditor.trigger 'move-down'
rootView.getActiveEditor().preempt palette.getSelectedEventName(), eventHandler
palette.trigger 'event-palette:select'
expect(eventHandler).toHaveBeenCalled()
expect(rootView.getActiveEditor().isFocused).toBeTruthy()
expect(palette.hasParent()).toBeFalsy()
describe "when an item is clicked", ->
it "selects item and triggers its event", ->
element = palette.eventList.find('.event:eq(3)')
element.mousedown()
expect(element).toHaveClass 'selected'
rootView.getActiveEditor().preempt palette.getSelectedEventName(), eventHandler
element.mouseup()
expect(eventHandler).toHaveBeenCalled()
rootView.getActiveEditor().preempt palette.getSelectedEventName(), eventHandler
element.click()

View File

@@ -19,6 +19,8 @@ class EventPalette extends View
@on 'move-down', => @selectNext()
@on 'event-palette:cancel', => @detach()
@on 'event-palette:select', => @triggerSelectedEvent()
@on 'mousedown', '.event', (e) => @selectItem($(e.target).closest('.event'))
@on 'mouseup', '.event', => @triggerSelectedEvent()
attach: ->
@previouslyFocusedElement = $(':focus')
@@ -72,5 +74,5 @@ class EventPalette extends View
@detach()
detach: ->
@rootView.focus() if @is(':focus')
@rootView.focus() if @miniEditor.isFocused
super