From ad8447cc3560a61bb0f135c52edac770ede361bb Mon Sep 17 00:00:00 2001 From: Kevin Brown Date: Sat, 14 May 2016 22:01:42 -0400 Subject: [PATCH] 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. --- src/js/select2/utils.js | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/src/js/select2/utils.js b/src/js/select2/utils.js index 7bb962dc..d1a23d29 100644 --- a/src/js/select2/utils.js +++ b/src/js/select2/utils.js @@ -124,9 +124,23 @@ define([ Observable.prototype.trigger = function (event) { var slice = Array.prototype.slice; + var params = slice.call(arguments, 1); this.listeners = this.listeners || {}; + // Params should always come in as an array + if (params == null) { + params = []; + } + + // If there are no arguments to the event, use a temporary object + if (params.length === 0) { + params.push({}); + } + + // Set the `_type` of the first object to the event + params[0]._type = event; + if (event in this.listeners) { this.invoke(this.listeners[event], slice.call(arguments, 1)); }