keyboard config object support #405
parent
7094f44eb9
commit
56595d65cf
41
js/reveal.js
41
js/reveal.js
|
@ -2098,13 +2098,46 @@ 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;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var triggered = false;
|
||||||
|
|
||||||
|
// 1. User defined key bindings
|
||||||
|
if( typeof config.keyboard === 'object' ) {
|
||||||
|
|
||||||
|
for( var key in config.keyboard ) {
|
||||||
|
|
||||||
|
// Check if this binding matches the pressed key
|
||||||
|
if( parseInt( key, 10 ) === event.keyCode ) {
|
||||||
|
|
||||||
|
var value = config.keyboard[ key ];
|
||||||
|
|
||||||
|
// Calback function
|
||||||
|
if( typeof value === 'function' ) {
|
||||||
|
value.apply( null, [ event ] );
|
||||||
|
}
|
||||||
|
// String shortcuts to reveal.js API
|
||||||
|
else if( typeof value === 'string' && typeof Reveal[ value ] === 'function' ) {
|
||||||
|
Reveal[ value ].call();
|
||||||
|
}
|
||||||
|
|
||||||
|
triggered = true;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
// 2. System defined key bindings
|
||||||
|
if( triggered === false ) {
|
||||||
|
|
||||||
|
// Assume true and try to prove false
|
||||||
|
triggered = true;
|
||||||
|
|
||||||
switch( event.keyCode ) {
|
switch( event.keyCode ) {
|
||||||
// p, page up
|
// p, page up
|
||||||
case 80: case 33: navigatePrev(); break;
|
case 80: case 33: navigatePrev(); break;
|
||||||
|
@ -2134,6 +2167,8 @@ var Reveal = (function(){
|
||||||
triggered = false;
|
triggered = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
// If the input resulted in a triggered action we should prevent
|
// If the input resulted in a triggered action we should prevent
|
||||||
// the browsers default behavior
|
// the browsers default behavior
|
||||||
if( triggered ) {
|
if( triggered ) {
|
||||||
|
|
File diff suppressed because one or more lines are too long
Loading…
Reference in New Issue