keyboard config object support #405

This commit is contained in:
Hakim El Hattab 2013-06-16 11:49:51 -04:00
parent 7094f44eb9
commit 56595d65cf
2 changed files with 67 additions and 32 deletions

View File

@ -2098,40 +2098,75 @@ var Reveal = (function(){
// keyboard modifier key is present // keyboard modifier key is present
if( hasFocus || (event.shiftKey && event.keyCode !== 32) || event.altKey || event.ctrlKey || event.metaKey ) return; if( hasFocus || (event.shiftKey && event.keyCode !== 32) || event.altKey || event.ctrlKey || event.metaKey ) return;
var triggered = true; // While paused only allow "unpausing" keyboard events (b and .)
// while paused only allow "unpausing" keyboard events (b and .)
if( isPaused() && [66,190,191].indexOf( event.keyCode ) === -1 ) { if( isPaused() && [66,190,191].indexOf( event.keyCode ) === -1 ) {
return false; return false;
} }
switch( event.keyCode ) { var triggered = false;
// p, page up
case 80: case 33: navigatePrev(); break; // 1. User defined key bindings
// n, page down if( typeof config.keyboard === 'object' ) {
case 78: case 34: navigateNext(); break;
// h, left for( var key in config.keyboard ) {
case 72: case 37: navigateLeft(); break;
// l, right // Check if this binding matches the pressed key
case 76: case 39: navigateRight(); break; if( parseInt( key, 10 ) === event.keyCode ) {
// k, up
case 75: case 38: navigateUp(); break; var value = config.keyboard[ key ];
// j, down
case 74: case 40: navigateDown(); break; // Calback function
// home if( typeof value === 'function' ) {
case 36: slide( 0 ); break; value.apply( null, [ event ] );
// end }
case 35: slide( Number.MAX_VALUE ); break; // String shortcuts to reveal.js API
// space else if( typeof value === 'string' && typeof Reveal[ value ] === 'function' ) {
case 32: isOverview() ? deactivateOverview() : event.shiftKey ? navigatePrev() : navigateNext(); break; Reveal[ value ].call();
// return }
case 13: isOverview() ? deactivateOverview() : triggered = false; break;
// b, period, Logitech presenter tools "black screen" button triggered = true;
case 66: case 190: case 191: togglePause(); break;
// f }
case 70: enterFullscreen(); break;
default: }
triggered = false;
}
// 2. System defined key bindings
if( triggered === false ) {
// Assume true and try to prove false
triggered = true;
switch( event.keyCode ) {
// p, page up
case 80: case 33: navigatePrev(); break;
// n, page down
case 78: case 34: navigateNext(); break;
// h, left
case 72: case 37: navigateLeft(); break;
// l, right
case 76: case 39: navigateRight(); break;
// k, up
case 75: case 38: navigateUp(); break;
// j, down
case 74: case 40: navigateDown(); break;
// home
case 36: slide( 0 ); break;
// end
case 35: slide( Number.MAX_VALUE ); break;
// space
case 32: isOverview() ? deactivateOverview() : event.shiftKey ? navigatePrev() : navigateNext(); break;
// return
case 13: isOverview() ? deactivateOverview() : triggered = false; break;
// b, period, Logitech presenter tools "black screen" button
case 66: case 190: case 191: togglePause(); break;
// f
case 70: enterFullscreen(); break;
default:
triggered = false;
}
} }
// If the input resulted in a triggered action we should prevent // If the input resulted in a triggered action we should prevent

4
js/reveal.min.js vendored

File diff suppressed because one or more lines are too long