aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorBastien Wirtz <bastien.wirtz@gmail.com>2020-03-25 23:03:25 -0700
committerGitHub <noreply@github.com>2020-03-25 23:03:25 -0700
commit990b6c3d46bf45f62ec3c0f6602f26829b32d36c (patch)
treeae4b14056d97c82d8dbdfa7ff82a0f385c4c8157
parent4b87511f28b2d7b8b85bb07ffe6c9909c141acd6 (diff)
parent6eba37a370cdd3c0275d49fa693ab189d8ab8ff2 (diff)
downloadhomer-990b6c3d46bf45f62ec3c0f6602f26829b32d36c.tar.gz
homer-990b6c3d46bf45f62ec3c0f6602f26829b32d36c.tar.zst
homer-990b6c3d46bf45f62ec3c0f6602f26829b32d36c.zip
Merge pull request #36 from jozefs/keyboard-shortcuts
Add keyboard shortcuts for searching
-rw-r--r--app.js29
-rw-r--r--index.html2
2 files changed, 30 insertions, 1 deletions
diff --git a/app.js b/app.js
index 6c83074..36508ab 100644
--- a/app.js
+++ b/app.js
@@ -85,6 +85,35 @@ const app = new Vue({
85 toggleMenu: function() { 85 toggleMenu: function() {
86 this.showMenu = !this.showMenu; 86 this.showMenu = !this.showMenu;
87 } 87 }
88 },
89 mounted() {
90 function isSmallScreen() {
91 return window.matchMedia('screen and (max-width: 1023px)').matches;
92 }
93 this._keyListener = function(e) {
94 if (e.key === '/') {
95 if (isSmallScreen()) {
96 this.showMenu = true;
97 }
98 Vue.nextTick(() => {
99 this.$refs.search.focus();
100 });
101
102 e.preventDefault();
103 }
104 if (e.key === 'Escape') {
105 this.filter = '';
106 this.$refs.search.blur();
107 if (isSmallScreen()) {
108 this.showMenu = false;
109 }
110 }
111 }
112
113 document.addEventListener('keydown', this._keyListener.bind(this));
114 },
115 beforeDestroy() {
116 document.removeEventListener('keydown', this._keyListener);
88 } 117 }
89}); 118});
90 119
diff --git a/index.html b/index.html
index 9c1b531..85c9b78 100644
--- a/index.html
+++ b/index.html
@@ -59,7 +59,7 @@
59 :class="['fas', vlayout ? 'fa-list' : 'fa-columns']"></i></a> 59 :class="['fas', vlayout ? 'fa-list' : 'fa-columns']"></i></a>
60 <div class="search-bar"> 60 <div class="search-bar">
61 <label for="search" class="search-label"></label> 61 <label for="search" class="search-label"></label>
62 <input type="text" id="search" v-model="filter" /> 62 <input type="text" id="search" ref="search" v-model="filter" />
63 </div> 63 </div>
64 </div> 64 </div>
65 </div> 65 </div>