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

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

Issue 2207323002: [MD History] Factor out a common HistoryListBehavior. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: 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 293205804389a21425c26bc0c26756533d9e42ea..6caffd4b4027ba4965e28ead71e04e905545499b 100644
--- a/ui/webui/resources/js/util.js
+++ b/ui/webui/resources/js/util.js
@@ -373,6 +373,30 @@ function quoteString(str) {
return str.replace(/([\\\.\+\*\?\[\^\]\$\(\)\{\}\=\!\<\>\|\:])/g, '\\$1');
}
+/**
+ * Returns a promise which is resolved when |eventName| is fired on |element|
+ * and |predicate| is true.
+ * @param {HTMLElement} element
+ * @param {string} eventName
+ * @param {function(Event): boolean} predicate
tsergeant 2016/08/05 01:39:09 @return {Promise}
calamity 2016/08/09 02:56:00 Done.
+ */
+function waitForEvent(element, eventName, predicate) {
tsergeant 2016/08/05 01:39:09 I can conceive of situations where this would be u
calamity 2016/08/09 02:56:00 Done.
+ if (!predicate)
+ predicate = function() { return true; };
+
+ return new Promise(function(resolve) {
+ var listener = function(e) {
+ if (!predicate(e))
+ return;
+
+ resolve();
+ element.removeEventListener(eventName, listener);
+ }
+
+ element.addEventListener(eventName, listener);
+ });
+}
+
// <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