Allow chaining of .select2()
`.select2("open")`, `.select2("close")`, and `.select2("destroy")` can now be safely chained. This closes https://github.com/select2/select2/issues/3221.
This commit is contained in:
parent
da1ec4e028
commit
01160f29d8
12
dist/js/select2.full.js
vendored
12
dist/js/select2.full.js
vendored
@ -5574,6 +5574,9 @@ S2.define('jquery.select2',[
|
||||
require('jquery.mousewheel');
|
||||
|
||||
if ($.fn.select2 == null) {
|
||||
// All methods that should return the element
|
||||
var thisMethods = ['open', 'close', 'destroy'];
|
||||
|
||||
$.fn.select2 = function (options) {
|
||||
options = options || {};
|
||||
|
||||
@ -5589,7 +5592,14 @@ S2.define('jquery.select2',[
|
||||
var instance = this.data('select2');
|
||||
var args = Array.prototype.slice.call(arguments, 1);
|
||||
|
||||
return instance[options](args);
|
||||
var ret = instance[options](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);
|
||||
}
|
||||
|
4
dist/js/select2.full.min.js
vendored
4
dist/js/select2.full.min.js
vendored
File diff suppressed because one or more lines are too long
12
dist/js/select2.js
vendored
12
dist/js/select2.js
vendored
@ -5236,6 +5236,9 @@ S2.define('jquery.select2',[
|
||||
require('jquery.mousewheel');
|
||||
|
||||
if ($.fn.select2 == null) {
|
||||
// All methods that should return the element
|
||||
var thisMethods = ['open', 'close', 'destroy'];
|
||||
|
||||
$.fn.select2 = function (options) {
|
||||
options = options || {};
|
||||
|
||||
@ -5251,7 +5254,14 @@ S2.define('jquery.select2',[
|
||||
var instance = this.data('select2');
|
||||
var args = Array.prototype.slice.call(arguments, 1);
|
||||
|
||||
return instance[options](args);
|
||||
var ret = instance[options](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);
|
||||
}
|
||||
|
2
dist/js/select2.min.js
vendored
2
dist/js/select2.min.js
vendored
File diff suppressed because one or more lines are too long
@ -9,6 +9,9 @@ define([
|
||||
require('jquery.mousewheel');
|
||||
|
||||
if ($.fn.select2 == null) {
|
||||
// All methods that should return the element
|
||||
var thisMethods = ['open', 'close', 'destroy'];
|
||||
|
||||
$.fn.select2 = function (options) {
|
||||
options = options || {};
|
||||
|
||||
@ -24,7 +27,14 @@ define([
|
||||
var instance = this.data('select2');
|
||||
var args = Array.prototype.slice.call(arguments, 1);
|
||||
|
||||
return instance[options](args);
|
||||
var ret = instance[options](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);
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user