From: vincent Date: Sat, 26 Mar 2022 13:05:43 +0000 (+0100) Subject: wip #5181 @0.25 X-Git-Url: http://git.cubedesigners.com/?a=commitdiff_plain;h=25571ffdd9a07d012b1a7ba559dbcc7e24f5d71c;p=odl.git wip #5181 @0.25 --- diff --git a/resources/js/search.js b/resources/js/search.js index 35382b3..c97a03b 100644 --- a/resources/js/search.js +++ b/resources/js/search.js @@ -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 `${result.displayedTitle}`; @@ -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()); + }, + });