1
0
mirror of synced 2024-11-22 13:06:08 +03:00

Move all of the event binding into separate methods

This should make it easier to override in subclasses.
This commit is contained in:
Kevin Brown 2014-11-01 19:05:08 -04:00
parent 47d0bc4fe1
commit f8ca597f02
7 changed files with 497 additions and 352 deletions

View File

@ -1666,69 +1666,16 @@ define('select2/core',[
var self = this;
this.data.bind(this, $container);
this.selection.bind(this, $container);
// Bind the container to all of the adapters
this._bindAdapters();
this.dropdown.bind(this, $container);
this.results.bind(this, $container);
// Register any DOM event handler
this._registerDomEvents();
this.$element.on('change', function () {
self.data.current(function (data) {
self.trigger('selection:update', {
data: data
});
});
});
this.selection.on('open', function () {
self.open();
});
this.selection.on('close', function () {
self.close();
});
this.selection.on('toggle', function () {
self.toggleDropdown();
});
this.selection.on('results:select', function () {
self.trigger('results:select');
});
this.selection.on('results:previous', function () {
self.trigger('results:previous');
});
this.selection.on('results:next', function () {
self.trigger('results:next');
});
this.selection.on('unselected', function (params) {
self.trigger('unselect', params);
self.close();
});
this.results.on('selected', function (params) {
self.trigger('select', params);
self.close();
});
this.results.on('unselected', function (params) {
self.trigger('unselect', params);
self.close();
});
this.results.on('results:focus', function (params) {
self.trigger('results:focus', params);
});
this.on('open', function () {
$container.addClass('open');
});
this.on('close', function () {
$container.removeClass('open');
});
// Register any internal event handlers
this._registerSelectionEvents();
this._registerResultsEvents();
this._registerEvents();
// Set the initial state
@ -1738,15 +1685,6 @@ define('select2/core',[
});
});
this.on('query', function (params) {
this.data.query(params, function (data) {
self.trigger('results:all', {
data: data,
query: params
});
});
});
this.trigger('query', {});
// Hide the original select
@ -1797,6 +1735,97 @@ define('select2/core',[
$resultsContainer.append($results);
};
Select2.prototype._bindAdapters = function () {
this.data.bind(this, this.$container);
this.selection.bind(this, this.$container);
this.dropdown.bind(this, this.$container);
this.results.bind(this, this.$container);
};
Select2.prototype._registerDomEvents = function () {
var self = this;
this.$element.on('change', function () {
self.data.current(function (data) {
self.trigger('selection:update', {
data: data
});
});
});
};
Select2.prototype._registerSelectionEvents = function () {
var self = this;
this.selection.on('open', function () {
self.open();
});
this.selection.on('close', function () {
self.close();
});
this.selection.on('toggle', function () {
self.toggleDropdown();
});
this.selection.on('results:select', function () {
self.trigger('results:select');
});
this.selection.on('results:previous', function () {
self.trigger('results:previous');
});
this.selection.on('results:next', function () {
self.trigger('results:next');
});
this.selection.on('unselected', function (params) {
self.trigger('unselect', params);
self.close();
});
};
Select2.prototype._registerResultsEvents = function () {
var self = this;
this.results.on('selected', function (params) {
self.trigger('select', params);
self.close();
});
this.results.on('unselected', function (params) {
self.trigger('unselect', params);
self.close();
});
this.results.on('results:focus', function (params) {
self.trigger('results:focus', params);
});
};
Select2.prototype._registerEvents = function () {
var self = this;
this.on('open', function () {
self.$container.addClass('open');
});
this.on('close', function () {
self.$container.removeClass('open');
});
this.on('query', function (params) {
this.data.query(params, function (data) {
self.trigger('results:all', {
data: data,
query: params
});
});
});
};
Select2.prototype.toggleDropdown = function () {
if (this.isOpen()) {
this.close();

169
dist/js/select2.amd.js vendored
View File

@ -1666,69 +1666,16 @@ define('select2/core',[
var self = this;
this.data.bind(this, $container);
this.selection.bind(this, $container);
// Bind the container to all of the adapters
this._bindAdapters();
this.dropdown.bind(this, $container);
this.results.bind(this, $container);
// Register any DOM event handler
this._registerDomEvents();
this.$element.on('change', function () {
self.data.current(function (data) {
self.trigger('selection:update', {
data: data
});
});
});
this.selection.on('open', function () {
self.open();
});
this.selection.on('close', function () {
self.close();
});
this.selection.on('toggle', function () {
self.toggleDropdown();
});
this.selection.on('results:select', function () {
self.trigger('results:select');
});
this.selection.on('results:previous', function () {
self.trigger('results:previous');
});
this.selection.on('results:next', function () {
self.trigger('results:next');
});
this.selection.on('unselected', function (params) {
self.trigger('unselect', params);
self.close();
});
this.results.on('selected', function (params) {
self.trigger('select', params);
self.close();
});
this.results.on('unselected', function (params) {
self.trigger('unselect', params);
self.close();
});
this.results.on('results:focus', function (params) {
self.trigger('results:focus', params);
});
this.on('open', function () {
$container.addClass('open');
});
this.on('close', function () {
$container.removeClass('open');
});
// Register any internal event handlers
this._registerSelectionEvents();
this._registerResultsEvents();
this._registerEvents();
// Set the initial state
@ -1738,15 +1685,6 @@ define('select2/core',[
});
});
this.on('query', function (params) {
this.data.query(params, function (data) {
self.trigger('results:all', {
data: data,
query: params
});
});
});
this.trigger('query', {});
// Hide the original select
@ -1797,6 +1735,97 @@ define('select2/core',[
$resultsContainer.append($results);
};
Select2.prototype._bindAdapters = function () {
this.data.bind(this, this.$container);
this.selection.bind(this, this.$container);
this.dropdown.bind(this, this.$container);
this.results.bind(this, this.$container);
};
Select2.prototype._registerDomEvents = function () {
var self = this;
this.$element.on('change', function () {
self.data.current(function (data) {
self.trigger('selection:update', {
data: data
});
});
});
};
Select2.prototype._registerSelectionEvents = function () {
var self = this;
this.selection.on('open', function () {
self.open();
});
this.selection.on('close', function () {
self.close();
});
this.selection.on('toggle', function () {
self.toggleDropdown();
});
this.selection.on('results:select', function () {
self.trigger('results:select');
});
this.selection.on('results:previous', function () {
self.trigger('results:previous');
});
this.selection.on('results:next', function () {
self.trigger('results:next');
});
this.selection.on('unselected', function (params) {
self.trigger('unselect', params);
self.close();
});
};
Select2.prototype._registerResultsEvents = function () {
var self = this;
this.results.on('selected', function (params) {
self.trigger('select', params);
self.close();
});
this.results.on('unselected', function (params) {
self.trigger('unselect', params);
self.close();
});
this.results.on('results:focus', function (params) {
self.trigger('results:focus', params);
});
};
Select2.prototype._registerEvents = function () {
var self = this;
this.on('open', function () {
self.$container.addClass('open');
});
this.on('close', function () {
self.$container.removeClass('open');
});
this.on('query', function (params) {
this.data.query(params, function (data) {
self.trigger('results:all', {
data: data,
query: params
});
});
});
};
Select2.prototype.toggleDropdown = function () {
if (this.isOpen()) {
this.close();

View File

@ -11201,69 +11201,16 @@ define('select2/core',[
var self = this;
this.data.bind(this, $container);
this.selection.bind(this, $container);
// Bind the container to all of the adapters
this._bindAdapters();
this.dropdown.bind(this, $container);
this.results.bind(this, $container);
// Register any DOM event handler
this._registerDomEvents();
this.$element.on('change', function () {
self.data.current(function (data) {
self.trigger('selection:update', {
data: data
});
});
});
this.selection.on('open', function () {
self.open();
});
this.selection.on('close', function () {
self.close();
});
this.selection.on('toggle', function () {
self.toggleDropdown();
});
this.selection.on('results:select', function () {
self.trigger('results:select');
});
this.selection.on('results:previous', function () {
self.trigger('results:previous');
});
this.selection.on('results:next', function () {
self.trigger('results:next');
});
this.selection.on('unselected', function (params) {
self.trigger('unselect', params);
self.close();
});
this.results.on('selected', function (params) {
self.trigger('select', params);
self.close();
});
this.results.on('unselected', function (params) {
self.trigger('unselect', params);
self.close();
});
this.results.on('results:focus', function (params) {
self.trigger('results:focus', params);
});
this.on('open', function () {
$container.addClass('open');
});
this.on('close', function () {
$container.removeClass('open');
});
// Register any internal event handlers
this._registerSelectionEvents();
this._registerResultsEvents();
this._registerEvents();
// Set the initial state
@ -11273,15 +11220,6 @@ define('select2/core',[
});
});
this.on('query', function (params) {
this.data.query(params, function (data) {
self.trigger('results:all', {
data: data,
query: params
});
});
});
this.trigger('query', {});
// Hide the original select
@ -11332,6 +11270,97 @@ define('select2/core',[
$resultsContainer.append($results);
};
Select2.prototype._bindAdapters = function () {
this.data.bind(this, this.$container);
this.selection.bind(this, this.$container);
this.dropdown.bind(this, this.$container);
this.results.bind(this, this.$container);
};
Select2.prototype._registerDomEvents = function () {
var self = this;
this.$element.on('change', function () {
self.data.current(function (data) {
self.trigger('selection:update', {
data: data
});
});
});
};
Select2.prototype._registerSelectionEvents = function () {
var self = this;
this.selection.on('open', function () {
self.open();
});
this.selection.on('close', function () {
self.close();
});
this.selection.on('toggle', function () {
self.toggleDropdown();
});
this.selection.on('results:select', function () {
self.trigger('results:select');
});
this.selection.on('results:previous', function () {
self.trigger('results:previous');
});
this.selection.on('results:next', function () {
self.trigger('results:next');
});
this.selection.on('unselected', function (params) {
self.trigger('unselect', params);
self.close();
});
};
Select2.prototype._registerResultsEvents = function () {
var self = this;
this.results.on('selected', function (params) {
self.trigger('select', params);
self.close();
});
this.results.on('unselected', function (params) {
self.trigger('unselect', params);
self.close();
});
this.results.on('results:focus', function (params) {
self.trigger('results:focus', params);
});
};
Select2.prototype._registerEvents = function () {
var self = this;
this.on('open', function () {
self.$container.addClass('open');
});
this.on('close', function () {
self.$container.removeClass('open');
});
this.on('query', function (params) {
this.data.query(params, function (data) {
self.trigger('results:all', {
data: data,
query: params
});
});
});
};
Select2.prototype.toggleDropdown = function () {
if (this.isOpen()) {
this.close();

File diff suppressed because one or more lines are too long

169
dist/js/select2.js vendored
View File

@ -2094,69 +2094,16 @@ define('select2/core',[
var self = this;
this.data.bind(this, $container);
this.selection.bind(this, $container);
// Bind the container to all of the adapters
this._bindAdapters();
this.dropdown.bind(this, $container);
this.results.bind(this, $container);
// Register any DOM event handler
this._registerDomEvents();
this.$element.on('change', function () {
self.data.current(function (data) {
self.trigger('selection:update', {
data: data
});
});
});
this.selection.on('open', function () {
self.open();
});
this.selection.on('close', function () {
self.close();
});
this.selection.on('toggle', function () {
self.toggleDropdown();
});
this.selection.on('results:select', function () {
self.trigger('results:select');
});
this.selection.on('results:previous', function () {
self.trigger('results:previous');
});
this.selection.on('results:next', function () {
self.trigger('results:next');
});
this.selection.on('unselected', function (params) {
self.trigger('unselect', params);
self.close();
});
this.results.on('selected', function (params) {
self.trigger('select', params);
self.close();
});
this.results.on('unselected', function (params) {
self.trigger('unselect', params);
self.close();
});
this.results.on('results:focus', function (params) {
self.trigger('results:focus', params);
});
this.on('open', function () {
$container.addClass('open');
});
this.on('close', function () {
$container.removeClass('open');
});
// Register any internal event handlers
this._registerSelectionEvents();
this._registerResultsEvents();
this._registerEvents();
// Set the initial state
@ -2166,15 +2113,6 @@ define('select2/core',[
});
});
this.on('query', function (params) {
this.data.query(params, function (data) {
self.trigger('results:all', {
data: data,
query: params
});
});
});
this.trigger('query', {});
// Hide the original select
@ -2225,6 +2163,97 @@ define('select2/core',[
$resultsContainer.append($results);
};
Select2.prototype._bindAdapters = function () {
this.data.bind(this, this.$container);
this.selection.bind(this, this.$container);
this.dropdown.bind(this, this.$container);
this.results.bind(this, this.$container);
};
Select2.prototype._registerDomEvents = function () {
var self = this;
this.$element.on('change', function () {
self.data.current(function (data) {
self.trigger('selection:update', {
data: data
});
});
});
};
Select2.prototype._registerSelectionEvents = function () {
var self = this;
this.selection.on('open', function () {
self.open();
});
this.selection.on('close', function () {
self.close();
});
this.selection.on('toggle', function () {
self.toggleDropdown();
});
this.selection.on('results:select', function () {
self.trigger('results:select');
});
this.selection.on('results:previous', function () {
self.trigger('results:previous');
});
this.selection.on('results:next', function () {
self.trigger('results:next');
});
this.selection.on('unselected', function (params) {
self.trigger('unselect', params);
self.close();
});
};
Select2.prototype._registerResultsEvents = function () {
var self = this;
this.results.on('selected', function (params) {
self.trigger('select', params);
self.close();
});
this.results.on('unselected', function (params) {
self.trigger('unselect', params);
self.close();
});
this.results.on('results:focus', function (params) {
self.trigger('results:focus', params);
});
};
Select2.prototype._registerEvents = function () {
var self = this;
this.on('open', function () {
self.$container.addClass('open');
});
this.on('close', function () {
self.$container.removeClass('open');
});
this.on('query', function (params) {
this.data.query(params, function (data) {
self.trigger('results:all', {
data: data,
query: params
});
});
});
};
Select2.prototype.toggleDropdown = function () {
if (this.isOpen()) {
this.close();

File diff suppressed because one or more lines are too long

169
src/js/select2/core.js vendored
View File

@ -48,69 +48,16 @@ define([
var self = this;
this.data.bind(this, $container);
this.selection.bind(this, $container);
// Bind the container to all of the adapters
this._bindAdapters();
this.dropdown.bind(this, $container);
this.results.bind(this, $container);
// Register any DOM event handlers
this._registerDomEvents();
this.$element.on('change', function () {
self.data.current(function (data) {
self.trigger('selection:update', {
data: data
});
});
});
this.selection.on('open', function () {
self.open();
});
this.selection.on('close', function () {
self.close();
});
this.selection.on('toggle', function () {
self.toggleDropdown();
});
this.selection.on('results:select', function () {
self.trigger('results:select');
});
this.selection.on('results:previous', function () {
self.trigger('results:previous');
});
this.selection.on('results:next', function () {
self.trigger('results:next');
});
this.selection.on('unselected', function (params) {
self.trigger('unselect', params);
self.close();
});
this.results.on('selected', function (params) {
self.trigger('select', params);
self.close();
});
this.results.on('unselected', function (params) {
self.trigger('unselect', params);
self.close();
});
this.results.on('results:focus', function (params) {
self.trigger('results:focus', params);
});
this.on('open', function () {
$container.addClass('open');
});
this.on('close', function () {
$container.removeClass('open');
});
// Register any internal event handlers
this._registerSelectionEvents();
this._registerResultsEvents();
this._registerEvents();
// Set the initial state
@ -120,15 +67,6 @@ define([
});
});
this.on('query', function (params) {
this.data.query(params, function (data) {
self.trigger('results:all', {
data: data,
query: params
});
});
});
this.trigger('query', {});
// Hide the original select
@ -179,6 +117,97 @@ define([
$resultsContainer.append($results);
};
Select2.prototype._bindAdapters = function () {
this.data.bind(this, this.$container);
this.selection.bind(this, this.$container);
this.dropdown.bind(this, this.$container);
this.results.bind(this, this.$container);
};
Select2.prototype._registerDomEvents = function () {
var self = this;
this.$element.on('change', function () {
self.data.current(function (data) {
self.trigger('selection:update', {
data: data
});
});
});
};
Select2.prototype._registerSelectionEvents = function () {
var self = this;
this.selection.on('open', function () {
self.open();
});
this.selection.on('close', function () {
self.close();
});
this.selection.on('toggle', function () {
self.toggleDropdown();
});
this.selection.on('results:select', function () {
self.trigger('results:select');
});
this.selection.on('results:previous', function () {
self.trigger('results:previous');
});
this.selection.on('results:next', function () {
self.trigger('results:next');
});
this.selection.on('unselected', function (params) {
self.trigger('unselect', params);
self.close();
});
};
Select2.prototype._registerResultsEvents = function () {
var self = this;
this.results.on('selected', function (params) {
self.trigger('select', params);
self.close();
});
this.results.on('unselected', function (params) {
self.trigger('unselect', params);
self.close();
});
this.results.on('results:focus', function (params) {
self.trigger('results:focus', params);
});
};
Select2.prototype._registerEvents = function () {
var self = this;
this.on('open', function () {
self.$container.addClass('open');
});
this.on('close', function () {
self.$container.removeClass('open');
});
this.on('query', function (params) {
this.data.query(params, function (data) {
self.trigger('results:all', {
data: data,
query: params
});
});
});
};
Select2.prototype.toggleDropdown = function () {
if (this.isOpen()) {
this.close();