Skip to content

Commit

Permalink
Ignore keyboard event if modifier key is held
Browse files Browse the repository at this point in the history
so that it does not interfere with web browser's own keyboard shortcut,
e.g. "Alt + Left arrow" for going back to the previous page in
browsing history.
  • Loading branch information
anthonyfok committed Aug 11, 2018
1 parent 66f4563 commit 7bf1b1b
Showing 1 changed file with 7 additions and 7 deletions.
14 changes: 7 additions & 7 deletions layouts/partials/previous-next-links.html
Expand Up @@ -13,13 +13,13 @@

<script>
document.body.onkeyup = function(e){

{{ if .Prev }}
if (!(e.ctrlKey || e.shiftKey || e.altKey || e.metaKey)) {
{{- if .Prev }}
if (e.keyCode == '37') { window.location = '{{ .Prev.Permalink }}'; }
{{ end }}
{{ if .Next }}
if (e.keyCode == '39') { window.location = '{{.Next.Permalink }}'; }
{{ end }}
{{- end }}
{{- if .Next }}
if (e.keyCode == '39') { window.location = '{{ .Next.Permalink }}'; }
{{- end }}
}
};

</script>

0 comments on commit 7bf1b1b

Please sign in to comment.