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 | |
Dan Beam
2016/06/29 18:28:09
nit: remove extra \n
dtapuska
2016/06/29 20:09:02
Done.
| |
376 | |
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)) { | |
Dan Beam
2016/06/29 18:28:09
I think it's cool that you're doing runtime featur
dtapuska
2016/06/29 20:09:02
Done.
| |
382 var keyGetter = { | |
Dan Beam
2016/06/29 18:28:09
can we just inline keyGetter? -1 global
Object.d
dtapuska
2016/06/29 20:09:02
Done.
| |
383 get: function () { | |
384 // 0-9 | |
385 if (this.keyCode >= 0x30 && this.keyCode <= 0x39) | |
386 return String.fromCharCode(this.keyCode); | |
Dan Beam
2016/06/29 18:28:09
indent off
dtapuska
2016/06/29 20:09:02
Done.
| |
387 | |
388 // A-Z | |
389 if (this.keyCode >= 0x41 && this.keyCode <= 0x5a) { | |
390 var result = String.fromCharCode(this.keyCode).toLowerCase(); | |
391 if (this.shiftKey) | |
392 result = result.toUpperCase(); | |
393 return result; | |
Dan Beam
2016/06/29 18:28:09
indent off
dtapuska
2016/06/29 20:09:02
Done.
| |
394 } | |
395 | |
396 // Special characters | |
397 switch(this.keyCode) { | |
398 case 0x08: return 'Backspace'; | |
399 case 0x09: return 'Tab'; | |
400 case 0x0d: return 'Enter'; | |
401 case 0x10: return 'Shift'; | |
402 case 0x11: return 'Control'; | |
403 case 0x12: return 'Alt'; | |
404 case 0x1b: return 'Escape'; | |
405 case 0x20: return ' '; | |
406 case 0x21: return 'PageUp'; | |
407 case 0x22: return 'PageDown'; | |
408 case 0x23: return 'End'; | |
409 case 0x24: return 'Home'; | |
410 case 0x25: return 'ArrowLeft'; | |
411 case 0x26: return 'ArrowUp'; | |
412 case 0x27: return 'ArrowRight'; | |
413 case 0x28: return 'ArrowDown'; | |
414 case 0x2d: return 'Insert'; | |
415 case 0x2e: return 'Delete'; | |
416 case 0x5b: return 'Meta'; | |
417 case 0x70: return 'F1'; | |
418 case 0x71: return 'F2'; | |
419 case 0x72: return 'F3'; | |
420 case 0x73: return 'F4'; | |
421 case 0x74: return 'F5'; | |
422 case 0x75: return 'F6'; | |
423 case 0x76: return 'F7'; | |
424 case 0x77: return 'F8'; | |
425 case 0x78: return 'F9'; | |
426 case 0x79: return 'F10'; | |
427 case 0x7a: return 'F11'; | |
428 case 0x7b: return 'F12'; | |
429 case 0xbb: return '='; | |
430 case 0xbd: return '-'; | |
431 case 0xdb: return '['; | |
432 case 0xdd: return ']'; | |
433 } | |
434 return 'Unidentified'; | |
435 } | |
436 }; | |
437 Object.defineProperty(KeyboardEvent.prototype, 'key', keyGetter); | |
438 } | |
OLD | NEW |