OLD | NEW |
1 // Determine whether focus is in an editable text field. | 1 // Determine whether focus is in an editable text field. |
2 function isEditable(path) { | 2 function isEditable(path) { |
3 var target = path[0]; | 3 var target = path[0]; |
4 | 4 |
5 // Elements may be explicitly marked as editable. | 5 // Elements may be explicitly marked as editable. |
6 if (target.isContentEditable) | 6 if (target.isContentEditable) |
7 return true; | 7 return true; |
8 | 8 |
9 // Several types of input fields are editable, but not all (e.g., checkboxes). | 9 // Many types of input fields are editable, but not all (e.g., checkboxes). |
10 var nodeName = target.nodeName; | 10 var nodeName = target.nodeName.toUpperCase(); |
11 var nodeType = target.type; | 11 var nodeType = target.type || ''; |
| 12 nodeType = nodeType.toLowerCase(); |
12 if (nodeName === 'TEXTAREA' || | 13 if (nodeName === 'TEXTAREA' || |
13 (nodeName === 'INPUT' && (nodeType === 'text' || | 14 (nodeName === 'INPUT' && (nodeType === 'text' || |
14 nodeType === 'email' || | |
15 nodeType === 'number' || | |
16 nodeType === 'password' || | 15 nodeType === 'password' || |
17 nodeType === 'search' || | 16 nodeType === 'search' || |
18 nodeType === 'tel'))) { | 17 nodeType === 'date' || |
| 18 nodeType === 'datetime' || |
| 19 nodeType === 'datetime-local' || |
| 20 nodeType === 'email' || |
| 21 nodeType === 'month' || |
| 22 nodeType === 'number' || |
| 23 nodeType === 'tel' || |
| 24 nodeType === 'time' || |
| 25 nodeType === 'url' || |
| 26 nodeType === 'week'))) { |
19 return true; | 27 return true; |
20 } | 28 } |
21 | 29 |
22 // Certain CSS styles, on elements or their parents, also indicate editable | 30 // Certain CSS styles, on elements or their parents, also indicate editable |
23 // fields. | 31 // fields. |
24 var pathLength = path.length; | 32 var pathLength = path.length; |
25 for (var i = 0; i < pathLength; ++i) { | 33 for (var i = 0; i < pathLength; ++i) { |
26 target = path[i]; | 34 target = path[i]; |
27 if (target.nodeType == 1) { // Only Elements have computed styles. | 35 if (target.nodeType == 1) { // Only Elements have computed styles. |
28 var userModify = getComputedStyle(path[i])['-webkit-user-select']; | 36 var userModify = getComputedStyle(path[i])['-webkit-user-select']; |
29 if (userModify == 'read-write' || userModify == 'write-only') | 37 if (userModify == 'read-write' || userModify == 'write-only') |
30 return true; | 38 return true; |
31 } | 39 } |
32 } | 40 } |
33 return false; | 41 return false; |
34 } | 42 } |
OLD | NEW |