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

Side by Side 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 unified diff | Download patch
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 // <include src="assert.js"> 5 // <include src="assert.js">
6 6
7 /** 7 /**
8 * Alias for document.getElementById. Found elements must be HTMLElements. 8 * Alias for document.getElementById. Found elements must be HTMLElements.
9 * @param {string} id The ID of the element to find. 9 * @param {string} id The ID of the element to find.
10 * @return {HTMLElement} The found element or null if not found. 10 * @return {HTMLElement} The found element or null if not found.
(...skipping 355 matching lines...) Expand 10 before | Expand all | Expand 10 after
366 366
367 /** 367 /**
368 * Quote a string so it can be used in a regular expression. 368 * Quote a string so it can be used in a regular expression.
369 * @param {string} str The source string. 369 * @param {string} str The source string.
370 * @return {string} The escaped string. 370 * @return {string} The escaped string.
371 */ 371 */
372 function quoteString(str) { 372 function quoteString(str) {
373 return str.replace(/([\\\.\+\*\?\[\^\]\$\(\)\{\}\=\!\<\>\|\:])/g, '\\$1'); 373 return str.replace(/([\\\.\+\*\?\[\^\]\$\(\)\{\}\=\!\<\>\|\:])/g, '\\$1');
374 } 374 }
375 375
376 /**
377 * Returns a promise which is resolved when |eventName| is fired on |element|
378 * and |predicate| is true.
379 * @param {HTMLElement} element
380 * @param {string} eventName
381 * @param {function(Event): boolean} predicate
tsergeant 2016/08/05 01:39:09 @return {Promise}
calamity 2016/08/09 02:56:00 Done.
382 */
383 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.
384 if (!predicate)
385 predicate = function() { return true; };
386
387 return new Promise(function(resolve) {
388 var listener = function(e) {
389 if (!predicate(e))
390 return;
391
392 resolve();
393 element.removeEventListener(eventName, listener);
394 }
395
396 element.addEventListener(eventName, listener);
397 });
398 }
399
376 // <if expr="is_ios"> 400 // <if expr="is_ios">
377 // Polyfill 'key' in KeyboardEvent for iOS. 401 // Polyfill 'key' in KeyboardEvent for iOS.
378 // This function is not intended to be complete but should 402 // This function is not intended to be complete but should
379 // be sufficient enough to have iOS work correctly while 403 // be sufficient enough to have iOS work correctly while
380 // it does not support key yet. 404 // it does not support key yet.
381 if (!('key' in KeyboardEvent.prototype)) { 405 if (!('key' in KeyboardEvent.prototype)) {
382 Object.defineProperty(KeyboardEvent.prototype, 'key', { 406 Object.defineProperty(KeyboardEvent.prototype, 'key', {
383 /** @this {KeyboardEvent} */ 407 /** @this {KeyboardEvent} */
384 get: function () { 408 get: function () {
385 // 0-9 409 // 0-9
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
432 case 0xdb: return '['; 456 case 0xdb: return '[';
433 case 0xdd: return ']'; 457 case 0xdd: return ']';
434 } 458 }
435 return 'Unidentified'; 459 return 'Unidentified';
436 } 460 }
437 }); 461 });
438 } else { 462 } else {
439 window.console.log("KeyboardEvent.Key polyfill not required"); 463 window.console.log("KeyboardEvent.Key polyfill not required");
440 } 464 }
441 // </if> /* is_ios */ 465 // </if> /* is_ios */
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698