From 0341f73d09920c61c6beb2d48a02e48a1daec5f8 Mon Sep 17 00:00:00 2001 From: Aaron van Geffen Date: Sat, 3 Sep 2016 21:33:48 +0200 Subject: [PATCH] Allow changing album pages by arrow keys. --- public/js/albumnav.js | 32 ++++++++++++++++++++++++++++++++ templates/PhotosIndex.php | 3 ++- 2 files changed, 34 insertions(+), 1 deletion(-) create mode 100644 public/js/albumnav.js diff --git a/public/js/albumnav.js b/public/js/albumnav.js new file mode 100644 index 0000000..fc8cfe6 --- /dev/null +++ b/public/js/albumnav.js @@ -0,0 +1,32 @@ +function enableKeyDownNavigation() { + document.addEventListener("keydown", function (event) { + if (event.keyCode == 37) { + var target = document.querySelector(".pagination ul > :first-child a"); + if (target && target.href) { + event.preventDefault(); + document.location.href = target.href; + } + } + else if (event.keyCode == 39) { + var target = document.querySelector(".pagination ul > :last-child a"); + if (target && target.href) { + event.preventDefault(); + document.location.href = target.href; + } + } + }, false); +} + +function disableKeyDownPropagation(obj) { + for (var x = 0; x < obj.length; x++) { + obj[x].addEventListener("keydown", function (event) { + if (event.keyCode == 37 || event.keyCode == 39) { + event.stopPropagation(); + } + }); + } +} + +enableKeyDownNavigation(); +disableKeyDownPropagation(document.getElementsByTagName("textarea")); +disableKeyDownPropagation(document.getElementsByTagName("input")); diff --git a/templates/PhotosIndex.php b/templates/PhotosIndex.php index 5f353b1..044ef39 100644 --- a/templates/PhotosIndex.php +++ b/templates/PhotosIndex.php @@ -53,7 +53,8 @@ class PhotosIndex extends SubTemplate } echo ' - '; + + '; } protected function header($photos)