| // Determine whether focus is in an editable text field. |
| function isEditable(path) { |
| var target = path[0]; |
| |
| // Elements may be explicitly marked as editable. |
| if (target.isContentEditable) |
| return true; |
| |
| // Several types of input fields are editable, but not all (e.g., checkboxes). |
| var nodeName = target.nodeName; |
| var nodeType = target.type; |
| if (nodeName === 'TEXTAREA' || |
| (nodeName === 'INPUT' && (nodeType === 'text' || |
| nodeType === 'email' || |
| nodeType === 'password' || |
| nodeType === 'search'))) { |
| return true; |
| } |
| |
| // Certain CSS styles, on elements or their parents, also indicate editable |
| // fields. |
| var pathLength = path.length; |
| for (var i = 0; i < pathLength; ++i) { |
| target = path[i]; |
| if (target.nodeType == 1) { // Only Elements have computed styles. |
| var userModify = getComputedStyle(path[i])['-webkit-user-select']; |
| if (userModify == 'read-write' || userModify == 'write-only') |
| return true; |
| } |
| } |
| return false; |
| } |