2014-10-14 21:12:57 -04:00
|
|
|
define([
|
|
|
|
'jquery',
|
2015-03-25 07:04:53 +09:00
|
|
|
'require',
|
|
|
|
|
2015-01-17 21:27:53 -05:00
|
|
|
'./select2/core',
|
|
|
|
'./select2/defaults'
|
2015-03-25 07:04:53 +09:00
|
|
|
], function ($, require, Select2, Defaults) {
|
2015-01-02 20:32:14 -05:00
|
|
|
// Force jQuery.mousewheel to be loaded if it hasn't already
|
2015-03-25 07:04:53 +09:00
|
|
|
require('jquery.mousewheel');
|
2015-01-02 20:32:14 -05:00
|
|
|
|
2014-10-14 21:12:57 -04:00
|
|
|
if ($.fn.select2 == null) {
|
2015-04-02 10:34:30 -04:00
|
|
|
// All methods that should return the element
|
|
|
|
var thisMethods = ['open', 'close', 'destroy'];
|
|
|
|
|
2014-10-14 21:12:57 -04:00
|
|
|
$.fn.select2 = function (options) {
|
|
|
|
options = options || {};
|
|
|
|
|
|
|
|
if (typeof options === 'object') {
|
|
|
|
this.each(function () {
|
2015-01-02 18:15:59 -05:00
|
|
|
var instanceOptions = $.extend({}, options, true);
|
|
|
|
|
|
|
|
var instance = new Select2($(this), instanceOptions);
|
2014-10-14 21:12:57 -04:00
|
|
|
});
|
2015-01-02 18:15:59 -05:00
|
|
|
|
|
|
|
return this;
|
2014-10-14 21:12:57 -04:00
|
|
|
} else if (typeof options === 'string') {
|
|
|
|
var instance = this.data('select2');
|
2015-04-02 11:41:18 -04:00
|
|
|
|
|
|
|
if (instance == null && window.console && console.error) {
|
|
|
|
console.error(
|
|
|
|
'The select2(\'' + options + '\') method was called on an ' +
|
|
|
|
'element that is not using Select2.'
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2014-10-20 20:29:23 -04:00
|
|
|
var args = Array.prototype.slice.call(arguments, 1);
|
2014-10-14 21:12:57 -04:00
|
|
|
|
2015-04-02 10:34:30 -04:00
|
|
|
var ret = instance[options](args);
|
|
|
|
|
|
|
|
// Check if we should be returning `this`
|
|
|
|
if ($.inArray(options, thisMethods) > -1) {
|
|
|
|
return this;
|
|
|
|
}
|
|
|
|
|
|
|
|
return ret;
|
2014-10-14 21:12:57 -04:00
|
|
|
} else {
|
|
|
|
throw new Error('Invalid arguments for Select2: ' + options);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2015-01-17 21:27:53 -05:00
|
|
|
if ($.fn.select2.defaults == null) {
|
|
|
|
$.fn.select2.defaults = Defaults;
|
|
|
|
}
|
|
|
|
|
2014-10-14 21:12:57 -04:00
|
|
|
return Select2;
|
|
|
|
});
|