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 click = 'return true;';
-
- // 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') {
- click = 'console.log($el.attributes.href.value); openPDF($el.attributes.href.value); closeSearch(); return false;';
- }
- return {url: URL, click: click, classes: classes, displayedTitle: result.displayedTitle};
- },
-
get results() {
if (this.query.length < 3) {
return [];
}
- var res = this.miniSearch.search(this.query);
+ var results = this.miniSearch.search(this.query);
+ var res = [];
+ for (var i in results) {
+ var r = results[r];
+ let URL = r.url;
+ let click = 'return true;';
+ // Media items get displayed on the media library page (simpler this way so extra JSON object isn't needed)
+ if (r.type === 'video' || r.type === 'audio') {
+ URL = `${this.medialibrary}?player=${r.id}`;
+ }
+ res.push({url: URL, click: click, displayedTitle: r.displayedTitle, id: r.id});
+ }
return res;
},
<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">
- <div x-model="makeResultLink(result, 'text-2xl text-blue')">
- <a x-bind:href="url" x-bind:class="classes" x-text="displayedTitle" @click="click"></a>
+ <div>
+ <template x-if="result.type==pdf">
+ <a x-bind:href="url" class="text-2xl text-blue" x-text="displayedTitle"></a>
+ </template>
+ <template x-if="result.type!=pdf">
+ <a x-bind:href="url" class="text-2xl text-blue" x-text="displayedTitle"
+ @click.prevent="console.log($el.attributes.href.value); openPDF($el.attributes.href.value); closeSearch();"></a>
+ </template>
</div>
<p x-text="result.text" class="mt-2 line-clamp-1"></p>
</div>