import intersect from '@alpinejs/intersect';
import media_library from './media-library';
import search from './search';
-
window.Alpine = Alpine;
// Plugins
Alpine.data('search', search);
Alpine.start();
-
-setInterval(function () {
- Alpine.discoverUninitializedComponents(function (el) {
- Alpine.initializeComponent(el)
- })
-}, 1000);
// 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 = '';
+ 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') {
// PDFs can be opened directly
if (result.type === 'pdf') {
- attributes = '@click.prevent="console.log($el.attributes.href.value); openPDF($el.attributes.href.value); closeSearch();"';
+ click = 'console.log($el.attributes.href.value); openPDF($el.attributes.href.value); closeSearch(); return false;';
}
-
- return `<a href="${URL}" class="${classes}" ${attributes}>${result.displayedTitle}</a>`;
+ return {url: URL, click: click, classes: classes, displayedTitle: result.displayedTitle};
},
get results() {
}
var res = this.miniSearch.search(this.query);
+
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-html="makeResultLink(result, 'text-2xl text-blue')"></div>
+ <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>
<p x-text="result.text" class="mt-2 line-clamp-1"></p>
</div>
</template>