// 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>`;
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());
+ },
+
});