From 64bff259ff040d74f0f9cf273eb7c16017e667f7 Mon Sep 17 00:00:00 2001 From: Book Pauk Date: Fri, 11 Jan 2019 01:53:45 +0700 Subject: [PATCH] =?UTF-8?q?=D0=94=D0=BE=D0=B1=D0=B0=D0=B2=D0=B8=D0=BB=20ke?= =?UTF-8?q?yHooks=20-=20=D0=BF=D0=B5=D1=80=D0=B5=D1=85=D0=B2=D0=B0=D1=82?= =?UTF-8?q?=20=D0=B8=20=D0=BF=D0=BE=D0=B4=D0=BF=D0=B8=D1=81=D0=BA=D1=83=20?= =?UTF-8?q?=D0=BD=D0=B0=20=D1=81=D0=BE=D0=B1=D1=8B=D1=82=D0=B8=D1=8F=20?= =?UTF-8?q?=D0=BA=D0=BB=D0=B0=D0=B2=D0=B8=D0=B0=D1=82=D1=83=D1=80=D1=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- client/components/App.vue | 31 ++++++++++++++++++++++++++--- client/components/Reader/Reader.vue | 10 ++++++++-- 2 files changed, 36 insertions(+), 5 deletions(-) diff --git a/client/components/App.vue b/client/components/App.vue index 8eb93ab2..640a47f3 100644 --- a/client/components/App.vue +++ b/client/components/App.vue @@ -50,7 +50,7 @@ import Component from 'vue-class-component'; export default @Component({ watch: { - rootRoute: function(newValue, oldValue) { + rootRoute: function(newValue) { if ((this.mode == 'reader' || this.mode == 'omnireader') && (newValue != '/reader')) { this.$router.replace('/reader'); } @@ -65,11 +65,36 @@ class App extends Vue { this.state = this.$store.state; this.uistate = this.$store.state.uistate; this.config = this.$store.state.config; + + //global keyHooks + this.keyHooks = []; + this.keyHook = (event) => { + for (const hook of this.keyHooks) + hook(event); + } + + this.$root.addKeyHook = (hook) => { + if (this.keyHooks.indexOf(hook) < 0) + this.keyHooks.push(hook); + } + + this.$root.removeKeyHook = (hook) => { + const i = this.keyHooks.indexOf(hook); + if (i >= 0) + this.keyHooks.splice(i, 1); + } + + document.addEventListener('keyup', (event) => { + this.keyHook(event); + }); + document.addEventListener('keydown', (event) => { + this.keyHook(event); + }); } mounted() { this.dispatch('config/loadConfig'); - this.$watch('apiError', function(newError, oldError) { + this.$watch('apiError', function(newError) { if (newError) { this.$notify.error({ title: 'Ошибка API', @@ -116,7 +141,7 @@ class App extends Vue { } get rootRoute() { - const m = this.$route.path.match(/^(\/[^\/]*).*$/i); + const m = this.$route.path.match(/^(\/[^/]*).*$/i); return (m ? m[1] : this.$route.path); } diff --git a/client/components/Reader/Reader.vue b/client/components/Reader/Reader.vue index 13ac53ce..ada6e0db 100644 --- a/client/components/Reader/Reader.vue +++ b/client/components/Reader/Reader.vue @@ -65,6 +65,8 @@ class Reader extends Vue { this.commit = this.$store.commit; this.dispatch = this.$store.dispatch; this.reader = this.$store.state.reader; + + this.$root.addKeyHook(this.keyHook); } get loaderActive() { @@ -98,11 +100,15 @@ class Reader extends Vue { result = 'LoaderPage'; if (!result) { - this.commit('reader/setLoaderActive', true); - result = 'LoaderPage'; + //this.commit('reader/setLoaderActive', true); + //result = 'LoaderPage'; } return result; } + + keyHook(event) { + //console.log(this.componentActive); + } } //----------------------------------------------------------------------------- //, .tool-button:focus, .tool-button:active, .tool-button:hover