From 918c7ca85a60254606f1c12d2ae4336e5359c0bb Mon Sep 17 00:00:00 2001 From: saber-nyan Date: Wed, 15 May 2019 11:07:41 +0300 Subject: [PATCH] =?UTF-8?q?=D0=94=D0=BE=D0=B1=D0=B0=D0=B2=D0=B8=D0=BB=20?= =?UTF-8?q?=D1=85=D0=BE=D1=82=D0=BA=D0=B5=D0=B9=20=D0=B4=D0=BB=D1=8F=20?= =?UTF-8?q?=D0=BD=D0=B0=D0=B2=D0=B8=D0=B3=D0=B0=D1=86=D0=B8=D0=B8=20=D0=BC?= =?UTF-8?q?=D0=B5=D0=B6=D0=B4=D1=83=20=D1=81=D1=82=D1=80=D0=B8=D0=BC=D0=B0?= =?UTF-8?q?=D0=BC=D0=B8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/components/Sidebar.vue | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) diff --git a/src/components/Sidebar.vue b/src/components/Sidebar.vue index aa2d76f..71dac6f 100644 --- a/src/components/Sidebar.vue +++ b/src/components/Sidebar.vue @@ -28,6 +28,33 @@ export default { data: function () { return { streams: [], + navigationKeysCallback: (e) => { + if (e.key === 'ArrowUp') { + e.preventDefault(); + const index = this.$data.streams.findIndex(e => e.id === this.$props.streamId); + const newStream = this.$data.streams[index - 1]; + if (!newStream) return; + const newId = newStream.id; + this.$router.push({name: 'home', params: {servicePort: this.$props.servicePort, streamId: newId}}); + } else if (e.key === 'ArrowDown') { + e.preventDefault(); + const index = this.$data.streams.findIndex(e => e.id === this.$props.streamId); + const newStream = this.$data.streams[index + 1]; + if (!newStream) return; + const newId = newStream.id; + this.$router.push({name: 'home', params: {servicePort: this.$props.servicePort, streamId: newId}}); + } else if (e.key === 'Home') { + const newStream = this.$data.streams[0]; + if (!newStream) return; + const newId = newStream.id; + this.$router.push({name: 'home', params: {servicePort: this.$props.servicePort, streamId: newId}}); + } else if (e.key === 'End') { + const newStream = this.$data.streams[this.$data.streams.length - 1]; + if (!newStream) return; + const newId = newStream.id; + this.$router.push({name: 'home', params: {servicePort: this.$props.servicePort, streamId: newId}}); + } + }, } }, watch: { @@ -85,6 +112,12 @@ export default { }, }, components: {Stream, InfiniteLoading,}, + mounted() { + document.addEventListener('keyup', this.$data.navigationKeysCallback); + }, + beforeDestroy() { + document.removeEventListener('keyup', this.$data.navigationKeysCallback); + }, }