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

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

Issue 2300753004: MD Settings menu should be visible (Closed)
Patch Set: closure Created 4 years, 3 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
« no previous file with comments | « chrome/test/data/webui/settings/settings_ui_browsertest.js ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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..d2820815f74dd5763ef91bc2e16dce96622fd74c 100644
--- a/ui/webui/resources/js/util.js
+++ b/ui/webui/resources/js/util.js
@@ -393,6 +393,31 @@ function quoteString(str) {
return str.replace(/([\\\.\+\*\?\[\^\]\$\(\)\{\}\=\!\<\>\|\:])/g, '\\$1');
}
+/**
+ * Calls |callback| and stops listening the first time any event in |eventNames|
+ * is triggered on |target|.
+ * @param {!EventTarget} target
+ * @param {!Array<string>|string} eventNames Array or space-delimited string of
+ * event names to listen to (e.g. 'click mousedown').
+ * @param {function(!Event)} callback Called at most once. The
+ * optional return value is passed on by the listener.
+ */
+function listenOnce(target, eventNames, callback) {
+ if (!Array.isArray(eventNames))
+ eventNames = eventNames.split(/ +/);
+
+ var removeAllAndCallCallback = function(event) {
+ eventNames.forEach(function(eventName) {
+ target.removeEventListener(eventName, removeAllAndCallCallback, false);
+ });
+ return callback(event);
+ };
+
+ eventNames.forEach(function(eventName) {
+ target.addEventListener(eventName, removeAllAndCallCallback, false);
+ });
+}
+
// <if expr="is_ios">
// Polyfill 'key' in KeyboardEvent for iOS.
// This function is not intended to be complete but should
« no previous file with comments | « chrome/test/data/webui/settings/settings_ui_browsertest.js ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698