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 () {
|
||||
var self = this;
|
||||
|
||||
this.data.on('results:message', function (params) {
|
||||
self.trigger('results:message', params);
|
||||
this.data.on('*', function (name, params) {
|
||||
self.trigger(name, params);
|
||||
});
|
||||
};
|
||||
|
||||
Select2.prototype._registerSelectionEvents = function () {
|
||||
var self = this;
|
||||
var nonRelayEvents = ['open', 'close', 'toggle', 'unselected'];
|
||||
|
||||
this.selection.on('open', function () {
|
||||
self.open();
|
||||
@ -3864,49 +3865,32 @@ define('select2/core',[
|
||||
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.selection.on('query', function (params) {
|
||||
self.trigger('query', params);
|
||||
});
|
||||
this.selection.on('*', function (name, params) {
|
||||
if (nonRelayEvents.indexOf(name) !== -1) {
|
||||
return;
|
||||
}
|
||||
|
||||
this.selection.on('keypress', function (e) {
|
||||
self.trigger('keypress', e);
|
||||
self.trigger(name, params);
|
||||
});
|
||||
};
|
||||
|
||||
Select2.prototype._registerDropdownEvents = function () {
|
||||
var self = this;
|
||||
|
||||
this.dropdown.on('query', function (params) {
|
||||
self.trigger('query', params);
|
||||
});
|
||||
|
||||
this.dropdown.on('keypress', function (e) {
|
||||
self.trigger('keypress', e);
|
||||
this.dropdown.on('*', function (name, params) {
|
||||
self.trigger(name, params);
|
||||
});
|
||||
};
|
||||
|
||||
Select2.prototype._registerResultsEvents = function () {
|
||||
var self = this;
|
||||
|
||||
this.results.on('query:append', function (params) {
|
||||
self.trigger('query:append', params);
|
||||
});
|
||||
var nonRelayEvents = ['selected', 'unselected'];
|
||||
|
||||
this.results.on('selected', function (params) {
|
||||
self.trigger('select', params);
|
||||
@ -3920,8 +3904,12 @@ define('select2/core',[
|
||||
self.close();
|
||||
});
|
||||
|
||||
this.results.on('results:focus', function (params) {
|
||||
self.trigger('results:focus', params);
|
||||
this.results.on('*', function (name, 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 () {
|
||||
var self = this;
|
||||
|
||||
this.data.on('results:message', function (params) {
|
||||
self.trigger('results:message', params);
|
||||
this.data.on('*', function (name, params) {
|
||||
self.trigger(name, params);
|
||||
});
|
||||
};
|
||||
|
||||
Select2.prototype._registerSelectionEvents = function () {
|
||||
var self = this;
|
||||
var nonRelayEvents = ['open', 'close', 'toggle', 'unselected'];
|
||||
|
||||
this.selection.on('open', function () {
|
||||
self.open();
|
||||
@ -3864,49 +3865,32 @@ define('select2/core',[
|
||||
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.selection.on('query', function (params) {
|
||||
self.trigger('query', params);
|
||||
});
|
||||
this.selection.on('*', function (name, params) {
|
||||
if (nonRelayEvents.indexOf(name) !== -1) {
|
||||
return;
|
||||
}
|
||||
|
||||
this.selection.on('keypress', function (e) {
|
||||
self.trigger('keypress', e);
|
||||
self.trigger(name, params);
|
||||
});
|
||||
};
|
||||
|
||||
Select2.prototype._registerDropdownEvents = function () {
|
||||
var self = this;
|
||||
|
||||
this.dropdown.on('query', function (params) {
|
||||
self.trigger('query', params);
|
||||
});
|
||||
|
||||
this.dropdown.on('keypress', function (e) {
|
||||
self.trigger('keypress', e);
|
||||
this.dropdown.on('*', function (name, params) {
|
||||
self.trigger(name, params);
|
||||
});
|
||||
};
|
||||
|
||||
Select2.prototype._registerResultsEvents = function () {
|
||||
var self = this;
|
||||
|
||||
this.results.on('query:append', function (params) {
|
||||
self.trigger('query:append', params);
|
||||
});
|
||||
var nonRelayEvents = ['selected', 'unselected'];
|
||||
|
||||
this.results.on('selected', function (params) {
|
||||
self.trigger('select', params);
|
||||
@ -3920,8 +3904,12 @@ define('select2/core',[
|
||||
self.close();
|
||||
});
|
||||
|
||||
this.results.on('results:focus', function (params) {
|
||||
self.trigger('results:focus', params);
|
||||
this.results.on('*', function (name, 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 () {
|
||||
var self = this;
|
||||
|
||||
this.data.on('results:message', function (params) {
|
||||
self.trigger('results:message', params);
|
||||
this.data.on('*', function (name, params) {
|
||||
self.trigger(name, params);
|
||||
});
|
||||
};
|
||||
|
||||
Select2.prototype._registerSelectionEvents = function () {
|
||||
var self = this;
|
||||
var nonRelayEvents = ['open', 'close', 'toggle', 'unselected'];
|
||||
|
||||
this.selection.on('open', function () {
|
||||
self.open();
|
||||
@ -13399,49 +13400,32 @@ define('select2/core',[
|
||||
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.selection.on('query', function (params) {
|
||||
self.trigger('query', params);
|
||||
});
|
||||
this.selection.on('*', function (name, params) {
|
||||
if (nonRelayEvents.indexOf(name) !== -1) {
|
||||
return;
|
||||
}
|
||||
|
||||
this.selection.on('keypress', function (e) {
|
||||
self.trigger('keypress', e);
|
||||
self.trigger(name, params);
|
||||
});
|
||||
};
|
||||
|
||||
Select2.prototype._registerDropdownEvents = function () {
|
||||
var self = this;
|
||||
|
||||
this.dropdown.on('query', function (params) {
|
||||
self.trigger('query', params);
|
||||
});
|
||||
|
||||
this.dropdown.on('keypress', function (e) {
|
||||
self.trigger('keypress', e);
|
||||
this.dropdown.on('*', function (name, params) {
|
||||
self.trigger(name, params);
|
||||
});
|
||||
};
|
||||
|
||||
Select2.prototype._registerResultsEvents = function () {
|
||||
var self = this;
|
||||
|
||||
this.results.on('query:append', function (params) {
|
||||
self.trigger('query:append', params);
|
||||
});
|
||||
var nonRelayEvents = ['selected', 'unselected'];
|
||||
|
||||
this.results.on('selected', function (params) {
|
||||
self.trigger('select', params);
|
||||
@ -13455,8 +13439,12 @@ define('select2/core',[
|
||||
self.close();
|
||||
});
|
||||
|
||||
this.results.on('results:focus', function (params) {
|
||||
self.trigger('results:focus', params);
|
||||
this.results.on('*', function (name, 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 () {
|
||||
var self = this;
|
||||
|
||||
this.data.on('results:message', function (params) {
|
||||
self.trigger('results:message', params);
|
||||
this.data.on('*', function (name, params) {
|
||||
self.trigger(name, params);
|
||||
});
|
||||
};
|
||||
|
||||
Select2.prototype._registerSelectionEvents = function () {
|
||||
var self = this;
|
||||
var nonRelayEvents = ['open', 'close', 'toggle', 'unselected'];
|
||||
|
||||
this.selection.on('open', function () {
|
||||
self.open();
|
||||
@ -4292,49 +4293,32 @@ define('select2/core',[
|
||||
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.selection.on('query', function (params) {
|
||||
self.trigger('query', params);
|
||||
});
|
||||
this.selection.on('*', function (name, params) {
|
||||
if (nonRelayEvents.indexOf(name) !== -1) {
|
||||
return;
|
||||
}
|
||||
|
||||
this.selection.on('keypress', function (e) {
|
||||
self.trigger('keypress', e);
|
||||
self.trigger(name, params);
|
||||
});
|
||||
};
|
||||
|
||||
Select2.prototype._registerDropdownEvents = function () {
|
||||
var self = this;
|
||||
|
||||
this.dropdown.on('query', function (params) {
|
||||
self.trigger('query', params);
|
||||
});
|
||||
|
||||
this.dropdown.on('keypress', function (e) {
|
||||
self.trigger('keypress', e);
|
||||
this.dropdown.on('*', function (name, params) {
|
||||
self.trigger(name, params);
|
||||
});
|
||||
};
|
||||
|
||||
Select2.prototype._registerResultsEvents = function () {
|
||||
var self = this;
|
||||
|
||||
this.results.on('query:append', function (params) {
|
||||
self.trigger('query:append', params);
|
||||
});
|
||||
var nonRelayEvents = ['selected', 'unselected'];
|
||||
|
||||
this.results.on('selected', function (params) {
|
||||
self.trigger('select', params);
|
||||
@ -4348,8 +4332,12 @@ define('select2/core',[
|
||||
self.close();
|
||||
});
|
||||
|
||||
this.results.on('results:focus', function (params) {
|
||||
self.trigger('results:focus', params);
|
||||
this.results.on('*', function (name, 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
@ -615,15 +615,15 @@ $(".js-example-language").select2({
|
||||
|
||||
<pre data-fill-from=".js-code-theme"></pre>
|
||||
|
||||
<script type="text/x-example-code" class="js-code-theme">
|
||||
$(".js-example-theme-single").select2({
|
||||
theme: "classic"
|
||||
});
|
||||
<script type="text/x-example-code" class="js-code-theme">
|
||||
$(".js-example-theme-single").select2({
|
||||
theme: "classic"
|
||||
});
|
||||
|
||||
$(".js-example-theme-multiple").select2({
|
||||
theme: "classic"
|
||||
});
|
||||
</script>
|
||||
$(".js-example-theme-multiple").select2({
|
||||
theme: "classic"
|
||||
});
|
||||
</script>
|
||||
</div>
|
||||
</section>
|
||||
|
||||
@ -647,13 +647,13 @@ $(".js-example-language").select2({
|
||||
<div class="col-md-8">
|
||||
<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">
|
||||
$(".js-example-rtl").select2({
|
||||
dir: "rtl"
|
||||
});
|
||||
</script>
|
||||
<script type="text/x-example-code" class="js-code-rtl">
|
||||
$(".js-example-rtl").select2({
|
||||
dir: "rtl"
|
||||
});
|
||||
</script>
|
||||
</div>
|
||||
</section>
|
||||
</div>
|
||||
|
@ -622,6 +622,18 @@ ajax: {
|
||||
</p>
|
||||
</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">
|
||||
<div class="page-header">
|
||||
<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 () {
|
||||
var self = this;
|
||||
|
||||
this.data.on('results:message', function (params) {
|
||||
self.trigger('results:message', params);
|
||||
this.data.on('*', function (name, params) {
|
||||
self.trigger(name, params);
|
||||
});
|
||||
};
|
||||
|
||||
Select2.prototype._registerSelectionEvents = function () {
|
||||
var self = this;
|
||||
var nonRelayEvents = ['open', 'close', 'toggle', 'unselected'];
|
||||
|
||||
this.selection.on('open', function () {
|
||||
self.open();
|
||||
@ -168,49 +169,32 @@ define([
|
||||
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.selection.on('query', function (params) {
|
||||
self.trigger('query', params);
|
||||
});
|
||||
this.selection.on('*', function (name, params) {
|
||||
if (nonRelayEvents.indexOf(name) !== -1) {
|
||||
return;
|
||||
}
|
||||
|
||||
this.selection.on('keypress', function (e) {
|
||||
self.trigger('keypress', e);
|
||||
self.trigger(name, params);
|
||||
});
|
||||
};
|
||||
|
||||
Select2.prototype._registerDropdownEvents = function () {
|
||||
var self = this;
|
||||
|
||||
this.dropdown.on('query', function (params) {
|
||||
self.trigger('query', params);
|
||||
});
|
||||
|
||||
this.dropdown.on('keypress', function (e) {
|
||||
self.trigger('keypress', e);
|
||||
this.dropdown.on('*', function (name, params) {
|
||||
self.trigger(name, params);
|
||||
});
|
||||
};
|
||||
|
||||
Select2.prototype._registerResultsEvents = function () {
|
||||
var self = this;
|
||||
|
||||
this.results.on('query:append', function (params) {
|
||||
self.trigger('query:append', params);
|
||||
});
|
||||
var nonRelayEvents = ['selected', 'unselected'];
|
||||
|
||||
this.results.on('selected', function (params) {
|
||||
self.trigger('select', params);
|
||||
@ -224,8 +208,12 @@ define([
|
||||
self.close();
|
||||
});
|
||||
|
||||
this.results.on('results:focus', function (params) {
|
||||
self.trigger('results:focus', params);
|
||||
this.results.on('*', function (name, params) {
|
||||
if (nonRelayEvents.indexOf(name) !== -1) {
|
||||
return;
|
||||
}
|
||||
|
||||
self.trigger(name, params);
|
||||
});
|
||||
};
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user