1
0
mirror of https://github.com/webslides/WebSlides.git synced 2025-08-20 11:51:40 +02:00

Moving plugins, adding Keyboard integration

This commit is contained in:
Antonio Laguna
2017-01-28 17:17:10 +01:00
parent 0e02056ca7
commit b99fdc8c47
6 changed files with 58 additions and 3 deletions

View File

@@ -1,4 +1,4 @@
import Plugins from './plugins'; import Plugins from '../plugins/plugins';
import Slide from './slide'; import Slide from './slide';
import DOM from '../utils/dom'; import DOM from '../utils/dom';
import ScrollHelper from '../utils/scroll-to'; import ScrollHelper from '../utils/scroll-to';
@@ -9,7 +9,8 @@ const CLASSES = {
const PLUGINS = { const PLUGINS = {
'nav': Plugins.Navigation, 'nav': Plugins.Navigation,
'hash': Plugins.Hash 'hash': Plugins.Hash,
'keyboard': Plugins.Keyboard
}; };
export default class WebSlides { export default class WebSlides {

42
src/plugins/keyboard.js Normal file
View File

@@ -0,0 +1,42 @@
import Keys from '../utils/keys';
export default class Keyboard {
/**
* @param {WebSlides} wsInstance The WebSlides instance
*/
constructor(wsInstance) {
/**
* @type {WebSlides}
* @private
*/
this.ws_ = wsInstance;
document.addEventListener("keydown", this.onKeyPress_.bind(this), false);
}
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;
}
}
}
if (method) {
method.call(this.ws_);
}
}
}

View File

@@ -1,7 +1,9 @@
import Navigation from './navigation'; import Navigation from './navigation';
import Hash from './hash'; import Hash from './hash';
import Keyboard from './keyboard';
export default { export default {
Navigation, Navigation,
Hash Hash,
Keyboard
}; };

10
src/utils/keys.js Normal file
View File

@@ -0,0 +1,10 @@
const Keys = {
ENTER: 13,
SPACE: 32,
LEFT: 37,
UP: 38,
RIGHT: 39,
DOWN: 40
};
export default Keys;