Skip to content

Commit ad8447c

Browse files
committed
Add a new _type parameter for the first event argument
This will include the event type in the _type property, so it can be accessed within the event handlers if it's not normally passed in. This should not conflict with any existing handlers, and this should not be considered a public property on event arguments.
1 parent acd3306 commit ad8447c

1 file changed

Lines changed: 14 additions & 0 deletions

File tree

src/js/select2/utils.js

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -124,9 +124,23 @@ define([
124124

125125
Observable.prototype.trigger = function (event) {
126126
var slice = Array.prototype.slice;
127+
var params = slice.call(arguments, 1);
127128

128129
this.listeners = this.listeners || {};
129130

131+
// Params should always come in as an array
132+
if (params == null) {
133+
params = [];
134+
}
135+
136+
// If there are no arguments to the event, use a temporary object
137+
if (params.length === 0) {
138+
params.push({});
139+
}
140+
141+
// Set the `_type` of the first object to the event
142+
params[0]._type = event;
143+
130144
if (event in this.listeners) {
131145
this.invoke(this.listeners[event], slice.call(arguments, 1));
132146
}

0 commit comments

Comments
 (0)