Przeglądaj źródła

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.
Kevin Brown 10 lat temu
rodzic
commit
85593de1fa

+ 4 - 2
dist/js/select2.amd.full.js

@@ -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;

+ 4 - 2
dist/js/select2.amd.js

@@ -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;

+ 4 - 2
dist/js/select2.full.js

@@ -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;

Plik diff jest za duży
+ 0 - 0
dist/js/select2.full.min.js


+ 4 - 2
dist/js/select2.js

@@ -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;

Plik diff jest za duży
+ 0 - 0
dist/js/select2.min.js


+ 1 - 0
package.json

@@ -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"
   }

+ 1 - 1
src/js/select2/core.js

@@ -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;

+ 3 - 1
src/js/select2/selection/base.js

@@ -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) {

Niektóre pliki nie zostały wyświetlone z powodu dużej ilości zmienionych plików