X-Git-Url: https://git.immae.eu/?a=blobdiff_plain;f=app.js;h=36508abb694ef108fc0ecbfd552f3cda62a71f81;hb=6eba37a370cdd3c0275d49fa693ab189d8ab8ff2;hp=6c8307436749b5a33e039aafefc5aaed994b6805;hpb=2cf93f388130134d8ff9cf1af7535e21cafc207f;p=github%2Fbastienwirtz%2Fhomer.git 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({ toggleMenu: function() { 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); } });