Skip to content

Commit

Permalink
Create Chose.trigger to replace simulate (prototype)
Browse files Browse the repository at this point in the history
  • Loading branch information
marcandre committed Sep 27, 2016
1 parent 29792b4 commit 5bea25d
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 3 deletions.
9 changes: 8 additions & 1 deletion coffee/chosen.proto.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -506,4 +506,11 @@ class @Chosen extends AbstractChosen
@search_field.setStyle({'width': w + 'px'})

trigger_form_field_change: ->
@form_field.simulate("change") if typeof Event.simulate is 'function'
Chosen.trigger(@form_field, 'change')

@trigger: (element, eventType) ->
if (document.createEventObject) # Old IE:
element.fireEvent("on#{eventType}", document.createEventObject());
else # Modern way:
evt = new Event(eventType, bubbles: true, cancelable: true)
element.dispatchEvent(evt)
4 changes: 2 additions & 2 deletions spec/proto/basic.spec.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,11 @@ describe "Basic setup", ->
expect($F(select)).toBe ""

container = div.down(".chosen-container")
container.simulate("mousedown") # open the drop
Chosen.trigger(container, "mousedown") # open the drop
expect(container.hasClassName("chosen-container-active")).toBe true

#select an item
container.select(".active-result").last().simulate("mouseup")
Chosen.trigger(container.select(".active-result").last(), "mouseup");

expect($F(select)).toBe "Afghanistan"
div.remove()

0 comments on commit 5bea25d

Please sign in to comment.