Skip to content

Instantly share code, notes, and snippets.

@apavlyut
Forked from argent-smith/attach-select2.js.coffee
Last active August 29, 2015 14:05
Show Gist options
  • Save apavlyut/69a2b50a778e2759b266 to your computer and use it in GitHub Desktop.
Save apavlyut/69a2b50a778e2759b266 to your computer and use it in GitHub Desktop.
# connecting select2 to the appropriate hooks:
#
# hard case: best_in_place's select
$ ->
# first, find the mount point
$('body').on 'best_in_place:activate', '.best_in_place', ->
# second, attach empty update() to `this` to screen the downstream calls
# which otherwise will cause an error
@update = ->
# now unbind `blur` from the <select> and bind it to the downstream
# best_in_place's handler; this prevents the immediate select2's
# destruction since clicking on it would cause `blur` on the downstream
# best_in_place
$(@).find('select').select2()
.unbind('blur').bind('blur', {editor: @}, BestInPlaceEditor.forms.select.blurHandler)
# simple case: attach to a usual select
$ ->
$('.select2').select2()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment