forked from extern/homer
Merge pull request #36 from jozefs/keyboard-shortcuts
Add keyboard shortcuts for searching
This commit is contained in:
commit
990b6c3d46
29
app.js
29
app.js
@ -85,6 +85,35 @@ const app = new Vue({
|
|||||||
toggleMenu: function() {
|
toggleMenu: function() {
|
||||||
this.showMenu = !this.showMenu;
|
this.showMenu = !this.showMenu;
|
||||||
}
|
}
|
||||||
|
},
|
||||||
|
mounted() {
|
||||||
|
function isSmallScreen() {
|
||||||
|
return window.matchMedia('screen and (max-width: 1023px)').matches;
|
||||||
|
}
|
||||||
|
this._keyListener = function(e) {
|
||||||
|
if (e.key === '/') {
|
||||||
|
if (isSmallScreen()) {
|
||||||
|
this.showMenu = true;
|
||||||
|
}
|
||||||
|
Vue.nextTick(() => {
|
||||||
|
this.$refs.search.focus();
|
||||||
|
});
|
||||||
|
|
||||||
|
e.preventDefault();
|
||||||
|
}
|
||||||
|
if (e.key === 'Escape') {
|
||||||
|
this.filter = '';
|
||||||
|
this.$refs.search.blur();
|
||||||
|
if (isSmallScreen()) {
|
||||||
|
this.showMenu = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
document.addEventListener('keydown', this._keyListener.bind(this));
|
||||||
|
},
|
||||||
|
beforeDestroy() {
|
||||||
|
document.removeEventListener('keydown', this._keyListener);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -59,7 +59,7 @@
|
|||||||
:class="['fas', vlayout ? 'fa-list' : 'fa-columns']"></i></a>
|
:class="['fas', vlayout ? 'fa-list' : 'fa-columns']"></i></a>
|
||||||
<div class="search-bar">
|
<div class="search-bar">
|
||||||
<label for="search" class="search-label"></label>
|
<label for="search" class="search-label"></label>
|
||||||
<input type="text" id="search" v-model="filter" />
|
<input type="text" id="search" ref="search" v-model="filter" />
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
Loading…
Reference in New Issue
Block a user