فهرست منبع

Moved the body click handlers out

This should allow us to start working on the body mask handler,
and make future implementations easier to work with.
Kevin Brown 10 سال پیش
والد
کامیت
be3414f6fe
7فایلهای تغییر یافته به همراه140 افزوده شده و 100 حذف شده
  1. 28 20
      dist/js/select2.amd.full.js
  2. 28 20
      dist/js/select2.amd.js
  3. 28 20
      dist/js/select2.full.js
  4. 0 0
      dist/js/select2.full.min.js
  5. 28 20
      dist/js/select2.js
  6. 0 0
      dist/js/select2.min.js
  7. 28 20
      src/js/select2/selection/base.js

+ 28 - 20
dist/js/select2.amd.full.js

@@ -684,25 +684,7 @@ define('select2/selection/base',[
       // When the dropdown is open, aria-expanded="true"
       self.$selection.attr('aria-expanded', 'true');
 
-      $(document.body).on('mousedown.select2.' + container.id, function (e) {
-        var $target = $(e.target);
-
-        var $select = $target.closest('.select2');
-
-        var $all = $('.select2.select2-container--open');
-
-        $all.each(function () {
-          var $this = $(this);
-
-          if (this == $select[0]) {
-            return;
-          }
-
-          var $element = $this.data('element');
-
-          $element.select2('close');
-        });
-      });
+      self._attachCloseHandler(container);
     });
 
     container.on('close', function () {
@@ -712,10 +694,36 @@ define('select2/selection/base',[
 
       self.$selection.focus();
 
-      $(document.body).off('mousedown.select2.' + container.id);
+      self._detachCloseHandler(container);
     });
   };
 
+  BaseSelection.prototype._attachCloseHandler = function (container) {
+    $(document.body).on('mousedown.select2.' + container.id, function (e) {
+      var $target = $(e.target);
+
+      var $select = $target.closest('.select2');
+
+      var $all = $('.select2.select2-container--open');
+
+      $all.each(function () {
+        var $this = $(this);
+
+        if (this == $select[0]) {
+          return;
+        }
+
+        var $element = $this.data('element');
+
+        $element.select2('close');
+      });
+    });
+  };
+
+  BaseSelection.prototype._detachCloseHandler = function (container) {
+    $(document.body).off('mousedown.select2.' + container.id);
+  };
+
   BaseSelection.prototype.destroy = function () {
     // Unbind the dropdown click handler if it exists
     $(document.body).off('.select2.' + this.container.id);

+ 28 - 20
dist/js/select2.amd.js

@@ -684,25 +684,7 @@ define('select2/selection/base',[
       // When the dropdown is open, aria-expanded="true"
       self.$selection.attr('aria-expanded', 'true');
 
-      $(document.body).on('mousedown.select2.' + container.id, function (e) {
-        var $target = $(e.target);
-
-        var $select = $target.closest('.select2');
-
-        var $all = $('.select2.select2-container--open');
-
-        $all.each(function () {
-          var $this = $(this);
-
-          if (this == $select[0]) {
-            return;
-          }
-
-          var $element = $this.data('element');
-
-          $element.select2('close');
-        });
-      });
+      self._attachCloseHandler(container);
     });
 
     container.on('close', function () {
@@ -712,10 +694,36 @@ define('select2/selection/base',[
 
       self.$selection.focus();
 
-      $(document.body).off('mousedown.select2.' + container.id);
+      self._detachCloseHandler(container);
     });
   };
 
+  BaseSelection.prototype._attachCloseHandler = function (container) {
+    $(document.body).on('mousedown.select2.' + container.id, function (e) {
+      var $target = $(e.target);
+
+      var $select = $target.closest('.select2');
+
+      var $all = $('.select2.select2-container--open');
+
+      $all.each(function () {
+        var $this = $(this);
+
+        if (this == $select[0]) {
+          return;
+        }
+
+        var $element = $this.data('element');
+
+        $element.select2('close');
+      });
+    });
+  };
+
+  BaseSelection.prototype._detachCloseHandler = function (container) {
+    $(document.body).off('mousedown.select2.' + container.id);
+  };
+
   BaseSelection.prototype.destroy = function () {
     // Unbind the dropdown click handler if it exists
     $(document.body).off('.select2.' + this.container.id);

+ 28 - 20
dist/js/select2.full.js

@@ -10219,25 +10219,7 @@ define('select2/selection/base',[
       // When the dropdown is open, aria-expanded="true"
       self.$selection.attr('aria-expanded', 'true');
 
-      $(document.body).on('mousedown.select2.' + container.id, function (e) {
-        var $target = $(e.target);
-
-        var $select = $target.closest('.select2');
-
-        var $all = $('.select2.select2-container--open');
-
-        $all.each(function () {
-          var $this = $(this);
-
-          if (this == $select[0]) {
-            return;
-          }
-
-          var $element = $this.data('element');
-
-          $element.select2('close');
-        });
-      });
+      self._attachCloseHandler(container);
     });
 
     container.on('close', function () {
@@ -10247,10 +10229,36 @@ define('select2/selection/base',[
 
       self.$selection.focus();
 
-      $(document.body).off('mousedown.select2.' + container.id);
+      self._detachCloseHandler(container);
+    });
+  };
+
+  BaseSelection.prototype._attachCloseHandler = function (container) {
+    $(document.body).on('mousedown.select2.' + container.id, function (e) {
+      var $target = $(e.target);
+
+      var $select = $target.closest('.select2');
+
+      var $all = $('.select2.select2-container--open');
+
+      $all.each(function () {
+        var $this = $(this);
+
+        if (this == $select[0]) {
+          return;
+        }
+
+        var $element = $this.data('element');
+
+        $element.select2('close');
+      });
     });
   };
 
+  BaseSelection.prototype._detachCloseHandler = function (container) {
+    $(document.body).off('mousedown.select2.' + container.id);
+  };
+
   BaseSelection.prototype.destroy = function () {
     // Unbind the dropdown click handler if it exists
     $(document.body).off('.select2.' + this.container.id);

تفاوت فایلی نمایش داده نمی شود زیرا این فایل بسیار بزرگ است
+ 0 - 0
dist/js/select2.full.min.js


+ 28 - 20
dist/js/select2.js

@@ -1112,25 +1112,7 @@ define('select2/selection/base',[
       // When the dropdown is open, aria-expanded="true"
       self.$selection.attr('aria-expanded', 'true');
 
-      $(document.body).on('mousedown.select2.' + container.id, function (e) {
-        var $target = $(e.target);
-
-        var $select = $target.closest('.select2');
-
-        var $all = $('.select2.select2-container--open');
-
-        $all.each(function () {
-          var $this = $(this);
-
-          if (this == $select[0]) {
-            return;
-          }
-
-          var $element = $this.data('element');
-
-          $element.select2('close');
-        });
-      });
+      self._attachCloseHandler(container);
     });
 
     container.on('close', function () {
@@ -1140,10 +1122,36 @@ define('select2/selection/base',[
 
       self.$selection.focus();
 
-      $(document.body).off('mousedown.select2.' + container.id);
+      self._detachCloseHandler(container);
     });
   };
 
+  BaseSelection.prototype._attachCloseHandler = function (container) {
+    $(document.body).on('mousedown.select2.' + container.id, function (e) {
+      var $target = $(e.target);
+
+      var $select = $target.closest('.select2');
+
+      var $all = $('.select2.select2-container--open');
+
+      $all.each(function () {
+        var $this = $(this);
+
+        if (this == $select[0]) {
+          return;
+        }
+
+        var $element = $this.data('element');
+
+        $element.select2('close');
+      });
+    });
+  };
+
+  BaseSelection.prototype._detachCloseHandler = function (container) {
+    $(document.body).off('mousedown.select2.' + container.id);
+  };
+
   BaseSelection.prototype.destroy = function () {
     // Unbind the dropdown click handler if it exists
     $(document.body).off('.select2.' + this.container.id);

تفاوت فایلی نمایش داده نمی شود زیرا این فایل بسیار بزرگ است
+ 0 - 0
dist/js/select2.min.js


+ 28 - 20
src/js/select2/selection/base.js

@@ -45,25 +45,7 @@ define([
       // When the dropdown is open, aria-expanded="true"
       self.$selection.attr('aria-expanded', 'true');
 
-      $(document.body).on('mousedown.select2.' + container.id, function (e) {
-        var $target = $(e.target);
-
-        var $select = $target.closest('.select2');
-
-        var $all = $('.select2.select2-container--open');
-
-        $all.each(function () {
-          var $this = $(this);
-
-          if (this == $select[0]) {
-            return;
-          }
-
-          var $element = $this.data('element');
-
-          $element.select2('close');
-        });
-      });
+      self._attachCloseHandler(container);
     });
 
     container.on('close', function () {
@@ -73,10 +55,36 @@ define([
 
       self.$selection.focus();
 
-      $(document.body).off('mousedown.select2.' + container.id);
+      self._detachCloseHandler(container);
     });
   };
 
+  BaseSelection.prototype._attachCloseHandler = function (container) {
+    $(document.body).on('mousedown.select2.' + container.id, function (e) {
+      var $target = $(e.target);
+
+      var $select = $target.closest('.select2');
+
+      var $all = $('.select2.select2-container--open');
+
+      $all.each(function () {
+        var $this = $(this);
+
+        if (this == $select[0]) {
+          return;
+        }
+
+        var $element = $this.data('element');
+
+        $element.select2('close');
+      });
+    });
+  };
+
+  BaseSelection.prototype._detachCloseHandler = function (container) {
+    $(document.body).off('mousedown.select2.' + container.id);
+  };
+
   BaseSelection.prototype.destroy = function () {
     // Unbind the dropdown click handler if it exists
     $(document.body).off('.select2.' + this.container.id);

برخی فایل ها در این مقایسه diff نمایش داده نمی شوند زیرا تعداد فایل ها بسیار زیاد است