From 389552c057f2db631399470a1be84420afc3ad21 Mon Sep 17 00:00:00 2001 From: Nathan Sobo Date: Tue, 2 Oct 2012 16:59:08 -1000 Subject: [PATCH] Can trigger an event by clicking it in the list --- spec/extensions/event-palette-spec.coffee | 36 ++++++++++++++----- .../event-palette/event-palette.coffee | 4 ++- 2 files changed, 31 insertions(+), 9 deletions(-) diff --git a/spec/extensions/event-palette-spec.coffee b/spec/extensions/event-palette-spec.coffee index c5f110b6e..bc5e0ab9e 100644 --- a/spec/extensions/event-palette-spec.coffee +++ b/spec/extensions/event-palette-spec.coffee @@ -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() + diff --git a/src/extensions/event-palette/event-palette.coffee b/src/extensions/event-palette/event-palette.coffee index 4c466065d..ca708f06d 100644 --- a/src/extensions/event-palette/event-palette.coffee +++ b/src/extensions/event-palette/event-palette.coffee @@ -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