Use the star event for internal binding
The star event will allow us to relay any custom events as well as the ones used internally by Select2. This also makes it much easier to start triggering events in general, as we don't need to relay it in the core anymore. A module has been created for the jQuery-facing events, and the release announcement has been updated to mention the event name changes. This also adds some documentation about the public events.
This commit is contained in:
parent
68286e3cff
commit
bba967ba21
46
dist/js/select2.amd.full.js
vendored
46
dist/js/select2.amd.full.js
vendored
@ -3846,13 +3846,14 @@ define('select2/core',[
|
|||||||
Select2.prototype._registerDataEvents = function () {
|
Select2.prototype._registerDataEvents = function () {
|
||||||
var self = this;
|
var self = this;
|
||||||
|
|
||||||
this.data.on('results:message', function (params) {
|
this.data.on('*', function (name, params) {
|
||||||
self.trigger('results:message', params);
|
self.trigger(name, params);
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
Select2.prototype._registerSelectionEvents = function () {
|
Select2.prototype._registerSelectionEvents = function () {
|
||||||
var self = this;
|
var self = this;
|
||||||
|
var nonRelayEvents = ['open', 'close', 'toggle', 'unselected'];
|
||||||
|
|
||||||
this.selection.on('open', function () {
|
this.selection.on('open', function () {
|
||||||
self.open();
|
self.open();
|
||||||
@ -3864,49 +3865,32 @@ define('select2/core',[
|
|||||||
self.toggleDropdown();
|
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) {
|
this.selection.on('unselected', function (params) {
|
||||||
self.trigger('unselect', params);
|
self.trigger('unselect', params);
|
||||||
|
|
||||||
self.close();
|
self.close();
|
||||||
});
|
});
|
||||||
|
|
||||||
this.selection.on('query', function (params) {
|
this.selection.on('*', function (name, params) {
|
||||||
self.trigger('query', params);
|
if (nonRelayEvents.indexOf(name) !== -1) {
|
||||||
});
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
this.selection.on('keypress', function (e) {
|
self.trigger(name, params);
|
||||||
self.trigger('keypress', e);
|
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
Select2.prototype._registerDropdownEvents = function () {
|
Select2.prototype._registerDropdownEvents = function () {
|
||||||
var self = this;
|
var self = this;
|
||||||
|
|
||||||
this.dropdown.on('query', function (params) {
|
this.dropdown.on('*', function (name, params) {
|
||||||
self.trigger('query', params);
|
self.trigger(name, params);
|
||||||
});
|
|
||||||
|
|
||||||
this.dropdown.on('keypress', function (e) {
|
|
||||||
self.trigger('keypress', e);
|
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
Select2.prototype._registerResultsEvents = function () {
|
Select2.prototype._registerResultsEvents = function () {
|
||||||
var self = this;
|
var self = this;
|
||||||
|
var nonRelayEvents = ['selected', 'unselected'];
|
||||||
this.results.on('query:append', function (params) {
|
|
||||||
self.trigger('query:append', params);
|
|
||||||
});
|
|
||||||
|
|
||||||
this.results.on('selected', function (params) {
|
this.results.on('selected', function (params) {
|
||||||
self.trigger('select', params);
|
self.trigger('select', params);
|
||||||
@ -3920,8 +3904,12 @@ define('select2/core',[
|
|||||||
self.close();
|
self.close();
|
||||||
});
|
});
|
||||||
|
|
||||||
this.results.on('results:focus', function (params) {
|
this.results.on('*', function (name, params) {
|
||||||
self.trigger('results:focus', params);
|
if (nonRelayEvents.indexOf(name) !== -1) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
self.trigger(name, params);
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
|
46
dist/js/select2.amd.js
vendored
46
dist/js/select2.amd.js
vendored
@ -3846,13 +3846,14 @@ define('select2/core',[
|
|||||||
Select2.prototype._registerDataEvents = function () {
|
Select2.prototype._registerDataEvents = function () {
|
||||||
var self = this;
|
var self = this;
|
||||||
|
|
||||||
this.data.on('results:message', function (params) {
|
this.data.on('*', function (name, params) {
|
||||||
self.trigger('results:message', params);
|
self.trigger(name, params);
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
Select2.prototype._registerSelectionEvents = function () {
|
Select2.prototype._registerSelectionEvents = function () {
|
||||||
var self = this;
|
var self = this;
|
||||||
|
var nonRelayEvents = ['open', 'close', 'toggle', 'unselected'];
|
||||||
|
|
||||||
this.selection.on('open', function () {
|
this.selection.on('open', function () {
|
||||||
self.open();
|
self.open();
|
||||||
@ -3864,49 +3865,32 @@ define('select2/core',[
|
|||||||
self.toggleDropdown();
|
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) {
|
this.selection.on('unselected', function (params) {
|
||||||
self.trigger('unselect', params);
|
self.trigger('unselect', params);
|
||||||
|
|
||||||
self.close();
|
self.close();
|
||||||
});
|
});
|
||||||
|
|
||||||
this.selection.on('query', function (params) {
|
this.selection.on('*', function (name, params) {
|
||||||
self.trigger('query', params);
|
if (nonRelayEvents.indexOf(name) !== -1) {
|
||||||
});
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
this.selection.on('keypress', function (e) {
|
self.trigger(name, params);
|
||||||
self.trigger('keypress', e);
|
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
Select2.prototype._registerDropdownEvents = function () {
|
Select2.prototype._registerDropdownEvents = function () {
|
||||||
var self = this;
|
var self = this;
|
||||||
|
|
||||||
this.dropdown.on('query', function (params) {
|
this.dropdown.on('*', function (name, params) {
|
||||||
self.trigger('query', params);
|
self.trigger(name, params);
|
||||||
});
|
|
||||||
|
|
||||||
this.dropdown.on('keypress', function (e) {
|
|
||||||
self.trigger('keypress', e);
|
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
Select2.prototype._registerResultsEvents = function () {
|
Select2.prototype._registerResultsEvents = function () {
|
||||||
var self = this;
|
var self = this;
|
||||||
|
var nonRelayEvents = ['selected', 'unselected'];
|
||||||
this.results.on('query:append', function (params) {
|
|
||||||
self.trigger('query:append', params);
|
|
||||||
});
|
|
||||||
|
|
||||||
this.results.on('selected', function (params) {
|
this.results.on('selected', function (params) {
|
||||||
self.trigger('select', params);
|
self.trigger('select', params);
|
||||||
@ -3920,8 +3904,12 @@ define('select2/core',[
|
|||||||
self.close();
|
self.close();
|
||||||
});
|
});
|
||||||
|
|
||||||
this.results.on('results:focus', function (params) {
|
this.results.on('*', function (name, params) {
|
||||||
self.trigger('results:focus', params);
|
if (nonRelayEvents.indexOf(name) !== -1) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
self.trigger(name, params);
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
|
46
dist/js/select2.full.js
vendored
46
dist/js/select2.full.js
vendored
@ -13381,13 +13381,14 @@ define('select2/core',[
|
|||||||
Select2.prototype._registerDataEvents = function () {
|
Select2.prototype._registerDataEvents = function () {
|
||||||
var self = this;
|
var self = this;
|
||||||
|
|
||||||
this.data.on('results:message', function (params) {
|
this.data.on('*', function (name, params) {
|
||||||
self.trigger('results:message', params);
|
self.trigger(name, params);
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
Select2.prototype._registerSelectionEvents = function () {
|
Select2.prototype._registerSelectionEvents = function () {
|
||||||
var self = this;
|
var self = this;
|
||||||
|
var nonRelayEvents = ['open', 'close', 'toggle', 'unselected'];
|
||||||
|
|
||||||
this.selection.on('open', function () {
|
this.selection.on('open', function () {
|
||||||
self.open();
|
self.open();
|
||||||
@ -13399,49 +13400,32 @@ define('select2/core',[
|
|||||||
self.toggleDropdown();
|
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) {
|
this.selection.on('unselected', function (params) {
|
||||||
self.trigger('unselect', params);
|
self.trigger('unselect', params);
|
||||||
|
|
||||||
self.close();
|
self.close();
|
||||||
});
|
});
|
||||||
|
|
||||||
this.selection.on('query', function (params) {
|
this.selection.on('*', function (name, params) {
|
||||||
self.trigger('query', params);
|
if (nonRelayEvents.indexOf(name) !== -1) {
|
||||||
});
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
this.selection.on('keypress', function (e) {
|
self.trigger(name, params);
|
||||||
self.trigger('keypress', e);
|
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
Select2.prototype._registerDropdownEvents = function () {
|
Select2.prototype._registerDropdownEvents = function () {
|
||||||
var self = this;
|
var self = this;
|
||||||
|
|
||||||
this.dropdown.on('query', function (params) {
|
this.dropdown.on('*', function (name, params) {
|
||||||
self.trigger('query', params);
|
self.trigger(name, params);
|
||||||
});
|
|
||||||
|
|
||||||
this.dropdown.on('keypress', function (e) {
|
|
||||||
self.trigger('keypress', e);
|
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
Select2.prototype._registerResultsEvents = function () {
|
Select2.prototype._registerResultsEvents = function () {
|
||||||
var self = this;
|
var self = this;
|
||||||
|
var nonRelayEvents = ['selected', 'unselected'];
|
||||||
this.results.on('query:append', function (params) {
|
|
||||||
self.trigger('query:append', params);
|
|
||||||
});
|
|
||||||
|
|
||||||
this.results.on('selected', function (params) {
|
this.results.on('selected', function (params) {
|
||||||
self.trigger('select', params);
|
self.trigger('select', params);
|
||||||
@ -13455,8 +13439,12 @@ define('select2/core',[
|
|||||||
self.close();
|
self.close();
|
||||||
});
|
});
|
||||||
|
|
||||||
this.results.on('results:focus', function (params) {
|
this.results.on('*', function (name, params) {
|
||||||
self.trigger('results:focus', params);
|
if (nonRelayEvents.indexOf(name) !== -1) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
self.trigger(name, params);
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
|
2
dist/js/select2.full.min.js
vendored
2
dist/js/select2.full.min.js
vendored
File diff suppressed because one or more lines are too long
46
dist/js/select2.js
vendored
46
dist/js/select2.js
vendored
@ -4274,13 +4274,14 @@ define('select2/core',[
|
|||||||
Select2.prototype._registerDataEvents = function () {
|
Select2.prototype._registerDataEvents = function () {
|
||||||
var self = this;
|
var self = this;
|
||||||
|
|
||||||
this.data.on('results:message', function (params) {
|
this.data.on('*', function (name, params) {
|
||||||
self.trigger('results:message', params);
|
self.trigger(name, params);
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
Select2.prototype._registerSelectionEvents = function () {
|
Select2.prototype._registerSelectionEvents = function () {
|
||||||
var self = this;
|
var self = this;
|
||||||
|
var nonRelayEvents = ['open', 'close', 'toggle', 'unselected'];
|
||||||
|
|
||||||
this.selection.on('open', function () {
|
this.selection.on('open', function () {
|
||||||
self.open();
|
self.open();
|
||||||
@ -4292,49 +4293,32 @@ define('select2/core',[
|
|||||||
self.toggleDropdown();
|
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) {
|
this.selection.on('unselected', function (params) {
|
||||||
self.trigger('unselect', params);
|
self.trigger('unselect', params);
|
||||||
|
|
||||||
self.close();
|
self.close();
|
||||||
});
|
});
|
||||||
|
|
||||||
this.selection.on('query', function (params) {
|
this.selection.on('*', function (name, params) {
|
||||||
self.trigger('query', params);
|
if (nonRelayEvents.indexOf(name) !== -1) {
|
||||||
});
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
this.selection.on('keypress', function (e) {
|
self.trigger(name, params);
|
||||||
self.trigger('keypress', e);
|
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
Select2.prototype._registerDropdownEvents = function () {
|
Select2.prototype._registerDropdownEvents = function () {
|
||||||
var self = this;
|
var self = this;
|
||||||
|
|
||||||
this.dropdown.on('query', function (params) {
|
this.dropdown.on('*', function (name, params) {
|
||||||
self.trigger('query', params);
|
self.trigger(name, params);
|
||||||
});
|
|
||||||
|
|
||||||
this.dropdown.on('keypress', function (e) {
|
|
||||||
self.trigger('keypress', e);
|
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
Select2.prototype._registerResultsEvents = function () {
|
Select2.prototype._registerResultsEvents = function () {
|
||||||
var self = this;
|
var self = this;
|
||||||
|
var nonRelayEvents = ['selected', 'unselected'];
|
||||||
this.results.on('query:append', function (params) {
|
|
||||||
self.trigger('query:append', params);
|
|
||||||
});
|
|
||||||
|
|
||||||
this.results.on('selected', function (params) {
|
this.results.on('selected', function (params) {
|
||||||
self.trigger('select', params);
|
self.trigger('select', params);
|
||||||
@ -4348,8 +4332,12 @@ define('select2/core',[
|
|||||||
self.close();
|
self.close();
|
||||||
});
|
});
|
||||||
|
|
||||||
this.results.on('results:focus', function (params) {
|
this.results.on('*', function (name, params) {
|
||||||
self.trigger('results:focus', params);
|
if (nonRelayEvents.indexOf(name) !== -1) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
self.trigger(name, params);
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
|
2
dist/js/select2.min.js
vendored
2
dist/js/select2.min.js
vendored
File diff suppressed because one or more lines are too long
@ -647,7 +647,7 @@ $(".js-example-language").select2({
|
|||||||
<div class="col-md-8">
|
<div class="col-md-8">
|
||||||
<h2>Example code</h2>
|
<h2>Example code</h2>
|
||||||
|
|
||||||
<pre data-fill-from=".js-code-theme"></pre>
|
<pre data-fill-from=".js-code-rtl"></pre>
|
||||||
|
|
||||||
<script type="text/x-example-code" class="js-code-rtl">
|
<script type="text/x-example-code" class="js-code-rtl">
|
||||||
$(".js-example-rtl").select2({
|
$(".js-example-rtl").select2({
|
||||||
|
@ -622,6 +622,18 @@ ajax: {
|
|||||||
</p>
|
</p>
|
||||||
</section>
|
</section>
|
||||||
|
|
||||||
|
<section id="events">
|
||||||
|
<div class="page-header">
|
||||||
|
<h1>Events</h1>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<p>
|
||||||
|
Select2 has an internal event system that is used to notify parts of the
|
||||||
|
component that state has changed, as well as an adapter that allows some
|
||||||
|
of these events to be relayed to the outside word.
|
||||||
|
</p>
|
||||||
|
</section>
|
||||||
|
|
||||||
<section id="adapters">
|
<section id="adapters">
|
||||||
<div class="page-header">
|
<div class="page-header">
|
||||||
<h1>Adapters</h1>
|
<h1>Adapters</h1>
|
||||||
|
46
src/js/select2/core.js
vendored
46
src/js/select2/core.js
vendored
@ -150,13 +150,14 @@ define([
|
|||||||
Select2.prototype._registerDataEvents = function () {
|
Select2.prototype._registerDataEvents = function () {
|
||||||
var self = this;
|
var self = this;
|
||||||
|
|
||||||
this.data.on('results:message', function (params) {
|
this.data.on('*', function (name, params) {
|
||||||
self.trigger('results:message', params);
|
self.trigger(name, params);
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
Select2.prototype._registerSelectionEvents = function () {
|
Select2.prototype._registerSelectionEvents = function () {
|
||||||
var self = this;
|
var self = this;
|
||||||
|
var nonRelayEvents = ['open', 'close', 'toggle', 'unselected'];
|
||||||
|
|
||||||
this.selection.on('open', function () {
|
this.selection.on('open', function () {
|
||||||
self.open();
|
self.open();
|
||||||
@ -168,49 +169,32 @@ define([
|
|||||||
self.toggleDropdown();
|
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) {
|
this.selection.on('unselected', function (params) {
|
||||||
self.trigger('unselect', params);
|
self.trigger('unselect', params);
|
||||||
|
|
||||||
self.close();
|
self.close();
|
||||||
});
|
});
|
||||||
|
|
||||||
this.selection.on('query', function (params) {
|
this.selection.on('*', function (name, params) {
|
||||||
self.trigger('query', params);
|
if (nonRelayEvents.indexOf(name) !== -1) {
|
||||||
});
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
this.selection.on('keypress', function (e) {
|
self.trigger(name, params);
|
||||||
self.trigger('keypress', e);
|
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
Select2.prototype._registerDropdownEvents = function () {
|
Select2.prototype._registerDropdownEvents = function () {
|
||||||
var self = this;
|
var self = this;
|
||||||
|
|
||||||
this.dropdown.on('query', function (params) {
|
this.dropdown.on('*', function (name, params) {
|
||||||
self.trigger('query', params);
|
self.trigger(name, params);
|
||||||
});
|
|
||||||
|
|
||||||
this.dropdown.on('keypress', function (e) {
|
|
||||||
self.trigger('keypress', e);
|
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
Select2.prototype._registerResultsEvents = function () {
|
Select2.prototype._registerResultsEvents = function () {
|
||||||
var self = this;
|
var self = this;
|
||||||
|
var nonRelayEvents = ['selected', 'unselected'];
|
||||||
this.results.on('query:append', function (params) {
|
|
||||||
self.trigger('query:append', params);
|
|
||||||
});
|
|
||||||
|
|
||||||
this.results.on('selected', function (params) {
|
this.results.on('selected', function (params) {
|
||||||
self.trigger('select', params);
|
self.trigger('select', params);
|
||||||
@ -224,8 +208,12 @@ define([
|
|||||||
self.close();
|
self.close();
|
||||||
});
|
});
|
||||||
|
|
||||||
this.results.on('results:focus', function (params) {
|
this.results.on('*', function (name, params) {
|
||||||
self.trigger('results:focus', params);
|
if (nonRelayEvents.indexOf(name) !== -1) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
self.trigger(name, params);
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user