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