$doc = new Document();
$doc->setType($data->get('type'));
$doc->setId($data->get('id'));
- $doc->setUrl('asset_' . $data->get('id'));
+ $doc->setUrl($this->relativeURL($asset->getFirstMediaUrl($asset->file_upload)));
+ $doc->setThumb($this->relativeURL($asset->getThumbURL()));
$doc->setTitle($data->get('title'));
$doc->setKeywords($data->get('keywords'));
$this->addDocument($doc);
foreach ($pdfs as $pdf) {
$document = new PDF($pdf->getFirstMediaInField('file_upload')->getPath());
$document->setId($pdf->id);
- $document->setUrl('asset_' . $document->getId());
+ $document->setUrl($this->relativeURL($pdf->getFirstMediaUrl($pdf->file_upload)));
$document->setTitle($pdf->title);
$document->setKeywords($pdf->keywords);
- $document->setThumb($pdf->getThumbURL());
+ $document->setThumb($this->relativeURL($pdf->getThumbURL()));
$document->setType('pdf');
$this->addDocument($document);
}
}
+
+ public function relativeURL($URL) {
+ // Get the relative URL by taking from /storage/ onwards
+ // We assume that assets are always going to be in the storage folder
+ return '.' . strstr($URL, '/storage/');
+ }
}
},
},
query: '', // The search query
+ medialibrary: '', // Holds URL of the media library that is passed in from the component
async init() {
- this.miniSearch = new MiniSearch(this.setup);
- await loadScript('../js/search.index.js');
- this.miniSearch.addAllAsync(minisearchodl);
+ // We need the URL from the HTML because it gets properly updated when exporting the final version
+ await loadScript(this.$el.dataset.searchindex);
+
+ // Delay miniSearch initialisation so there's less chance of animations stuttering during page loads
+ setTimeout(() => {
+ this.miniSearch = new MiniSearch(this.setup);
+ this.miniSearch.addAllAsync(minisearchodl);
+ }, 4000);
+
+ this.medialibrary = this.$el.dataset.medialibrary;
+ },
+
+ makeResultLink(result, classes) {
+ // Result links have differing attributes, so we need this function to be able to generate the HTML correctly
+ // This can't be done directly in the x-for template loop
+ let URL = result.url;
+ let attributes = '';
+
+ // Media items get displayed on the media library page (simpler this way so extra JSON object isn't needed)
+ if (result.type === 'video' || result.type === 'audio') {
+ URL = `${this.medialibrary}?player=${result.id}`;
+ }
+
+ // PDFs can be opened directly
+ if (result.type === 'pdf') {
+ attributes = '@click.prevent="openPDF($el.attributes.href.value); closeSearch();"';
+ }
+
+ return `<a href="${URL}" class="${classes}" ${attributes}>${result.title}</a>`;
},
get results() {
<div class="overlay search-overlay
bg-white text-black
z-20"
+ {{-- Pass URLs in from HTML so JS will always have the correct version regardless of environment --}}
+ data-searchindex="{{ asset('js/search.index.js') }}"
+ data-medialibrary="{{ \App\Http\Controllers\FrontController::getLinkData('medialibrary')['url'] }}"
{{-- See js/search.js --}}
x-data="search()"
x-show="searchOpen"
placeholder="Recherche"
@keyup.enter="$el.blur()" {{-- Remove focus on enter in order to hide virtual keyboard --}}
x-model="query"
- class="appearance-none outline-none
+ class="appearance-none outline-none bg-white
mt-8 w-full
font-semibold text-6xl uppercase
animate"
</div>
{{-- Search Results --}}
- <div class="flex-1 max-h-full overflow-y-auto"
+ <div class="flex-1 max-h-full w-full overflow-y-auto"
x-show="searchOpen"
x-transition:enter.opacity.duration.500ms.delay.1500ms
x-transition:leave.opacity.delay.50ms>
<div class="h-full max-h-full overflow-y-auto">
<template x-for="result in results" :key="result.id">
<div class="py-8 border-b border-black border-opacity-20">
- <a :href="result.url" x-text="result.title" class="text-2xl text-blue"></a>
+ <div x-html="makeResultLink(result, 'text-2xl text-blue')"></div>
<p x-text="result.text" class="mt-2 line-clamp-1"></p>
</div>
</template>
},
openSearch() {
+ // Search can be opened from the menu, so make sure menu is closed first
+ // to prevent interference since the menu always has a higher z-index
this.menuOpen = false;
this.searchOpen = true;
this.$nextTick(() => {
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);
</ul>
</div>
- {{-- Search Overlay --}}
- <x-search/>
-
{{-- PDF Viewer Overlay --}}
<div class="overlay pdf-overlay
bg-white text-black
{{-- Media Player --}}
<x-media-library.player/>
+ {{-- Search Overlay (placed last so it sits above other modals, like the PDF viewer, with the same z-index) --}}
+ <x-search/>
+
@endsection