Created
October 31, 2014 19:31
-
-
Save djpate/ecb8a6d90a418b0eb2ea to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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