OLD | NEW |
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 354 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
365 } | 365 } |
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 |
| 376 <if expr="is_ios"> |
| 377 // Polyfill 'key' in KeyboardEvent for iOS. |
| 378 // This function is not intended to be complete but should |
| 379 // be sufficient enough to have iOS work correctly while |
| 380 // it does not support key yet. |
| 381 if (!('key' in KeyboardEvent.prototype)) { |
| 382 Object.defineProperty(KeyboardEvent.prototype, 'key', { |
| 383 /** @this {KeyboardEvent} */ |
| 384 get: function () { |
| 385 // 0-9 |
| 386 if (this.keyCode >= 0x30 && this.keyCode <= 0x39) |
| 387 return String.fromCharCode(this.keyCode); |
| 388 |
| 389 // A-Z |
| 390 if (this.keyCode >= 0x41 && this.keyCode <= 0x5a) { |
| 391 var result = String.fromCharCode(this.keyCode).toLowerCase(); |
| 392 if (this.shiftKey) |
| 393 result = result.toUpperCase(); |
| 394 return result; |
| 395 } |
| 396 |
| 397 // Special characters |
| 398 switch(this.keyCode) { |
| 399 case 0x08: return 'Backspace'; |
| 400 case 0x09: return 'Tab'; |
| 401 case 0x0d: return 'Enter'; |
| 402 case 0x10: return 'Shift'; |
| 403 case 0x11: return 'Control'; |
| 404 case 0x12: return 'Alt'; |
| 405 case 0x1b: return 'Escape'; |
| 406 case 0x20: return ' '; |
| 407 case 0x21: return 'PageUp'; |
| 408 case 0x22: return 'PageDown'; |
| 409 case 0x23: return 'End'; |
| 410 case 0x24: return 'Home'; |
| 411 case 0x25: return 'ArrowLeft'; |
| 412 case 0x26: return 'ArrowUp'; |
| 413 case 0x27: return 'ArrowRight'; |
| 414 case 0x28: return 'ArrowDown'; |
| 415 case 0x2d: return 'Insert'; |
| 416 case 0x2e: return 'Delete'; |
| 417 case 0x5b: return 'Meta'; |
| 418 case 0x70: return 'F1'; |
| 419 case 0x71: return 'F2'; |
| 420 case 0x72: return 'F3'; |
| 421 case 0x73: return 'F4'; |
| 422 case 0x74: return 'F5'; |
| 423 case 0x75: return 'F6'; |
| 424 case 0x76: return 'F7'; |
| 425 case 0x77: return 'F8'; |
| 426 case 0x78: return 'F9'; |
| 427 case 0x79: return 'F10'; |
| 428 case 0x7a: return 'F11'; |
| 429 case 0x7b: return 'F12'; |
| 430 case 0xbb: return '='; |
| 431 case 0xbd: return '-'; |
| 432 case 0xdb: return '['; |
| 433 case 0xdd: return ']'; |
| 434 } |
| 435 return 'Unidentified'; |
| 436 } |
| 437 }); |
| 438 } else { |
| 439 window.console.log("KeyboardEvent.Key polyfill not required"); |
| 440 } |
| 441 </if> /* is_ios */ |
OLD | NEW |