refactoring

This commit is contained in:
Hakim El Hattab
2020-03-10 20:40:35 +01:00
parent 3d6212378a
commit ac15678dea
5 changed files with 69 additions and 53 deletions

View File

@ -1,7 +1,7 @@
import { extend, toArray, enterFullscreen } from '../utils/util.js'
import { enterFullscreen } from '../utils/util.js'
/**
*
* Handles all reveal.js keyboard interactions.
*/
export default class Keyboard {
@ -21,30 +21,9 @@ export default class Keyboard {
}
refreshSortcuts() {
// Define our contextual list of keyboard shortcuts
if( this.Reveal.getConfig().navigationMode === 'linear' ) {
this.shortcuts['→ , ↓ , SPACE , N , L , J'] = 'Next slide';
this.shortcuts['← , ↑ , P , H , K'] = 'Previous slide';
}
else {
this.shortcuts['N , SPACE'] = 'Next slide';
this.shortcuts['P'] = 'Previous slide';
this.shortcuts['← , H'] = 'Navigate left';
this.shortcuts['→ , L'] = 'Navigate right';
this.shortcuts['↑ , K'] = 'Navigate up';
this.shortcuts['↓ , J'] = 'Navigate down';
}
this.shortcuts['Home , Shift ←'] = 'First slide';
this.shortcuts['End , Shift →'] = 'Last slide';
this.shortcuts['B , .'] = 'Pause';
this.shortcuts['F'] = 'Fullscreen';
this.shortcuts['ESC, O'] = 'Slide overview';
}
/**
* Starts listening for keyboard events.
*/
bind() {
document.addEventListener( 'keydown', this.onDocumentKeyDown, false );
@ -52,6 +31,9 @@ export default class Keyboard {
}
/**
* Stops listening for keyboard events.
*/
unbind() {
document.removeEventListener( 'keydown', this.onDocumentKeyDown, false );
@ -91,6 +73,32 @@ export default class Keyboard {
}
/**
* Updates our keyboard shortcuts based on current settings.
*/
refreshSortcuts() {
if( this.Reveal.getConfig().navigationMode === 'linear' ) {
this.shortcuts['→ , ↓ , SPACE , N , L , J'] = 'Next slide';
this.shortcuts['← , ↑ , P , H , K'] = 'Previous slide';
}
else {
this.shortcuts['N , SPACE'] = 'Next slide';
this.shortcuts['P'] = 'Previous slide';
this.shortcuts['← , H'] = 'Navigate left';
this.shortcuts['→ , L'] = 'Navigate right';
this.shortcuts['↑ , K'] = 'Navigate up';
this.shortcuts['↓ , J'] = 'Navigate down';
}
this.shortcuts['Home , Shift ←'] = 'First slide';
this.shortcuts['End , Shift →'] = 'Last slide';
this.shortcuts['B , .'] = 'Pause';
this.shortcuts['F'] = 'Fullscreen';
this.shortcuts['ESC, O'] = 'Slide overview';
}
/**
* Programmatically triggers a keyboard event
*