Reduce code duplication in the 'keydown' event handler in viewer.js
, by re-factoring the code which ensures that the viewerContainer
is focused
This commit is contained in:
parent
d5232f5b5a
commit
8275dff1b1
@ -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();
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user