瀏覽代碼

Register the click handler in the container

This shouldn't be in the core, it's much easier to override things
in the container.
Kevin Brown 10 年之前
父節點
當前提交
3b575ad92f

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

@@ -534,6 +534,32 @@ define('select2/selection/base',[
     container.on('selection:update', function (params) {
       self.update(params.data);
     });
+
+    container.on('open', function () {
+      $(document.body).on('mousedown.select2.' + container.id, function (e) {
+        var $target = $(e.target);
+
+        var $select = $target.closest('.select2');
+
+        var $all = $('.select2.open');
+
+        $all.each(function () {
+          var $this = $(this);
+
+          if (this == $select[0]) {
+            return;
+          }
+
+          var $element = $this.data('element');
+
+          $element.select2('close');
+        });
+      });
+
+      container.on('close', function () {
+        $(document.body).off('mousedown.select2.' + container.id);
+      });
+    });
   };
 
   BaseSelection.prototype.update = function (data) {
@@ -1746,26 +1772,6 @@ define('select2/core',[
   Select2.prototype._registerDomEvents = function () {
     var self = this;
 
-    $(document.body).on('mousedown', function (e) {
-      var $target = $(e.target);
-
-      var $select = $target.closest('.select2');
-
-      var $all = $('.select2.open');
-
-      $all.each(function () {
-        var $this = $(this);
-
-        if (this == $select[0]) {
-          return;
-        }
-
-        var $element = $this.data('element');
-
-        $element.select2('close');
-      });
-    });
-
     this.$element.on('change', function () {
       self.data.current(function (data) {
         self.trigger('selection:update', {

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

@@ -534,6 +534,32 @@ define('select2/selection/base',[
     container.on('selection:update', function (params) {
       self.update(params.data);
     });
+
+    container.on('open', function () {
+      $(document.body).on('mousedown.select2.' + container.id, function (e) {
+        var $target = $(e.target);
+
+        var $select = $target.closest('.select2');
+
+        var $all = $('.select2.open');
+
+        $all.each(function () {
+          var $this = $(this);
+
+          if (this == $select[0]) {
+            return;
+          }
+
+          var $element = $this.data('element');
+
+          $element.select2('close');
+        });
+      });
+
+      container.on('close', function () {
+        $(document.body).off('mousedown.select2.' + container.id);
+      });
+    });
   };
 
   BaseSelection.prototype.update = function (data) {
@@ -1746,26 +1772,6 @@ define('select2/core',[
   Select2.prototype._registerDomEvents = function () {
     var self = this;
 
-    $(document.body).on('mousedown', function (e) {
-      var $target = $(e.target);
-
-      var $select = $target.closest('.select2');
-
-      var $all = $('.select2.open');
-
-      $all.each(function () {
-        var $this = $(this);
-
-        if (this == $select[0]) {
-          return;
-        }
-
-        var $element = $this.data('element');
-
-        $element.select2('close');
-      });
-    });
-
     this.$element.on('change', function () {
       self.data.current(function (data) {
         self.trigger('selection:update', {

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

@@ -10069,6 +10069,32 @@ define('select2/selection/base',[
     container.on('selection:update', function (params) {
       self.update(params.data);
     });
+
+    container.on('open', function () {
+      $(document.body).on('mousedown.select2.' + container.id, function (e) {
+        var $target = $(e.target);
+
+        var $select = $target.closest('.select2');
+
+        var $all = $('.select2.open');
+
+        $all.each(function () {
+          var $this = $(this);
+
+          if (this == $select[0]) {
+            return;
+          }
+
+          var $element = $this.data('element');
+
+          $element.select2('close');
+        });
+      });
+
+      container.on('close', function () {
+        $(document.body).off('mousedown.select2.' + container.id);
+      });
+    });
   };
 
   BaseSelection.prototype.update = function (data) {
@@ -11281,26 +11307,6 @@ define('select2/core',[
   Select2.prototype._registerDomEvents = function () {
     var self = this;
 
-    $(document.body).on('mousedown', function (e) {
-      var $target = $(e.target);
-
-      var $select = $target.closest('.select2');
-
-      var $all = $('.select2.open');
-
-      $all.each(function () {
-        var $this = $(this);
-
-        if (this == $select[0]) {
-          return;
-        }
-
-        var $element = $this.data('element');
-
-        $element.select2('close');
-      });
-    });
-
     this.$element.on('change', function () {
       self.data.current(function (data) {
         self.trigger('selection:update', {

文件差異過大導致無法顯示
+ 0 - 0
dist/js/select2.full.min.js


+ 26 - 20
dist/js/select2.js

@@ -962,6 +962,32 @@ define('select2/selection/base',[
     container.on('selection:update', function (params) {
       self.update(params.data);
     });
+
+    container.on('open', function () {
+      $(document.body).on('mousedown.select2.' + container.id, function (e) {
+        var $target = $(e.target);
+
+        var $select = $target.closest('.select2');
+
+        var $all = $('.select2.open');
+
+        $all.each(function () {
+          var $this = $(this);
+
+          if (this == $select[0]) {
+            return;
+          }
+
+          var $element = $this.data('element');
+
+          $element.select2('close');
+        });
+      });
+
+      container.on('close', function () {
+        $(document.body).off('mousedown.select2.' + container.id);
+      });
+    });
   };
 
   BaseSelection.prototype.update = function (data) {
@@ -2174,26 +2200,6 @@ define('select2/core',[
   Select2.prototype._registerDomEvents = function () {
     var self = this;
 
-    $(document.body).on('mousedown', function (e) {
-      var $target = $(e.target);
-
-      var $select = $target.closest('.select2');
-
-      var $all = $('.select2.open');
-
-      $all.each(function () {
-        var $this = $(this);
-
-        if (this == $select[0]) {
-          return;
-        }
-
-        var $element = $this.data('element');
-
-        $element.select2('close');
-      });
-    });
-
     this.$element.on('change', function () {
       self.data.current(function (data) {
         self.trigger('selection:update', {

文件差異過大導致無法顯示
+ 0 - 0
dist/js/select2.min.js


+ 0 - 20
src/js/select2/core.js

@@ -128,26 +128,6 @@ define([
   Select2.prototype._registerDomEvents = function () {
     var self = this;
 
-    $(document.body).on('mousedown', function (e) {
-      var $target = $(e.target);
-
-      var $select = $target.closest('.select2');
-
-      var $all = $('.select2.open');
-
-      $all.each(function () {
-        var $this = $(this);
-
-        if (this == $select[0]) {
-          return;
-        }
-
-        var $element = $this.data('element');
-
-        $element.select2('close');
-      });
-    });
-
     this.$element.on('change', function () {
       self.data.current(function (data) {
         self.trigger('selection:update', {

+ 26 - 0
src/js/select2/selection/base.js

@@ -20,6 +20,32 @@ define([
     container.on('selection:update', function (params) {
       self.update(params.data);
     });
+
+    container.on('open', function () {
+      $(document.body).on('mousedown.select2.' + container.id, function (e) {
+        var $target = $(e.target);
+
+        var $select = $target.closest('.select2');
+
+        var $all = $('.select2.open');
+
+        $all.each(function () {
+          var $this = $(this);
+
+          if (this == $select[0]) {
+            return;
+          }
+
+          var $element = $this.data('element');
+
+          $element.select2('close');
+        });
+      });
+
+      container.on('close', function () {
+        $(document.body).off('mousedown.select2.' + container.id);
+      });
+    });
   };
 
   BaseSelection.prototype.update = function (data) {

部分文件因文件數量過多而無法顯示