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, so we'll have to | |
6 // look at the focused (active) element. | |
4 if (e.key === 'Backspace' && | 7 if (e.key === 'Backspace' && |
8 !e.defaultPrevented && | |
5 !e.altKey && | 9 !e.altKey && |
6 !e.ctrlKey && | 10 !e.ctrlKey && |
7 !e.metaKey && | 11 !e.metaKey && |
8 !isEditable(e.path)) { | 12 !isEditable(document.activeElement)) { |
ojan
2016/09/09 18:06:30
This won't do the right thing with shadow DOM.
h
| |
9 e.shiftKey ? window.history.forward(): window.history.back(); | 13 e.shiftKey ? window.history.forward(): window.history.back(); |
10 e.preventDefault(); | 14 e.preventDefault(); |
11 } | 15 } |
12 }); | 16 }); |
OLD | NEW |