From 321cbec990b04359de57d5a8ad6cf7bbc10bd1ec Mon Sep 17 00:00:00 2001 From: Jens Kraemer Date: Mon, 13 Aug 2018 17:16:22 +0800 Subject: [PATCH 3/4] adds file preview prev/next navigation with arrow keys --- app/views/layouts/_file.html.erb | 2 +- app/views/repositories/entry.html.erb | 2 +- public/javascripts/application.js | 31 +++++++++++++++++++++++++++++++ 3 files changed, 33 insertions(+), 2 deletions(-) diff --git a/app/views/layouts/_file.html.erb b/app/views/layouts/_file.html.erb index 8ffadf703..5c1478b9c 100644 --- a/app/views/layouts/_file.html.erb +++ b/app/views/layouts/_file.html.erb @@ -12,7 +12,7 @@ <%= yield %> - + <%= render_pagination %> diff --git a/app/views/repositories/entry.html.erb b/app/views/repositories/entry.html.erb index ca52e2873..940bb2dc2 100644 --- a/app/views/repositories/entry.html.erb +++ b/app/views/repositories/entry.html.erb @@ -35,7 +35,7 @@ :class => 'icon icon-download') : nil } %> <% end %> - + <%= render_pagination %> diff --git a/public/javascripts/application.js b/public/javascripts/application.js index 5221152fb..76f65bf4c 100644 --- a/public/javascripts/application.js +++ b/public/javascripts/application.js @@ -756,6 +756,36 @@ function setupTabs() { } } +function setupFilePreviewNavigation() { + // only bind arrow keys when preview navigation is present + const element = $('.pagination.filepreview').first(); + if (element) { + + const handleArrowKey = function(selector, e){ + const href = $(element).find(selector).attr('href'); + if (href) { + window.location = href; + e.preventDefault(); + } + }; + + $(document).keydown(function(e) { + if(e.shiftKey || e.metaKey || e.ctrlKey || e.altKey) return; + switch(e.key) { + case 'ArrowLeft': + handleArrowKey('.previous a', e); + break; + + case 'ArrowRight': + handleArrowKey('.next a', e); + break; + } + }); + } +} + + + function hideOnLoad() { $('.hol').hide(); } @@ -879,3 +909,4 @@ $(document).ready(hideOnLoad); $(document).ready(addFormObserversForDoubleSubmit); $(document).ready(defaultFocus); $(document).ready(setupTabs); +$(document).ready(setupFilePreviewNavigation); -- 2.11.0