1
0
mirror of synced 2024-11-29 16:16:02 +03:00

Register the click handler in the container

This shouldn't be in the core, it's much easier to override things
in the container.
This commit is contained in:
Kevin Brown 2014-11-01 19:36:02 -04:00
parent 130358e8ae
commit 3b575ad92f
8 changed files with 133 additions and 103 deletions

View File

@ -534,6 +534,32 @@ define('select2/selection/base',[
container.on('selection:update', function (params) { container.on('selection:update', function (params) {
self.update(params.data); 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) { BaseSelection.prototype.update = function (data) {
@ -1746,26 +1772,6 @@ define('select2/core',[
Select2.prototype._registerDomEvents = function () { Select2.prototype._registerDomEvents = function () {
var self = this; 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 () { this.$element.on('change', function () {
self.data.current(function (data) { self.data.current(function (data) {
self.trigger('selection:update', { self.trigger('selection:update', {

View File

@ -534,6 +534,32 @@ define('select2/selection/base',[
container.on('selection:update', function (params) { container.on('selection:update', function (params) {
self.update(params.data); 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) { BaseSelection.prototype.update = function (data) {
@ -1746,26 +1772,6 @@ define('select2/core',[
Select2.prototype._registerDomEvents = function () { Select2.prototype._registerDomEvents = function () {
var self = this; 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 () { this.$element.on('change', function () {
self.data.current(function (data) { self.data.current(function (data) {
self.trigger('selection:update', { self.trigger('selection:update', {

View File

@ -10069,6 +10069,32 @@ define('select2/selection/base',[
container.on('selection:update', function (params) { container.on('selection:update', function (params) {
self.update(params.data); 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) { BaseSelection.prototype.update = function (data) {
@ -11281,26 +11307,6 @@ define('select2/core',[
Select2.prototype._registerDomEvents = function () { Select2.prototype._registerDomEvents = function () {
var self = this; 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 () { this.$element.on('change', function () {
self.data.current(function (data) { self.data.current(function (data) {
self.trigger('selection:update', { self.trigger('selection:update', {

File diff suppressed because one or more lines are too long

46
dist/js/select2.js vendored
View File

@ -962,6 +962,32 @@ define('select2/selection/base',[
container.on('selection:update', function (params) { container.on('selection:update', function (params) {
self.update(params.data); 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) { BaseSelection.prototype.update = function (data) {
@ -2174,26 +2200,6 @@ define('select2/core',[
Select2.prototype._registerDomEvents = function () { Select2.prototype._registerDomEvents = function () {
var self = this; 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 () { this.$element.on('change', function () {
self.data.current(function (data) { self.data.current(function (data) {
self.trigger('selection:update', { self.trigger('selection:update', {

File diff suppressed because one or more lines are too long

View File

@ -128,26 +128,6 @@ define([
Select2.prototype._registerDomEvents = function () { Select2.prototype._registerDomEvents = function () {
var self = this; 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 () { this.$element.on('change', function () {
self.data.current(function (data) { self.data.current(function (data) {
self.trigger('selection:update', { self.trigger('selection:update', {

View File

@ -20,6 +20,32 @@ define([
container.on('selection:update', function (params) { container.on('selection:update', function (params) {
self.update(params.data); 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) { BaseSelection.prototype.update = function (data) {