1
0
mirror of synced 2024-11-22 04:56:08 +03:00

Fixed bug when destroying Select2

When destroying Select2, an error could be raised while destroying
the selection container. This was because the destroy handler was
relying on the container id being present.

The old functionality has been restored where Select2 will destroy
itself when it is initialized again.
This commit is contained in:
Kevin Brown 2014-11-25 13:39:46 -05:00
parent ade7180d70
commit 85593de1fa
9 changed files with 25 additions and 14 deletions

View File

@ -660,6 +660,8 @@ define('select2/selection/base',[
var id = container.id + '-container';
var resultsId = container.id + '-results';
this.container = container;
this.$selection.attr('aria-owns', resultsId);
this.$selection.on('keydown', function (evt) {
@ -716,7 +718,7 @@ define('select2/selection/base',[
BaseSelection.prototype.destroy = function () {
// Unbind the dropdown click handler if it exists
$(document.body).off('.select2.' + container.id);
$(document.body).off('.select2.' + this.container.id);
};
BaseSelection.prototype.update = function (data) {
@ -3101,7 +3103,7 @@ define('select2/core',[
], function ($, Options, Utils, KEYS) {
var Select2 = function ($element, options) {
if ($element.data('select2') != null) {
return;
$element.select2('destroy');
}
this.$element = $element;

View File

@ -660,6 +660,8 @@ define('select2/selection/base',[
var id = container.id + '-container';
var resultsId = container.id + '-results';
this.container = container;
this.$selection.attr('aria-owns', resultsId);
this.$selection.on('keydown', function (evt) {
@ -716,7 +718,7 @@ define('select2/selection/base',[
BaseSelection.prototype.destroy = function () {
// Unbind the dropdown click handler if it exists
$(document.body).off('.select2.' + container.id);
$(document.body).off('.select2.' + this.container.id);
};
BaseSelection.prototype.update = function (data) {
@ -3101,7 +3103,7 @@ define('select2/core',[
], function ($, Options, Utils, KEYS) {
var Select2 = function ($element, options) {
if ($element.data('select2') != null) {
return;
$element.select2('destroy');
}
this.$element = $element;

View File

@ -10195,6 +10195,8 @@ define('select2/selection/base',[
var id = container.id + '-container';
var resultsId = container.id + '-results';
this.container = container;
this.$selection.attr('aria-owns', resultsId);
this.$selection.on('keydown', function (evt) {
@ -10251,7 +10253,7 @@ define('select2/selection/base',[
BaseSelection.prototype.destroy = function () {
// Unbind the dropdown click handler if it exists
$(document.body).off('.select2.' + container.id);
$(document.body).off('.select2.' + this.container.id);
};
BaseSelection.prototype.update = function (data) {
@ -12636,7 +12638,7 @@ define('select2/core',[
], function ($, Options, Utils, KEYS) {
var Select2 = function ($element, options) {
if ($element.data('select2') != null) {
return;
$element.select2('destroy');
}
this.$element = $element;

File diff suppressed because one or more lines are too long

6
dist/js/select2.js vendored
View File

@ -1088,6 +1088,8 @@ define('select2/selection/base',[
var id = container.id + '-container';
var resultsId = container.id + '-results';
this.container = container;
this.$selection.attr('aria-owns', resultsId);
this.$selection.on('keydown', function (evt) {
@ -1144,7 +1146,7 @@ define('select2/selection/base',[
BaseSelection.prototype.destroy = function () {
// Unbind the dropdown click handler if it exists
$(document.body).off('.select2.' + container.id);
$(document.body).off('.select2.' + this.container.id);
};
BaseSelection.prototype.update = function (data) {
@ -3529,7 +3531,7 @@ define('select2/core',[
], function ($, Options, Utils, KEYS) {
var Select2 = function ($element, options) {
if ($element.data('select2') != null) {
return;
$element.select2('destroy');
}
this.$element = $element;

File diff suppressed because one or more lines are too long

View File

@ -42,6 +42,7 @@
"grunt-contrib-uglify": "~0.4.0",
"grunt-contrib-watch": "~0.6.0",
"grunt-gh-pages": "^0.9.1",
"grunt-jekyll": "^0.4.2",
"grunt-sass": "~0.12.0",
"node-sass": "~0.8.6"
}

View File

@ -6,7 +6,7 @@ define([
], function ($, Options, Utils, KEYS) {
var Select2 = function ($element, options) {
if ($element.data('select2') != null) {
return;
$element.select2('destroy');
}
this.$element = $element;

View File

@ -21,6 +21,8 @@ define([
var id = container.id + '-container';
var resultsId = container.id + '-results';
this.container = container;
this.$selection.attr('aria-owns', resultsId);
this.$selection.on('keydown', function (evt) {
@ -77,7 +79,7 @@ define([
BaseSelection.prototype.destroy = function () {
// Unbind the dropdown click handler if it exists
$(document.body).off('.select2.' + container.id);
$(document.body).off('.select2.' + this.container.id);
};
BaseSelection.prototype.update = function (data) {