Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(35)

Unified Diff: ui/webui/resources/js/util.js

Issue 2300753004: MD Settings menu should be visible (Closed)
Patch Set: cleanup Created 4 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: ui/webui/resources/js/util.js
diff --git a/ui/webui/resources/js/util.js b/ui/webui/resources/js/util.js
index 759bfbbf308ac232374ffec3e12436f68882fbee..f94f8ec833c4a86868b10ae1ae78bce9718c5b86 100644
--- a/ui/webui/resources/js/util.js
+++ b/ui/webui/resources/js/util.js
@@ -393,6 +393,21 @@ function quoteString(str) {
return str.replace(/([\\\.\+\*\?\[\^\]\$\(\)\{\}\=\!\<\>\|\:])/g, '\\$1');
}
+/**
+ * Runs |callback| first time the |eventName| event is fired on |target|, then
+ * removes the listener.
+ * @param {!EventTarget} target
+ * @param {string} eventName
Dan Beam 2016/09/01 01:33:13 nit: maybe support multiple events? ... Callback
michaelpg 2016/09/01 02:20:26 Done. I had briefly considered this but thought it
+ * @param {function(!Event)} callback Called at most once. The
+ * optional return value is passed on by the listener.
+ */
+function listenOnce(target, eventName, callback) {
+ target.addEventListener(eventName, function runOnce(event) {
michaelpg 2016/09/01 01:00:27 dbeam: your example returned a Promise, but this w
+ target.removeEventListener(eventName, runOnce, false);
michaelpg 2016/09/01 01:00:27 apparently closure requires this 3rd argument for
+ return callback(event);
+ }, false);
Dan Beam 2016/09/01 01:33:13 we'll probably need some type @param {boolean=} op
michaelpg 2016/09/01 02:20:27 Acknowledged (does anyone actually use that? I've
+}
+
// <if expr="is_ios">
// Polyfill 'key' in KeyboardEvent for iOS.
// This function is not intended to be complete but should

Powered by Google App Engine
This is Rietveld 408576698