]> git.immae.eu Git - github/bastienwirtz/homer.git/blobdiff - app.js
Add keyboard shortcuts to navigate to the first search result.
[github/bastienwirtz/homer.git] / app.js
diff --git a/app.js b/app.js
index 36508abb694ef108fc0ecbfd552f3cda62a71f81..e79611069f9d779d4a09e969157ec805b0c24628 100644 (file)
--- a/app.js
+++ b/app.js
@@ -84,6 +84,26 @@ const app = new Vue({
         },
         toggleMenu: function() {
             this.showMenu = !this.showMenu;
+        },
+        matchesFilter: function(item) {
+            return (item.name.toLowerCase().includes(this.filter.toLowerCase())
+                || (item.tag && item.tag.toLowerCase().includes(this.filter.toLowerCase())))
+        },
+        firstMatchingService: function() {
+            for (group of this.config.services) {
+                for (item of group.items) {
+                    if (this.matchesFilter(item)) {
+                        return item;
+                    }
+                }
+            }
+            return null;
+        },
+        navigateToFirstService: function(target) {
+            service = this.firstMatchingService();
+            if (service) {
+                window.open(service.url, target || service.target || '_self');
+            }
         }
     },
     mounted() {