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