From a4de4a3a71e460141b740564ef22d1c79760db4e Mon Sep 17 00:00:00 2001 From: Jozef Selesi Date: Thu, 26 Mar 2020 19:12:43 +0000 Subject: [PATCH] Add keyboard shortcuts to navigate to the first search result. --- README.md | 7 +++++++ app.js | 20 ++++++++++++++++++++ index.html | 8 +++++--- 3 files changed, 32 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 5ab7c26..f052fc9 100644 --- a/README.md +++ b/README.md @@ -3,6 +3,13 @@ A dead simple static **HOM**epage for your serv**ER** to keep your services on h **Check out the live demo [here](https://homer-demo.netlify.com/).** +It supports keyboard shortcuts: + +* `/` Start searching. +* `Escape` Stop searching. +* `Enter` Open the first matching result (respects the bookmark's `_target` property). +* `Alt`/`Option` + `Enter` Open the first matching result in a new tab. + If you need authentication support, you're on your own (it can be secured using a web server auth module or exposing it only through a VPN network / SSH tunnel, ...) ![screenshot](https://raw.github.com/bastienwirtz/homer/master/screenshot.png) diff --git a/app.js b/app.js index 36508ab..e796110 100644 --- 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() { diff --git a/index.html b/index.html index 85c9b78..d427002 100644 --- a/index.html +++ b/index.html @@ -59,7 +59,9 @@ :class="['fas', vlayout ? 'fa-list' : 'fa-columns']"> @@ -95,7 +97,7 @@ v-else># {{ group.name }} + v-if="!filter || (item && matchesFilter(item))"> @@ -106,7 +108,7 @@

# {{ group.name }}

+ v-if="!filter || (item && matchesFilter(item))"> -- 2.41.0