From c32947c029c5cd5c1b7489cb16723a9fa7a54365 Mon Sep 17 00:00:00 2001 From: Michael Jumper Date: Wed, 26 May 2021 19:36:01 -0700 Subject: [PATCH] GUACAMOLE-1204: Allow the events given to Guacamole.Event.DOMEvent to be a single event or omitted entirely. --- .../src/main/webapp/modules/Event.js | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) diff --git a/guacamole-common-js/src/main/webapp/modules/Event.js b/guacamole-common-js/src/main/webapp/modules/Event.js index d94a11e78..073363754 100644 --- a/guacamole-common-js/src/main/webapp/modules/Event.js +++ b/guacamole-common-js/src/main/webapp/modules/Event.js @@ -79,10 +79,10 @@ Guacamole.Event = function Event(type) { }; /** - * A {@link Guacamole.Event} that relates to one or more DOM events. Continued - * propagation and default behavior of the related DOM events may be prevented - * with {@link Guacamole.Event.DOMEvent#stopPropagation stopPropagation()} and - * {@link Guacamole.Event.DOMEvent#preventDefault preventDefault()} + * A {@link Guacamole.Event} that may relate to one or more DOM events. + * Continued propagation and default behavior of the related DOM events may be + * prevented with {@link Guacamole.Event.DOMEvent#stopPropagation stopPropagation()} + * and {@link Guacamole.Event.DOMEvent#preventDefault preventDefault()} * respectively. * * @constructor @@ -91,8 +91,8 @@ Guacamole.Event = function Event(type) { * @param {String} type * The unique name of this event type. * - * @param {Event[]} events - * The DOM events that are related to this event. Future calls to + * @param {Event|Event[]} [events=[]] + * The DOM events that are related to this event, if any. Future calls to * {@link Guacamole.Event.DOMEvent#preventDefault preventDefault()} and * {@link Guacamole.Event.DOMEvent#stopPropagation stopPropagation()} will * affect these events. @@ -101,6 +101,13 @@ Guacamole.Event.DOMEvent = function DOMEvent(type, events) { Guacamole.Event.call(this, type); + // Default to empty array + events = events || []; + + // Automatically wrap non-array single Event in an array + if (!Array.isArray(events)) + events = [ events ]; + /** * Requests that the default behavior of related DOM events be prevented. * Whether this request will be honored by the browser depends on the