]> _ Git - odl.git/commitdiff
wip #5181 @0.5
authorvincent <vincent@enhydra.fr>
Sat, 26 Mar 2022 14:36:49 +0000 (15:36 +0100)
committervincent <vincent@enhydra.fr>
Sat, 26 Mar 2022 14:36:49 +0000 (15:36 +0100)
resources/js/search.js
resources/views/components/search.blade.php

index 311427e2615a5424e24a3cd2ee290b0d10e437cd..1e77fffcd5a89df7c832d5dbd07f8b9df77cb40c 100644 (file)
@@ -28,30 +28,23 @@ export default () => ({
         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;
     },
index 3b68a99776244f45655d10c8a054c4a3b1b69cdd..aa001f693d5911aea1e9ca5f31feaef1fa61023b 100644 (file)
             <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>