forked from select2/select2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Nadim Afana
committed
May 5, 2016
1 parent
07aa8a4
commit 54e126a
Showing
12 changed files
with
2,700 additions
and
2,636 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,57 +1,58 @@ | ||
define([ | ||
'jquery', | ||
'jquery-mousewheel', | ||
|
||
'./select2/core', | ||
'./select2/defaults' | ||
], function ($, _, Select2, Defaults) { | ||
if ($.fn.select2 == null) { | ||
// All methods that should return the element | ||
var thisMethods = ['open', 'close', 'destroy']; | ||
|
||
$.fn.select2 = function (options) { | ||
options = options || {}; | ||
|
||
if (typeof options === 'object') { | ||
this.each(function () { | ||
var instanceOptions = $.extend(true, {}, options); | ||
|
||
var instance = new Select2($(this), instanceOptions); | ||
}); | ||
|
||
return this; | ||
} else if (typeof options === 'string') { | ||
var ret; | ||
var args = Array.prototype.slice.call(arguments, 1); | ||
|
||
this.each(function () { | ||
var instance = $(this).data('select2'); | ||
|
||
if (instance == null && window.console && console.error) { | ||
console.error( | ||
'The select2(\'' + options + '\') method was called on an ' + | ||
'element that is not using Select2.' | ||
); | ||
} | ||
|
||
ret = instance[options].apply(instance, args); | ||
}); | ||
|
||
// Check if we should be returning `this` | ||
if ($.inArray(options, thisMethods) > -1) { | ||
return this; | ||
} | ||
|
||
return ret; | ||
} else { | ||
throw new Error('Invalid arguments for Select2: ' + options); | ||
} | ||
}; | ||
} | ||
|
||
if ($.fn.select2.defaults == null) { | ||
$.fn.select2.defaults = Defaults; | ||
} | ||
|
||
return Select2; | ||
}); | ||
define([ | ||
'jquery', | ||
'jquery-mousewheel', | ||
|
||
'./select2/core', | ||
'./select2/defaults', | ||
'./select2/utils' | ||
], function ($, _, Select2, Defaults, Utils) { | ||
if ($.fn.select2 == null) { | ||
// All methods that should return the element | ||
var thisMethods = ['open', 'close', 'destroy']; | ||
|
||
$.fn.select2 = function (options) { | ||
options = options || {}; | ||
|
||
if (typeof options === 'object') { | ||
this.each(function () { | ||
var instanceOptions = $.extend(true, {}, options); | ||
|
||
var instance = new Select2($(this), instanceOptions); | ||
}); | ||
|
||
return this; | ||
} else if (typeof options === 'string') { | ||
var ret; | ||
var args = Array.prototype.slice.call(arguments, 1); | ||
|
||
this.each(function () { | ||
var instance = Utils.GetData(this, 'select2'); | ||
|
||
if (instance == null && window.console && console.error) { | ||
console.error( | ||
'The select2(\'' + options + '\') method was called on an ' + | ||
'element that is not using Select2.' | ||
); | ||
} | ||
|
||
ret = instance[options].apply(instance, args); | ||
}); | ||
|
||
// Check if we should be returning `this` | ||
if ($.inArray(options, thisMethods) > -1) { | ||
return this; | ||
} | ||
|
||
return ret; | ||
} else { | ||
throw new Error('Invalid arguments for Select2: ' + options); | ||
} | ||
}; | ||
} | ||
|
||
if ($.fn.select2.defaults == null) { | ||
$.fn.select2.defaults = Defaults; | ||
} | ||
|
||
return Select2; | ||
}); |
Oops, something went wrong.