1
0
mirror of synced 2024-11-25 22:36:03 +03:00

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.
This commit is contained in:
Kevin Brown 2014-11-25 14:03:21 -05:00
parent 85593de1fa
commit be3414f6fe
7 changed files with 143 additions and 103 deletions

View File

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

View File

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

View File

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

File diff suppressed because one or more lines are too long

48
dist/js/select2.js vendored
View File

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

File diff suppressed because one or more lines are too long

View File

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