From 7516823617108bd23d0004143f5602dad7d74527 Mon Sep 17 00:00:00 2001 From: Go MAEDA Date: Thu, 4 Oct 2018 13:27:09 +0000 Subject: [PATCH] Adds file preview prev/next navigation with arrow keys (#29395). MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Patch by Jens Krämer. git-svn-id: http://svn.redmine.org/redmine/trunk@17569 e93f8b46-1217-0410-a6f0-8f06a7374b81 --- 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);