OLD | NEW |
1 // Listen for shift-backspace or unmodified backspace and navigate if not in | 1 // Listen for shift-backspace or unmodified backspace and navigate if not in |
2 // an editable field. We capture the event at the Window to let any handlers | 2 // an editable field. We capture the event at the Window to let any handlers |
3 // or listeners registered on the Document have a chance to handle it first. | 3 // or listeners registered on the Document have a chance to handle it first. |
4 window.addEventListener('keydown', function(e) { | 4 window.addEventListener('keydown', function(e) { |
5 // Listening on the Window means the event has no path (see | 5 // Before Chrome 55, listening on the Window means the event has no path, |
6 // http://crbug.com/645527), so we'll have to look at the focused (active) | 6 // instead pointing to the Window (see http://crbug.com/645527). In that |
7 // element. This means it will not work properly with shadow DOM. | 7 // case, we have to look at the focused (active) element. |
8 // TODO: Fix behavior with shadow DOM when the above bug is resolved. | 8 // TODO: Switch entirely to e.path once Chrome 55 is launched. |
9 if (e.key === 'Backspace' && | 9 if (e.key === 'Backspace' && |
10 !e.defaultPrevented && | 10 !e.defaultPrevented && |
11 !e.altKey && | 11 !e.altKey && |
12 !e.ctrlKey && | 12 !e.ctrlKey && |
13 !e.metaKey && | 13 !e.metaKey) { |
14 !isEditable(document.activeElement)) { | 14 var target = e.path[0]; |
15 e.shiftKey ? window.history.forward(): window.history.back(); | 15 if (target === window) |
16 e.preventDefault(); | 16 target = document.activeElement; |
| 17 if (!isEditable(target)) { |
| 18 e.shiftKey ? window.history.forward(): window.history.back(); |
| 19 e.preventDefault(); |
| 20 } |
17 } | 21 } |
18 }); | 22 }); |
OLD | NEW |