summaryrefslogtreecommitdiff
path: root/assets/viz/2/goog/events/events.js
diff options
context:
space:
mode:
Diffstat (limited to 'assets/viz/2/goog/events/events.js')
-rw-r--r--assets/viz/2/goog/events/events.js80
1 files changed, 47 insertions, 33 deletions
diff --git a/assets/viz/2/goog/events/events.js b/assets/viz/2/goog/events/events.js
index 6a0acf7..2787340 100644
--- a/assets/viz/2/goog/events/events.js
+++ b/assets/viz/2/goog/events/events.js
@@ -160,30 +160,34 @@ goog.events.listenerCountEstimate_ = 0;
* @param {function(this:T, EVENTOBJ):?|{handleEvent:function(?):?}|null}
* listener Callback method, or an object with a handleEvent function.
* WARNING: passing an Object is now softly deprecated.
- * @param {boolean=} opt_capt Whether to fire in capture phase (defaults to
- * false).
+ * @param {(boolean|!AddEventListenerOptions)=} opt_options
* @param {T=} opt_handler Element in whose scope to call the listener.
* @return {goog.events.Key} Unique key for the listener.
* @template T,EVENTOBJ
*/
-goog.events.listen = function(src, type, listener, opt_capt, opt_handler) {
+goog.events.listen = function(src, type, listener, opt_options, opt_handler) {
+ if (opt_options && opt_options.once) {
+ return goog.events.listenOnce(
+ src, type, listener, opt_options, opt_handler);
+ }
if (goog.isArray(type)) {
for (var i = 0; i < type.length; i++) {
- goog.events.listen(src, type[i], listener, opt_capt, opt_handler);
+ goog.events.listen(src, type[i], listener, opt_options, opt_handler);
}
return null;
}
listener = goog.events.wrapListener(listener);
if (goog.events.Listenable.isImplementedBy(src)) {
+ var capture =
+ goog.isObject(opt_options) ? !!opt_options.capture : !!opt_options;
return src.listen(
- /** @type {string|!goog.events.EventId} */ (type), listener, opt_capt,
+ /** @type {string|!goog.events.EventId} */ (type), listener, capture,
opt_handler);
} else {
return goog.events.listen_(
- /** @type {!EventTarget} */ (src),
- /** @type {string|!goog.events.EventId} */ (type), listener,
- /* callOnce */ false, opt_capt, opt_handler);
+ /** @type {!EventTarget} */ (src), type, listener,
+ /* callOnce */ false, opt_options, opt_handler);
}
};
@@ -198,23 +202,24 @@ goog.events.listen = function(src, type, listener, opt_capt, opt_handler) {
* one-off listener to become a normal listener.
*
* @param {EventTarget} src The node to listen to events on.
- * @param {string|!goog.events.EventId} type Event type.
+ * @param {string|?goog.events.EventId<EVENTOBJ>} type Event type.
* @param {!Function} listener Callback function.
* @param {boolean} callOnce Whether the listener is a one-off
* listener or otherwise.
- * @param {boolean=} opt_capt Whether to fire in capture phase (defaults to
- * false).
+ * @param {(boolean|!AddEventListenerOptions)=} opt_options
* @param {Object=} opt_handler Element in whose scope to call the listener.
* @return {goog.events.ListenableKey} Unique key for the listener.
+ * @template EVENTOBJ
* @private
*/
goog.events.listen_ = function(
- src, type, listener, callOnce, opt_capt, opt_handler) {
+ src, type, listener, callOnce, opt_options, opt_handler) {
if (!type) {
throw Error('Invalid event type');
}
- var capture = !!opt_capt;
+ var capture =
+ goog.isObject(opt_options) ? !!opt_options.capture : !!opt_options;
if (capture && !goog.events.BrowserFeature.HAS_W3C_EVENT_SUPPORT) {
if (goog.events.CAPTURE_SIMULATION_MODE ==
goog.events.CaptureSimulationMode.OFF_AND_FAIL) {
@@ -233,8 +238,8 @@ goog.events.listen_ = function(
new goog.events.ListenerMap(src);
}
- var listenerObj =
- listenerMap.add(type, listener, callOnce, opt_capt, opt_handler);
+ var listenerObj = /** @type {goog.events.Listener} */ (
+ listenerMap.add(type, listener, callOnce, capture, opt_handler));
// If the listenerObj already has a proxy, it has been set up
// previously. We simply return.
@@ -250,7 +255,13 @@ goog.events.listen_ = function(
// Attach the proxy through the browser's API
if (src.addEventListener) {
- src.addEventListener(type.toString(), proxy, capture);
+ // Don't pass an object as `capture` if the browser doesn't support that.
+ if (!goog.events.BrowserFeature.PASSIVE_EVENTS) {
+ opt_options = capture;
+ }
+ // Don't break tests that expect a boolean.
+ if (opt_options === undefined) opt_options = false;
+ src.addEventListener(type.toString(), proxy, opt_options);
} else if (src.attachEvent) {
// The else if above used to be an unconditional else. It would call
// exception on IE11, spoiling the day of some callers. The previous
@@ -310,29 +321,31 @@ goog.events.getProxy = function() {
* type Event type or array of event types.
* @param {function(this:T, EVENTOBJ):?|{handleEvent:function(?):?}|null}
* listener Callback method.
- * @param {boolean=} opt_capt Fire in capture phase?.
+ * @param {(boolean|!AddEventListenerOptions)=} opt_options
* @param {T=} opt_handler Element in whose scope to call the listener.
* @return {goog.events.Key} Unique key for the listener.
* @template T,EVENTOBJ
*/
-goog.events.listenOnce = function(src, type, listener, opt_capt, opt_handler) {
+goog.events.listenOnce = function(
+ src, type, listener, opt_options, opt_handler) {
if (goog.isArray(type)) {
for (var i = 0; i < type.length; i++) {
- goog.events.listenOnce(src, type[i], listener, opt_capt, opt_handler);
+ goog.events.listenOnce(src, type[i], listener, opt_options, opt_handler);
}
return null;
}
listener = goog.events.wrapListener(listener);
if (goog.events.Listenable.isImplementedBy(src)) {
+ var capture =
+ goog.isObject(opt_options) ? !!opt_options.capture : !!opt_options;
return src.listenOnce(
- /** @type {string|!goog.events.EventId} */ (type), listener, opt_capt,
+ /** @type {string|!goog.events.EventId} */ (type), listener, capture,
opt_handler);
} else {
return goog.events.listen_(
- /** @type {!EventTarget} */ (src),
- /** @type {string|!goog.events.EventId} */ (type), listener,
- /* callOnce */ true, opt_capt, opt_handler);
+ /** @type {!EventTarget} */ (src), type, listener,
+ /* callOnce */ true, opt_options, opt_handler);
}
};
@@ -368,25 +381,27 @@ goog.events.listenWithWrapper = function(
* type Event type or array of event types to unlisten to.
* @param {function(?):?|{handleEvent:function(?):?}|null} listener The
* listener function to remove.
- * @param {boolean=} opt_capt In DOM-compliant browsers, this determines
+ * @param {(boolean|!EventListenerOptions)=} opt_options
* whether the listener is fired during the capture or bubble phase of the
* event.
* @param {Object=} opt_handler Element in whose scope to call the listener.
* @return {?boolean} indicating whether the listener was there to remove.
* @template EVENTOBJ
*/
-goog.events.unlisten = function(src, type, listener, opt_capt, opt_handler) {
+goog.events.unlisten = function(src, type, listener, opt_options, opt_handler) {
if (goog.isArray(type)) {
for (var i = 0; i < type.length; i++) {
- goog.events.unlisten(src, type[i], listener, opt_capt, opt_handler);
+ goog.events.unlisten(src, type[i], listener, opt_options, opt_handler);
}
return null;
}
+ var capture =
+ goog.isObject(opt_options) ? !!opt_options.capture : !!opt_options;
listener = goog.events.wrapListener(listener);
if (goog.events.Listenable.isImplementedBy(src)) {
return src.unlisten(
- /** @type {string|!goog.events.EventId} */ (type), listener, opt_capt,
+ /** @type {string|!goog.events.EventId} */ (type), listener, capture,
opt_handler);
}
@@ -396,7 +411,6 @@ goog.events.unlisten = function(src, type, listener, opt_capt, opt_handler) {
return false;
}
- var capture = !!opt_capt;
var listenerMap = goog.events.getListenerMap_(
/** @type {!EventTarget} */ (src));
if (listenerMap) {
@@ -461,7 +475,7 @@ goog.events.unlistenByKey = function(key) {
src[goog.events.LISTENER_MAP_PROP_] = null;
}
} else {
- listener.markAsRemoved();
+ /** @type {!goog.events.Listener} */ (listener).markAsRemoved();
}
return true;
@@ -718,7 +732,7 @@ goog.events.fireListeners_ = function(obj, type, capture, eventObject) {
*
* @param {goog.events.Listener} listener The listener object to call.
* @param {Object} eventObject The event object to pass to the listener.
- * @return {boolean} Result of listener.
+ * @return {*} Result of listener.
*/
goog.events.fireListener = function(listener, eventObject) {
var listenerFn = listener.listener;
@@ -789,7 +803,7 @@ goog.events.protectBrowserEventEntryPoint = function(errorHandler) {
* @param {goog.events.Listener} listener The listener object.
* @param {Event=} opt_evt Optional event object that gets passed in via the
* native event handlers.
- * @return {boolean} Result of the event handler.
+ * @return {*} Result of the event handler.
* @this {EventTarget} The object or Element that fired the event.
* @private
*/
@@ -804,7 +818,7 @@ goog.events.handleBrowserEvent_ = function(listener, opt_evt) {
var ieEvent = opt_evt ||
/** @type {Event} */ (goog.getObjectByName('window.event'));
var evt = new goog.events.BrowserEvent(ieEvent, this);
- /** @type {boolean} */
+ /** @type {*} */
var retval = true;
if (goog.events.CAPTURE_SIMULATION_MODE ==
@@ -880,7 +894,7 @@ goog.events.markIeEvent_ = function(e) {
// We could test that that is the case but that would allocate 3 objects.
// If we use try/catch we will only allocate extra objects in the case of a
// failure.
- /** @preserveTry */
+
try {
e.keyCode = -1;
return;