| 1 |
define([ |
| 2 |
'jquery', |
| 3 |
'jquery-mousewheel', |
| 4 |
|
| 5 |
'./select2/core', |
| 6 |
'./select2/defaults', |
| 7 |
'./select2/utils' |
| 8 |
], function ($, _, Select2, Defaults, Utils) { |
| 9 |
if ($.fn.select2 == null) { |
| 10 |
// All methods that should return the element |
| 11 |
var thisMethods = ['open', 'close', 'destroy']; |
| 12 |
|
| 13 |
$.fn.select2 = function (options) { |
| 14 |
options = options || {}; |
| 15 |
|
| 16 |
if (typeof options === 'object') { |
| 17 |
this.each(function () { |
| 18 |
var instanceOptions = $.extend(true, {}, options); |
| 19 |
|
| 20 |
var instance = new Select2($(this), instanceOptions); |
| 21 |
}); |
| 22 |
|
| 23 |
return this; |
| 24 |
} else if (typeof options === 'string') { |
| 25 |
var ret; |
| 26 |
var args = Array.prototype.slice.call(arguments, 1); |
| 27 |
|
| 28 |
this.each(function () { |
| 29 |
var instance = Utils.GetData(this, 'select2'); |
| 30 |
|
| 31 |
if (instance == null && window.console && console.error) { |
| 32 |
console.error( |
| 33 |
'The select2(\'' + options + '\') method was called on an ' + |
| 34 |
'element that is not using Select2.' |
| 35 |
); |
| 36 |
} |
| 37 |
|
| 38 |
ret = instance[options].apply(instance, args); |
| 39 |
}); |
| 40 |
|
| 41 |
// Check if we should be returning `this` |
| 42 |
if ($.inArray(options, thisMethods) > -1) { |
| 43 |
return this; |
| 44 |
} |
| 45 |
|
| 46 |
return ret; |
| 47 |
} else { |
| 48 |
throw new Error('Invalid arguments for Select2: ' + options); |
| 49 |
} |
| 50 |
}; |
| 51 |
} |
| 52 |
|
| 53 |
if ($.fn.select2.defaults == null) { |
| 54 |
$.fn.select2.defaults = Defaults; |
| 55 |
} |
| 56 |
|
| 57 |
return Select2; |
| 58 |
}); |
| 59 |
|