Skip to content

Commit

Permalink
#2240 allow developers to use the variable PAGE_NUMBER in thumbnails …
Browse files Browse the repository at this point in the history
…again (was broken in version 19.5.0).
  • Loading branch information
stephanrauh committed Mar 30, 2024
1 parent 5060dc9 commit 006884d
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 4 deletions.
1 change: 1 addition & 0 deletions projects/ngx-extended-pdf-viewer/changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -536,3 +536,4 @@
- 19.5.0 #2221 improve support for CSP (content security policy); tidy up the code generating thumbnails; stop showing thumbnail images while loading
- 19.5.1 #2221 display the toolbar correctly (probably this breaks CSP support again); #2239 `currentPageIndex()` and `addImageToAnnotationLayer()` now return / expect the page index (starting with 0) instead of the page number (starting with 1)
- 19.6.0 #2256 emit events when a user adds, removes, or edits an annotation; #2228 fixed highlight editor; updated the browser compatibility list
- 19.6.1 #2240 allow developers to use the variable PAGE_NUMBER in thumbnails again (was broken in version 19.5.0).
2 changes: 1 addition & 1 deletion projects/ngx-extended-pdf-viewer/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "ngx-extended-pdf-viewer",
"description": "Embedding PDF files in your Angular application. Highly configurable viewer including the toolbar, sidebar, and all the features you're used to.",
"version": "19.6.0",
"version": "19.6.2",
"license": "Apache-2.0",
"repository": {
"url": "https://github.com/stephanrauh/ngx-extended-pdf-viewer"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -94,9 +94,7 @@ export class PdfSidebarContentComponent implements OnDestroy {
anchor.setAttribute('data-l10n-id', 'pdfjs-thumb-page-title');
anchor.setAttribute('data-l10n-args', thumbPageTitlePromiseOrPageL10nArgs);

newElement.querySelectorAll('[data-page-number]').forEach((element) => {
element.setAttribute('data-page-number', id.toString());
});
this.replacePageNuberEverywhere(newElement, id.toString());

anchor.onclick = () => {
linkService.page = id;
Expand Down Expand Up @@ -139,4 +137,24 @@ export class PdfSidebarContentComponent implements OnDestroy {
}
}
}

private replacePageNuberEverywhere(element: Element, pageNumber: string): void {
if (element.attributes) {
Array.from(element.attributes).forEach((attr) => {
if (attr.value.includes('PAGE_NUMBER')) {
attr.value = attr.value.replace('PAGE_NUMBER', pageNumber);
}
});
}

element.childNodes.forEach((child) => {
if (child.nodeType === Node.ELEMENT_NODE) {
this.replacePageNuberEverywhere(child as Element, pageNumber);
} else if (child.nodeType === Node.TEXT_NODE) {
if (child.nodeValue && child.nodeValue.includes('PAGE_NUMBER')) {
child.nodeValue = child.nodeValue.replace('PAGE_NUMBER', pageNumber);
}
}
});
}
}

0 comments on commit 006884d

Please sign in to comment.