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. | 2 // an editable field. We capture the event at the Window to let any handlers |
3 document.addEventListener('keydown', function(e) { | 3 // or listeners registered on the Document have a chance to handle it first. |
| 4 window.addEventListener('keydown', function(e) { |
| 5 // Listening on the Window means the event has no path (see |
| 6 // http://crbug.com/645527), so we'll have to look at the focused (active) |
| 7 // element. This means it will not work properly with shadow DOM. |
| 8 // TODO: Fix behavior with shadow DOM when the above bug is resolved. |
4 if (e.key === 'Backspace' && | 9 if (e.key === 'Backspace' && |
| 10 !e.defaultPrevented && |
5 !e.altKey && | 11 !e.altKey && |
6 !e.ctrlKey && | 12 !e.ctrlKey && |
7 !e.metaKey && | 13 !e.metaKey && |
8 !isEditable(e.path)) { | 14 !isEditable(document.activeElement)) { |
9 e.shiftKey ? window.history.forward(): window.history.back(); | 15 e.shiftKey ? window.history.forward(): window.history.back(); |
10 e.preventDefault(); | 16 e.preventDefault(); |
11 } | 17 } |
12 }); | 18 }); |
OLD | NEW |