f427451853
This exposes the default options for Select2 as `$.fn.select2.defaults`. A default option can be set using the `set(key, val)` option which is available. The key should use the same formatting as the HTML data attributes. This also adds some documentation about it.
40 lines
972 B
JavaScript
40 lines
972 B
JavaScript
define([
|
|
'jquery',
|
|
'./select2/core',
|
|
'./select2/defaults'
|
|
], function ($, Select2, Defaults) {
|
|
// Force jQuery.mousewheel to be loaded if it hasn't already
|
|
try {
|
|
require('jquery.mousewheel');
|
|
} catch (Exception) { }
|
|
|
|
if ($.fn.select2 == null) {
|
|
$.fn.select2 = function (options) {
|
|
options = options || {};
|
|
|
|
if (typeof options === 'object') {
|
|
this.each(function () {
|
|
var instanceOptions = $.extend({}, options, true);
|
|
|
|
var instance = new Select2($(this), instanceOptions);
|
|
});
|
|
|
|
return this;
|
|
} else if (typeof options === 'string') {
|
|
var instance = this.data('select2');
|
|
var args = Array.prototype.slice.call(arguments, 1);
|
|
|
|
return instance[options](args);
|
|
} else {
|
|
throw new Error('Invalid arguments for Select2: ' + options);
|
|
}
|
|
};
|
|
}
|
|
|
|
if ($.fn.select2.defaults == null) {
|
|
$.fn.select2.defaults = Defaults;
|
|
}
|
|
|
|
return Select2;
|
|
});
|