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

Side by Side Diff: ui/webui/resources/js/util.js

Issue 2300753004: MD Settings menu should be visible (Closed)
Patch Set: feedback 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 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 375 matching lines...) Expand 10 before | Expand all | Expand 10 after
386 386
387 /** 387 /**
388 * Quote a string so it can be used in a regular expression. 388 * Quote a string so it can be used in a regular expression.
389 * @param {string} str The source string. 389 * @param {string} str The source string.
390 * @return {string} The escaped string. 390 * @return {string} The escaped string.
391 */ 391 */
392 function quoteString(str) { 392 function quoteString(str) {
393 return str.replace(/([\\\.\+\*\?\[\^\]\$\(\)\{\}\=\!\<\>\|\:])/g, '\\$1'); 393 return str.replace(/([\\\.\+\*\?\[\^\]\$\(\)\{\}\=\!\<\>\|\:])/g, '\\$1');
394 } 394 }
395 395
396 /**
397 * Calls |callback| and stops listening the first time any event in |eventNames|
398 * is triggered on |target|.
399 * @param {!EventTarget} target
400 * @param {!Array<string>|string} eventNames Array or space-delimited string of
401 * event names to listen to (e.g. 'click mousedown').
402 * @param {function(!Event)} callback Called at most once. The
403 * optional return value is passed on by the listener.
404 */
405 function listenOnce(target, eventNames, callback) {
406 if (!Array.isArray(eventNames))
407 eventNames = eventNames.split(/ +/);
408
409 var removeAllAndCallCallback = function(event) {
410 for (var eventName of eventNames)
Dan Beam 2016/09/01 03:02:01 this code runs on iOS, where for..of support may b
michaelpg 2016/09/07 00:30:26 Done.
411 target.removeEventListener(eventName, removeAllAndCallCallback, false);
412 return callback(event);
413 };
414
415 for (var eventName of eventNames)
416 target.addEventListener(eventName, removeAllAndCallCallback, false);
417 }
418
396 // <if expr="is_ios"> 419 // <if expr="is_ios">
397 // Polyfill 'key' in KeyboardEvent for iOS. 420 // Polyfill 'key' in KeyboardEvent for iOS.
398 // This function is not intended to be complete but should 421 // This function is not intended to be complete but should
399 // be sufficient enough to have iOS work correctly while 422 // be sufficient enough to have iOS work correctly while
400 // it does not support key yet. 423 // it does not support key yet.
401 if (!('key' in KeyboardEvent.prototype)) { 424 if (!('key' in KeyboardEvent.prototype)) {
402 Object.defineProperty(KeyboardEvent.prototype, 'key', { 425 Object.defineProperty(KeyboardEvent.prototype, 'key', {
403 /** @this {KeyboardEvent} */ 426 /** @this {KeyboardEvent} */
404 get: function () { 427 get: function () {
405 // 0-9 428 // 0-9
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
452 case 0xdb: return '['; 475 case 0xdb: return '[';
453 case 0xdd: return ']'; 476 case 0xdd: return ']';
454 } 477 }
455 return 'Unidentified'; 478 return 'Unidentified';
456 } 479 }
457 }); 480 });
458 } else { 481 } else {
459 window.console.log("KeyboardEvent.Key polyfill not required"); 482 window.console.log("KeyboardEvent.Key polyfill not required");
460 } 483 }
461 // </if> /* is_ios */ 484 // </if> /* is_ios */
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698