X-Git-Url: https://git.immae.eu/?a=blobdiff_plain;f=app.js;h=e79611069f9d779d4a09e969157ec805b0c24628;hb=94f44a4fe822cb3c799fb34b880a9e462b5c9ed0;hp=a2960690a88072846cde77e93179307251c5f0ee;hpb=7cc525b2a65ce07a340562864682e663ab46bb84;p=github%2Fbastienwirtz%2Fhomer.git diff --git a/app.js b/app.js index a296069..e796110 100644 --- a/app.js +++ b/app.js @@ -21,6 +21,7 @@ const app = new Vue({ this.checkOffline(); try { this.config = await this.getConfig(); + document.title = this.config.title + ' | Homer'; } catch (error) { this.offline = true; } @@ -83,7 +84,56 @@ 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() { + 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); } });