Merge pull request #274 from robinschneider/hotkey

Added custom hotkey support
This commit is contained in:
Bastien Wirtz 2021-10-25 04:46:58 -07:00 committed by GitHub
commit cf33747f42
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 18 additions and 3 deletions

View File

@ -19,6 +19,9 @@ logo: "assets/logo.png"
# icon: "fas fa-skull-crossbones" # icon: "fas fa-skull-crossbones"
header: true # Set to false to hide the header header: true # Set to false to hide the header
# Optional: Different hotkey for search, defaults to "/"
# hotkey:
# search: "Shift"
footer: '<p>Created with <span class="has-text-danger">❤️</span> with <a href="https://bulma.io/">bulma</a>, <a href="https://vuejs.org/">vuejs</a> & <a href="https://fontawesome.com/">font awesome</a> // Fork me on <a href="https://github.com/bastienwirtz/homer"><i class="fab fa-github-alt"></i></a></p>' # set false if you want to hide it. footer: '<p>Created with <span class="has-text-danger">❤️</span> with <a href="https://bulma.io/">bulma</a>, <a href="https://vuejs.org/">vuejs</a> & <a href="https://fontawesome.com/">font awesome</a> // Fork me on <a href="https://github.com/bastienwirtz/homer"><i class="fab fa-github-alt"></i></a></p>' # set false if you want to hide it.
columns: "3" # "auto" or number (must be a factor of 12: 1, 2, 3, 4, 6, 12) columns: "3" # "auto" or number (must be a factor of 12: 1, 2, 3, 4, 6, 12)

View File

@ -41,6 +41,7 @@
<SearchInput <SearchInput
class="navbar-item is-inline-block-mobile" class="navbar-item is-inline-block-mobile"
:hotkey=searchHotkey()
@input="filterServices" @input="filterServices"
@search-focus="showMenu = true" @search-focus="showMenu = true"
@search-open="navigateToFirstService" @search-open="navigateToFirstService"
@ -167,6 +168,11 @@ export default {
window.onhashchange = this.buildDashboard; window.onhashchange = this.buildDashboard;
}, },
methods: { methods: {
searchHotkey() {
if (this.config.hotkey && this.config.hotkey.search) {
return this.config.hotkey.search;
}
},
buildDashboard: async function () { buildDashboard: async function () {
const defaults = jsyaml.load(defaultConfig); const defaults = jsyaml.load(defaultConfig);
let config; let config;

View File

@ -15,10 +15,16 @@
<script> <script>
export default { export default {
name: "SearchInput", name: "SearchInput",
props: ["value"], props: {
value: String,
hotkey: {
type: String,
default: "/"
}
},
mounted() { mounted() {
this._keyListener = function (event) { this._keyListener = function (event) {
if (event.key === "/") { if (event.key === this.hotkey) {
event.preventDefault(); event.preventDefault();
this.focus(); this.focus();
} }
@ -28,7 +34,7 @@ export default {
}; };
document.addEventListener("keydown", this._keyListener.bind(this)); document.addEventListener("keydown", this._keyListener.bind(this));
// fill seach from get parameter. // fill search from get parameter.
const search = new URLSearchParams(window.location.search).get("search"); const search = new URLSearchParams(window.location.search).get("search");
if (search) { if (search) {
this.$refs.search.value = search; this.$refs.search.value = search;