mirror of
https://github.com/webslides/WebSlides.git
synced 2025-08-21 04:12:01 +02:00
Moving plugins, adding Keyboard integration
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
import Plugins from './plugins';
|
||||
import Plugins from '../plugins/plugins';
|
||||
import Slide from './slide';
|
||||
import DOM from '../utils/dom';
|
||||
import ScrollHelper from '../utils/scroll-to';
|
||||
@@ -9,7 +9,8 @@ const CLASSES = {
|
||||
|
||||
const PLUGINS = {
|
||||
'nav': Plugins.Navigation,
|
||||
'hash': Plugins.Hash
|
||||
'hash': Plugins.Hash,
|
||||
'keyboard': Plugins.Keyboard
|
||||
};
|
||||
|
||||
export default class WebSlides {
|
||||
|
42
src/plugins/keyboard.js
Normal file
42
src/plugins/keyboard.js
Normal 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_);
|
||||
}
|
||||
}
|
||||
}
|
@@ -1,7 +1,9 @@
|
||||
import Navigation from './navigation';
|
||||
import Hash from './hash';
|
||||
import Keyboard from './keyboard';
|
||||
|
||||
export default {
|
||||
Navigation,
|
||||
Hash
|
||||
Hash,
|
||||
Keyboard
|
||||
};
|
10
src/utils/keys.js
Normal file
10
src/utils/keys.js
Normal file
@@ -0,0 +1,10 @@
|
||||
const Keys = {
|
||||
ENTER: 13,
|
||||
SPACE: 32,
|
||||
LEFT: 37,
|
||||
UP: 38,
|
||||
RIGHT: 39,
|
||||
DOWN: 40
|
||||
};
|
||||
|
||||
export default Keys;
|
Reference in New Issue
Block a user