From 8ae6954e5fd0fa03f6402c0a7f68fc14d0e3e9fd Mon Sep 17 00:00:00 2001 From: Antonio Laguna Date: Wed, 1 Mar 2017 13:56:11 +0100 Subject: [PATCH] Allowing to navigate with re/av page Fixes #48 --- src/js/plugins/keyboard.js | 36 ++++++++++++++++++++---------------- src/js/utils/keys.js | 2 ++ 2 files changed, 22 insertions(+), 16 deletions(-) diff --git a/src/js/plugins/keyboard.js b/src/js/plugins/keyboard.js index 20f473d..52a2768 100644 --- a/src/js/plugins/keyboard.js +++ b/src/js/plugins/keyboard.js @@ -24,22 +24,26 @@ export default class Keyboard { onKeyPress_(event) { let method; - if (event.which === Keys.SPACE) { - method = this.ws_.goNext; - } else { - if (this.ws_.isVertical) { - if (event.which === Keys.DOWN) { - method = this.ws_.goNext; - } else if (event.which === Keys.UP) { - method = this.ws_.goPrev; - } - } else { - if (event.which === Keys.RIGHT) { - method = this.ws_.goNext; - } else if (event.which === Keys.LEFT) { - method = this.ws_.goPrev; - } - } + switch (event.which) { + case Keys.AV_PAGE: + case Keys.SPACE: + method = this.ws_.goNext; + break; + case Keys.RE_PAGE: + method = this.ws_.goPrev; + break; + case Keys.DOWN: + method = this.ws_.isVertical ? this.ws_.goNext : null; + break; + case Keys.UP: + method = this.ws_.isVertical ? this.ws_.goPrev : null; + break; + case Keys.LEFT: + method = !this.ws_.isVertical ? this.ws_.goPrev : null; + break; + case Keys.RIGHT: + method = !this.ws_.isVertical ? this.ws_.goNext : null; + break; } if (method) { diff --git a/src/js/utils/keys.js b/src/js/utils/keys.js index 02c5a4a..628e40d 100644 --- a/src/js/utils/keys.js +++ b/src/js/utils/keys.js @@ -1,6 +1,8 @@ const Keys = { ENTER: 13, SPACE: 32, + RE_PAGE: 33, + AV_PAGE: 34, LEFT: 37, UP: 38, RIGHT: 39,