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