App-revealup

 view release on metacpan or  search on metacpan

share/revealjs/js/controllers/keyboard.js  view on Meta::CPAN

import { enterFullscreen } from '../utils/util.js'

/**
 * Handles all reveal.js keyboard interactions.
 */
export default class Keyboard {

	constructor( Reveal ) {

		this.Reveal = Reveal;

		// A key:value map of keyboard keys and descriptions of
		// the actions they trigger
		this.shortcuts = {};

		// Holds custom key code mappings
		this.bindings = {};

		this.onDocumentKeyDown = this.onDocumentKeyDown.bind( this );
		this.onDocumentKeyPress = this.onDocumentKeyPress.bind( this );

	}

	/**
	 * Called when the reveal.js config is updated.
	 */
	configure( config, oldConfig ) {

		if( config.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  ,  Shift SPACE']             = 'Previous slide';
			this.shortcuts['←  ,  H'] = 'Navigate left';
			this.shortcuts['→  ,  L'] = 'Navigate right';
			this.shortcuts['↑  ,  K'] = 'Navigate up';
			this.shortcuts['↓  ,  J'] = 'Navigate down';
		}

		this.shortcuts['Alt + ←/&#8593/→/↓']        = 'Navigate without fragments';
		this.shortcuts['Shift + ←/&#8593/→/↓']      = 'Jump to first/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 );
		document.addEventListener( 'keypress', this.onDocumentKeyPress, false );

	}

	/**
	 * Stops listening for keyboard events.
	 */
	unbind() {

		document.removeEventListener( 'keydown', this.onDocumentKeyDown, false );
		document.removeEventListener( 'keypress', this.onDocumentKeyPress, false );

	}

	/**
	 * Add a custom key binding with optional description to
	 * be added to the help screen.
	 */
	addKeyBinding( binding, callback ) {

		if( typeof binding === 'object' && binding.keyCode ) {
			this.bindings[binding.keyCode] = {
				callback: callback,
				key: binding.key,
				description: binding.description
			};
		}
		else {
			this.bindings[binding] = {
				callback: callback,



( run in 0.453 second using v1.01-cache-2.11-cpan-13bb782fe5a )