GUACAMOLE-1204: Allow the events given to Guacamole.Event.DOMEvent to be a single event or omitted entirely.

This commit is contained in:
Michael Jumper
2021-05-26 19:36:01 -07:00
parent 739fbbbf2e
commit c32947c029

View File

@@ -79,10 +79,10 @@ Guacamole.Event = function Event(type) {
}; };
/** /**
* A {@link Guacamole.Event} that relates to one or more DOM events. Continued * A {@link Guacamole.Event} that may relate to one or more DOM events.
* propagation and default behavior of the related DOM events may be prevented * Continued propagation and default behavior of the related DOM events may be
* with {@link Guacamole.Event.DOMEvent#stopPropagation stopPropagation()} and * prevented with {@link Guacamole.Event.DOMEvent#stopPropagation stopPropagation()}
* {@link Guacamole.Event.DOMEvent#preventDefault preventDefault()} * and {@link Guacamole.Event.DOMEvent#preventDefault preventDefault()}
* respectively. * respectively.
* *
* @constructor * @constructor
@@ -91,8 +91,8 @@ Guacamole.Event = function Event(type) {
* @param {String} type * @param {String} type
* The unique name of this event type. * The unique name of this event type.
* *
* @param {Event[]} events * @param {Event|Event[]} [events=[]]
* The DOM events that are related to this event. Future calls to * 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#preventDefault preventDefault()} and
* {@link Guacamole.Event.DOMEvent#stopPropagation stopPropagation()} will * {@link Guacamole.Event.DOMEvent#stopPropagation stopPropagation()} will
* affect these events. * affect these events.
@@ -101,6 +101,13 @@ Guacamole.Event.DOMEvent = function DOMEvent(type, events) {
Guacamole.Event.call(this, type); 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. * Requests that the default behavior of related DOM events be prevented.
* Whether this request will be honored by the browser depends on the * Whether this request will be honored by the browser depends on the