OLD | NEW |
1 /* | 1 /* |
2 * Copyright (C) 2011 Google Inc. All rights reserved. | 2 * Copyright (C) 2011 Google Inc. All rights reserved. |
3 * Copyright (C) 2006, 2007, 2008 Apple Inc. All rights reserved. | 3 * Copyright (C) 2006, 2007, 2008 Apple Inc. All rights reserved. |
4 * Copyright (C) 2007 Matt Lilek (pewtermoose@gmail.com). | 4 * Copyright (C) 2007 Matt Lilek (pewtermoose@gmail.com). |
5 * Copyright (C) 2009 Joseph Pecoraro | 5 * Copyright (C) 2009 Joseph Pecoraro |
6 * | 6 * |
7 * Redistribution and use in source and binary forms, with or without | 7 * Redistribution and use in source and binary forms, with or without |
8 * modification, are permitted provided that the following conditions | 8 * modification, are permitted provided that the following conditions |
9 * are met: | 9 * are met: |
10 * | 10 * |
(...skipping 1433 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1444 set gray(gray) | 1444 set gray(gray) |
1445 { | 1445 { |
1446 this._buttonElement.className = gray ? "close-button-gray" : "close-
button"; | 1446 this._buttonElement.className = gray ? "close-button-gray" : "close-
button"; |
1447 }, | 1447 }, |
1448 | 1448 |
1449 __proto__: HTMLDivElement.prototype | 1449 __proto__: HTMLDivElement.prototype |
1450 }); | 1450 }); |
1451 })(); | 1451 })(); |
1452 | 1452 |
1453 /** | 1453 /** |
| 1454 * @param {!Element} input |
| 1455 * @param {function(string)} apply |
| 1456 * @param {function(string):boolean} validate |
| 1457 * @param {boolean} numeric |
| 1458 * @return {function(string)} |
| 1459 */ |
| 1460 WebInspector.bindInput = function(input, apply, validate, numeric) |
| 1461 { |
| 1462 input.addEventListener("change", onChange, false); |
| 1463 input.addEventListener("input", onInput, false); |
| 1464 input.addEventListener("keydown", onKeyDown, false); |
| 1465 input.addEventListener("focus", input.select.bind(input), false); |
| 1466 |
| 1467 function onInput() |
| 1468 { |
| 1469 input.classList.toggle("error-input", !validate(input.value)); |
| 1470 } |
| 1471 |
| 1472 function onChange() |
| 1473 { |
| 1474 var valid = validate(input.value); |
| 1475 input.classList.toggle("error-input", !valid); |
| 1476 if (valid) |
| 1477 apply(input.value); |
| 1478 } |
| 1479 |
| 1480 /** |
| 1481 * @param {!Event} event |
| 1482 */ |
| 1483 function onKeyDown(event) |
| 1484 { |
| 1485 if (isEnterKey(event)) { |
| 1486 if (validate(input.value)) |
| 1487 apply(input.value); |
| 1488 return; |
| 1489 } |
| 1490 |
| 1491 if (!numeric) |
| 1492 return; |
| 1493 |
| 1494 var increment = event.keyIdentifier === "Up" ? 1 : event.keyIdentifier =
== "Down" ? -1 : 0; |
| 1495 if (!increment) |
| 1496 return; |
| 1497 if (event.shiftKey) |
| 1498 increment *= 10; |
| 1499 |
| 1500 var value = input.value; |
| 1501 if (!validate(value) || !value) |
| 1502 return; |
| 1503 |
| 1504 value = (value ? Number(value) : 0) + increment; |
| 1505 var stringValue = value ? String(value) : ""; |
| 1506 if (!validate(stringValue) || !value) |
| 1507 return; |
| 1508 |
| 1509 input.value = stringValue; |
| 1510 apply(input.value); |
| 1511 event.preventDefault(); |
| 1512 } |
| 1513 |
| 1514 /** |
| 1515 * @param {string} value |
| 1516 */ |
| 1517 function setValue(value) |
| 1518 { |
| 1519 if (value === input.value) |
| 1520 return; |
| 1521 var valid = validate(value); |
| 1522 input.classList.toggle("error-input", !valid); |
| 1523 input.value = value; |
| 1524 input.setSelectionRange(value.length, value.length); |
| 1525 } |
| 1526 |
| 1527 return setValue; |
| 1528 } |
| 1529 |
| 1530 /** |
1454 * @constructor | 1531 * @constructor |
1455 */ | 1532 */ |
1456 WebInspector.StringFormatter = function() | 1533 WebInspector.StringFormatter = function() |
1457 { | 1534 { |
1458 this._processors = []; | 1535 this._processors = []; |
1459 this._regexes = []; | 1536 this._regexes = []; |
1460 } | 1537 } |
1461 | 1538 |
1462 WebInspector.StringFormatter.prototype = { | 1539 WebInspector.StringFormatter.prototype = { |
1463 /** | 1540 /** |
(...skipping 280 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1744 [NetworkAgent.ResourcePriority.High, WebInspector.UIString("High")], | 1821 [NetworkAgent.ResourcePriority.High, WebInspector.UIString("High")], |
1745 [NetworkAgent.ResourcePriority.VeryHigh, WebInspector.UIString("High
est")] | 1822 [NetworkAgent.ResourcePriority.VeryHigh, WebInspector.UIString("High
est")] |
1746 ]); | 1823 ]); |
1747 WebInspector.uiLabelForPriority._priorityToUILabel = labelMap; | 1824 WebInspector.uiLabelForPriority._priorityToUILabel = labelMap; |
1748 } | 1825 } |
1749 return labelMap.get(priority) || WebInspector.UIString("Unknown"); | 1826 return labelMap.get(priority) || WebInspector.UIString("Unknown"); |
1750 } | 1827 } |
1751 | 1828 |
1752 /** @type {!WebInspector.ThemeSupport} */ | 1829 /** @type {!WebInspector.ThemeSupport} */ |
1753 WebInspector.themeSupport; | 1830 WebInspector.themeSupport; |
OLD | NEW |