aboutsummaryrefslogtreecommitdiffhomepage
path: root/app.js
diff options
context:
space:
mode:
Diffstat (limited to 'app.js')
-rw-r--r--app.js49
1 files changed, 49 insertions, 0 deletions
diff --git a/app.js b/app.js
index 6c83074..e796110 100644
--- a/app.js
+++ b/app.js
@@ -84,7 +84,56 @@ const app = new Vue({
84 }, 84 },
85 toggleMenu: function() { 85 toggleMenu: function() {
86 this.showMenu = !this.showMenu; 86 this.showMenu = !this.showMenu;
87 },
88 matchesFilter: function(item) {
89 return (item.name.toLowerCase().includes(this.filter.toLowerCase())
90 || (item.tag && item.tag.toLowerCase().includes(this.filter.toLowerCase())))
91 },
92 firstMatchingService: function() {
93 for (group of this.config.services) {
94 for (item of group.items) {
95 if (this.matchesFilter(item)) {
96 return item;
97 }
98 }
99 }
100 return null;
101 },
102 navigateToFirstService: function(target) {
103 service = this.firstMatchingService();
104 if (service) {
105 window.open(service.url, target || service.target || '_self');
106 }
107 }
108 },
109 mounted() {
110 function isSmallScreen() {
111 return window.matchMedia('screen and (max-width: 1023px)').matches;
87 } 112 }
113 this._keyListener = function(e) {
114 if (e.key === '/') {
115 if (isSmallScreen()) {
116 this.showMenu = true;
117 }
118 Vue.nextTick(() => {
119 this.$refs.search.focus();
120 });
121
122 e.preventDefault();
123 }
124 if (e.key === 'Escape') {
125 this.filter = '';
126 this.$refs.search.blur();
127 if (isSmallScreen()) {
128 this.showMenu = false;
129 }
130 }
131 }
132
133 document.addEventListener('keydown', this._keyListener.bind(this));
134 },
135 beforeDestroy() {
136 document.removeEventListener('keydown', this._keyListener);
88 } 137 }
89}); 138});
90 139