From 006884d6ce8057e69aed04c1b8668e12f7bc797b Mon Sep 17 00:00:00 2001 From: Stephan Rauh <3045767+stephanrauh@users.noreply.github.com> Date: Sat, 30 Mar 2024 22:41:02 +0100 Subject: [PATCH] stephanrauh/ngx-extended-pdf-viewer#2240 allow developers to use the variable PAGE_NUMBER in thumbnails again (was broken in version 19.5.0). --- projects/ngx-extended-pdf-viewer/changelog.md | 1 + projects/ngx-extended-pdf-viewer/package.json | 2 +- .../pdf-sidebar-content.component.ts | 24 ++++++++++++++++--- 3 files changed, 23 insertions(+), 4 deletions(-) diff --git a/projects/ngx-extended-pdf-viewer/changelog.md b/projects/ngx-extended-pdf-viewer/changelog.md index 08603e949..9ce1b2ed4 100644 --- a/projects/ngx-extended-pdf-viewer/changelog.md +++ b/projects/ngx-extended-pdf-viewer/changelog.md @@ -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). diff --git a/projects/ngx-extended-pdf-viewer/package.json b/projects/ngx-extended-pdf-viewer/package.json index f2f0dba8b..8b20a3f5e 100644 --- a/projects/ngx-extended-pdf-viewer/package.json +++ b/projects/ngx-extended-pdf-viewer/package.json @@ -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" diff --git a/projects/ngx-extended-pdf-viewer/src/lib/sidebar/pdf-sidebar/pdf-sidebar-content/pdf-sidebar-content.component.ts b/projects/ngx-extended-pdf-viewer/src/lib/sidebar/pdf-sidebar/pdf-sidebar-content/pdf-sidebar-content.component.ts index 24ca54a66..40851a574 100644 --- a/projects/ngx-extended-pdf-viewer/src/lib/sidebar/pdf-sidebar/pdf-sidebar-content/pdf-sidebar-content.component.ts +++ b/projects/ngx-extended-pdf-viewer/src/lib/sidebar/pdf-sidebar/pdf-sidebar-content/pdf-sidebar-content.component.ts @@ -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; @@ -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); + } + } + }); + } }