Skip to content

Commit

Permalink
use fat arrow function for test_active_click
Browse files Browse the repository at this point in the history
removed the need for the manual bind, which is what coffeescript does
in the background
  • Loading branch information
koenpunt committed Nov 27, 2016
1 parent e9d9f5b commit 3658d35
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 9 deletions.
8 changes: 4 additions & 4 deletions coffee/chosen.jquery.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ class Chosen extends AbstractChosen
@container.bind 'click.chosen', (evt) -> evt.preventDefault(); return # gobble click of anchor

destroy: ->
$(@container[0].ownerDocument).unbind 'click.chosen', @click_test_action
$(@container[0].ownerDocument).unbind 'click.chosen', this.test_active_click
@form_field_label.unbind 'click.chosen' if @form_field_label.length > 0

if @search_field[0].tabIndex
Expand Down Expand Up @@ -139,7 +139,7 @@ class Chosen extends AbstractChosen
if not (evt? and ($ evt.target).hasClass "search-choice-close")
if not @active_field
@search_field.val "" if @is_multiple
$(@container[0].ownerDocument).bind 'click.chosen', @click_test_action
$(@container[0].ownerDocument).bind 'click.chosen', this.test_active_click
this.results_show()
else if not @is_multiple and evt and (($(evt.target)[0] == @selected_item[0]) || $(evt.target).parents("a.chosen-single").length)
evt.preventDefault()
Expand All @@ -161,7 +161,7 @@ class Chosen extends AbstractChosen
this.close_field() if not @active_field and @container.hasClass "chosen-container-active"

close_field: ->
$(@container[0].ownerDocument).unbind "click.chosen", @click_test_action
$(@container[0].ownerDocument).unbind 'click.chosen', this.test_active_click

@active_field = false
this.results_hide()
Expand All @@ -183,7 +183,7 @@ class Chosen extends AbstractChosen
@search_field.focus()


test_active_click: (evt) ->
test_active_click: (evt) =>
active_container = $(evt.target).closest('.chosen-container')
if active_container.length and @container[0] == active_container[0]
@active_field = true
Expand Down
8 changes: 4 additions & 4 deletions coffee/chosen.proto.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ class @Chosen extends AbstractChosen
@container.observe "click", (evt) => evt.preventDefault() # gobble click of anchor

destroy: ->
@container.ownerDocument.stopObserving "click", @click_test_action
@container.ownerDocument.stopObserving 'click', this.test_active_click

for event in ['chosen:updated', 'chosen:activate', 'chosen:open', 'chosen:close']
@form_field.stopObserving(event)
Expand Down Expand Up @@ -141,7 +141,7 @@ class @Chosen extends AbstractChosen
if not (evt? and evt.target.hasClassName "search-choice-close")
if not @active_field
@search_field.clear() if @is_multiple
@container.ownerDocument.observe "click", @click_test_action
@container.ownerDocument.observe 'click', this.test_active_click
this.results_show()
else if not @is_multiple and evt and (evt.target is @selected_item || evt.target.up("a.chosen-single"))
this.results_toggle()
Expand All @@ -162,7 +162,7 @@ class @Chosen extends AbstractChosen
this.close_field() if not @active_field and @container.hasClassName("chosen-container-active")

close_field: ->
@container.ownerDocument.stopObserving "click", @click_test_action
@container.ownerDocument.stopObserving 'click', this.test_active_click

@active_field = false
this.results_hide()
Expand All @@ -183,7 +183,7 @@ class @Chosen extends AbstractChosen
@search_field.value = this.get_search_field_value()
@search_field.focus()

test_active_click: (evt) ->
test_active_click: (evt) =>
if evt.target.up('.chosen-container') is @container
@active_field = true
else
Expand Down
1 change: 0 additions & 1 deletion coffee/lib/abstract-chosen.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ class AbstractChosen
this.on_ready()

set_default_values: ->
@click_test_action = (evt) => this.test_active_click(evt)
@active_field = false
@mouse_on_container = false
@results_showing = false
Expand Down

0 comments on commit 3658d35

Please sign in to comment.