Skip to content

Commit

Permalink
stephanrauh/ngx-extended-pdf-viewer#2463 now the PDF viewer only reac…
Browse files Browse the repository at this point in the history
…ts on the arrow keys if they aren't used for accessability
  • Loading branch information
stephanrauh committed Aug 18, 2024
1 parent 598858a commit 220236b
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 5 deletions.
38 changes: 34 additions & 4 deletions web/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -3373,11 +3373,17 @@ function webViewerKeyDown(evt) {
turnPage !== 0 &&
(!turnOnlyIfPageFit || pdfViewer.currentScaleValue === "page-fit")
) {
if (turnPage > 0) {
pdfViewer.nextPage();
} else {
pdfViewer.previousPage();
const { mainContainer } = PDFViewerApplication.appConfig;

// #2463 modified by ngx-extended-pdf-viewer
if (viewerIsAllowedToCaptureKeyEvent(mainContainer)) {
if (turnPage > 0) {
pdfViewer.nextPage();
} else {
pdfViewer.previousPage();
}
}
// #2463 end of modification by ngx-extended-pdf-viewer
handled = true;
}
}
Expand Down Expand Up @@ -3426,6 +3432,30 @@ function webViewerKeyDown(evt) {
}
}

/**
* Checks if the viewer can capture the keyboard event without
* ruining the user experience of the browser. In particular,
* it's still possible to navigate with the arrow keys through
* tabs.
* @param {the main container of the viewer} mainContainer
* @returns true if there's no reason to prevent the viewer from capturing the
* event
*/
function viewerIsAllowedToCaptureKeyEvent(mainContainer) {
let elementInFocus = document.activeElement;
const ngxExtendedPdfViewer = mainContainer.closest('ngx-extended-pdf-viewer');
while (elementInFocus && elementInFocus !== document.body) {
if (elementInFocus === ngxExtendedPdfViewer) {
return true;
}
if (elementInFocus.tabIndex !== -1) {
return false;
}
elementInFocus = elementInFocus.parentElement;
}
return true;
}

function beforeUnload(evt) {
evt.preventDefault();
evt.returnValue = "";
Expand Down
2 changes: 1 addition & 1 deletion web/ngx-extended-pdf-viewer-version.js
Original file line number Diff line number Diff line change
@@ -1 +1 @@
export const ngxExtendedPdfViewerVersion = '21.3.1';
export const ngxExtendedPdfViewerVersion = '21.3.2';

0 comments on commit 220236b

Please sign in to comment.