]> _ Git - odl.git/commitdiff
wip #5181 @0.25
authorvincent <vincent@enhydra.fr>
Sat, 26 Mar 2022 13:05:43 +0000 (14:05 +0100)
committervincent <vincent@enhydra.fr>
Sat, 26 Mar 2022 13:05:43 +0000 (14:05 +0100)
resources/js/search.js

index 35382b3e7816e4de2c8480c3a2fb00e752eca36e..c97a03b954c4410f385f07b886ffbfc7bc44cd51 100644 (file)
@@ -41,7 +41,7 @@ export default () => ({
 
         // PDFs can be opened directly
         if (result.type === 'pdf') {
-            attributes = '@click.prevent="app().openPDF($el.attributes.href.value); app().closeSearch();"';
+            attributes = '@click.prevent="openPDF($el.attributes.href.value); closeSearch();"';
         }
 
         return `<a href="${URL}" class="${classes}" ${attributes}>${result.displayedTitle}</a>`;
@@ -66,5 +66,37 @@ export default () => ({
         return `${this.results.length} résultats`;
     },
 
+    viewerURL: '/front/coeur/pdfjs/web/viewer.html?file=', // Base URL for viewer
+
+    openPDF(PDF_URL, updateQuerystring = true) {
+        PDF_URL = PDF_URL.replace('./storage', '../../../storage');
+
+        // Extra level needed when on non-exported version
+        if (location.href.includes('/front/') && !PDF_URL.includes('http')) {
+            PDF_URL = '../' + PDF_URL;
+        }
+
+        if (updateQuerystring) {
+            const location = new URL(window.location.href);
+            location.searchParams.set('pdf', PDF_URL);
+            history.replaceState(null, document.title, location.toString());
+        }
+
+        this.PDFOpen = true;
+        this.$nextTick(() => {
+            this.$refs.PDFViewer.setAttribute('src', this.viewerURL + PDF_URL)
+        });
+    },
+
+    closePDF() {
+        this.PDFOpen = false;
+        this.$refs.PDFViewer.setAttribute('src', '');
+
+        // Update the page URL to remove querystring
+        const location = new URL(window.location.href);
+        location.searchParams.delete('pdf');
+        history.replaceState(null, document.title, location.toString());
+    },
+
 });