Skip to content

Instantly share code, notes, and snippets.

@djpate
Created October 31, 2014 19:31
Show Gist options
  • Save djpate/ecb8a6d90a418b0eb2ea to your computer and use it in GitHub Desktop.
Save djpate/ecb8a6d90a418b0eb2ea to your computer and use it in GitHub Desktop.
define [
'ConsoleFactory'
'oraculum/mixins/evented-method'
'oraculum/mixins/listener'
'select2'
], (ConsoleFactory) ->
ConsoleFactory.defineMixin 'Select2.ViewMixin', {
mixinOptions:
select2: {}
eventedMethods:
attach: {}
listen:
'attach:after this': 'select2'
'dispose:before this': 'destroySelect2'
mixconfig: ({select2}, {select2Options}) ->
if _.isFunction select2
@select2Options = select2Options
else
_.extend select2, select2Options
select2: ->
options = @mixinOptions.select2
options = options.call this if _.isFunction options
_extend options, @select2Options if @select2Options
@$el.select2 options
destroySelect2: ->
@$el.data('select2')?.destroy()
}, {
mixins: [
'EventedMethod.Mixin',
'Listener.Mixin'
]
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment