[Pkg-javascript-commits] [pdf.js] 119/157: Reduce code duplication in the 'keydown' event handler in `viewer.js`, by re-factoring the code which ensures that the `viewerContainer` is focused

David Prévot taffit at moszumanska.debian.org
Tue Aug 11 06:46:47 UTC 2015


This is an automated email from the git hooks/post-receive script.

taffit pushed a commit to branch master
in repository pdf.js.

commit 8275dff1b1ff7e4756b1e24ad6173bd283094bfe
Author: Jonas Jenwald <jonas.jenwald at gmail.com>
Date:   Thu Jul 23 12:25:19 2015 +0200

    Reduce code duplication in the 'keydown' event handler in `viewer.js`, by re-factoring the code which ensures that the `viewerContainer` is focused
---
 web/viewer.js | 29 +++++++++++++----------------
 1 file changed, 13 insertions(+), 16 deletions(-)

diff --git a/web/viewer.js b/web/viewer.js
index 9bbe8d8..e627097 100644
--- a/web/viewer.js
+++ b/web/viewer.js
@@ -1935,6 +1935,7 @@ window.addEventListener('keydown', function keydown(evt) {
       return;
     }
   }
+  var ensureViewerFocused = false;
 
   if (cmd === 0) { // no control key pressed at all.
     switch (evt.keyCode) {
@@ -1993,9 +1994,7 @@ window.addEventListener('keydown', function keydown(evt) {
         if (isViewerInPresentationMode || PDFViewerApplication.page > 1) {
           PDFViewerApplication.page = 1;
           handled = true;
-          if (!pdfViewer.containsElement(curElement)) {
-            pdfViewer.focus();
-          }
+          ensureViewerFocused = true;
         }
         break;
       case 35: // end
@@ -2003,9 +2002,7 @@ window.addEventListener('keydown', function keydown(evt) {
             PDFViewerApplication.page < PDFViewerApplication.pagesCount)) {
           PDFViewerApplication.page = PDFViewerApplication.pagesCount;
           handled = true;
-          if (!pdfViewer.containsElement(curElement)) {
-            pdfViewer.focus();
-          }
+          ensureViewerFocused = true;
         }
         break;
 
@@ -2040,17 +2037,10 @@ window.addEventListener('keydown', function keydown(evt) {
   if (!handled && !isViewerInPresentationMode) {
     // 33=Page Up  34=Page Down  35=End    36=Home
     // 37=Left     38=Up         39=Right  40=Down
-    if (evt.keyCode >= 33 && evt.keyCode <= 40 &&
-        !pdfViewer.containsElement(curElement)) {
-      // The page container is not focused, but a page navigation key has been
-      // pressed. Change the focus to the viewer container to make sure that
-      // navigation by keyboard works as expected.
-      pdfViewer.focus();
-    }
     // 32=Spacebar
-    if (evt.keyCode === 32 && curElementTagName !== 'BUTTON' &&
-        !pdfViewer.containsElement(curElement)) {
-      pdfViewer.focus();
+    if ((evt.keyCode >= 33 && evt.keyCode <= 40) ||
+        (evt.keyCode === 32 && curElementTagName !== 'BUTTON')) {
+      ensureViewerFocused = true;
     }
   }
 
@@ -2071,6 +2061,13 @@ window.addEventListener('keydown', function keydown(evt) {
     }
   }
 
+  if (ensureViewerFocused && !pdfViewer.containsElement(curElement)) {
+    // The page container is not focused, but a page navigation key has been
+    // pressed. Change the focus to the viewer container to make sure that
+    // navigation by keyboard works as expected.
+    pdfViewer.focus();
+  }
+
   if (handled) {
     evt.preventDefault();
   }

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-javascript/pdf.js.git



More information about the Pkg-javascript-commits mailing list