introduced destroy method, closes #18
This commit is contained in:
parent
c8b274e9ab
commit
1faea146d4
24
select2.js
24
select2.js
@ -318,6 +318,11 @@
|
||||
// prepare options
|
||||
this.opts = this.prepareOpts(opts);
|
||||
|
||||
// destroy if called on an existing component
|
||||
if (opts.element.data("select2") !== undefined) {
|
||||
this.destroy();
|
||||
}
|
||||
|
||||
this.container = this.createContainer();
|
||||
|
||||
if (opts.element.attr("class") !== undefined) {
|
||||
@ -325,7 +330,8 @@
|
||||
}
|
||||
|
||||
// swap container for the element
|
||||
this.opts.element.data("select2", this)
|
||||
this.opts.element
|
||||
.data("select2", this)
|
||||
.hide()
|
||||
.after(this.container);
|
||||
this.container.data("select2", this);
|
||||
@ -382,6 +388,16 @@
|
||||
}
|
||||
};
|
||||
|
||||
AbstractSelect2.prototype.destroy = function () {
|
||||
var select2 = this.opts.element.data("select2");
|
||||
if (select2 !== undefined) {
|
||||
select2.container.remove();
|
||||
select2.opts.element
|
||||
.removeData("select2")
|
||||
.show();
|
||||
}
|
||||
};
|
||||
|
||||
AbstractSelect2.prototype.prepareOpts = function (opts) {
|
||||
var element, select;
|
||||
|
||||
@ -1157,7 +1173,8 @@
|
||||
// filter out duplicates
|
||||
$(data).each(function () {
|
||||
if (indexOf(this.id, ids) < 0) {
|
||||
ids.push(this.id); filtered.push(this);
|
||||
ids.push(this.id);
|
||||
filtered.push(this);
|
||||
}
|
||||
});
|
||||
data = filtered;
|
||||
@ -1344,7 +1361,7 @@
|
||||
var args = Array.prototype.slice.call(arguments, 0),
|
||||
opts,
|
||||
select2,
|
||||
value, multiple, allowedMethods = ["val"];
|
||||
value, multiple, allowedMethods = ["val", "destroy"];
|
||||
|
||||
this.each(function () {
|
||||
if (args.length === 0 || typeof(args[0]) === "object") {
|
||||
@ -1368,6 +1385,7 @@
|
||||
|
||||
value = undefined;
|
||||
select2 = $(this).data("select2");
|
||||
if (select2 === undefined) return;
|
||||
value = select2[args[0]].apply(select2, args.slice(1));
|
||||
if (value !== undefined) {return false;}
|
||||
} else {
|
||||
|
Loading…
Reference in New Issue
Block a user