fix and tests for custom key bindings in help overlay
parent
aafb8769f9
commit
f04a00672c
|
@ -1,5 +1,5 @@
|
||||||
/*!
|
/*!
|
||||||
* reveal.js 4.0.0-dev (Mon May 11 2020)
|
* reveal.js 4.0.0-dev (Tue May 12 2020)
|
||||||
* https://revealjs.com
|
* https://revealjs.com
|
||||||
* MIT licensed
|
* MIT licensed
|
||||||
*
|
*
|
||||||
|
|
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
|
@ -122,6 +122,18 @@ export default class Keyboard {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
getShortcuts() {
|
||||||
|
|
||||||
|
return this.shortcuts;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
getBindings() {
|
||||||
|
|
||||||
|
return this.bindings;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Handler for the document level 'keypress' event.
|
* Handler for the document level 'keypress' event.
|
||||||
*
|
*
|
||||||
|
|
15
js/reveal.js
15
js/reveal.js
|
@ -712,15 +712,18 @@ export default function( revealElement, options ) {
|
||||||
|
|
||||||
let html = '<p class="title">Keyboard Shortcuts</p><br/>';
|
let html = '<p class="title">Keyboard Shortcuts</p><br/>';
|
||||||
|
|
||||||
|
let shortcuts = keyboard.getShortcuts(),
|
||||||
|
bindings = keyboard.getBindings();
|
||||||
|
|
||||||
html += '<table><th>KEY</th><th>ACTION</th>';
|
html += '<table><th>KEY</th><th>ACTION</th>';
|
||||||
for( let key in keyboard.shortcuts ) {
|
for( let key in shortcuts ) {
|
||||||
html += `<tr><td>${key}</td><td>${keyboard.shortcuts[ key ]}</td></tr>`;
|
html += `<tr><td>${key}</td><td>${shortcuts[ key ]}</td></tr>`;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Add custom key bindings that have associated descriptions
|
// Add custom key bindings that have associated descriptions
|
||||||
for( let binding in keyboard.registeredKeyBindings ) {
|
for( let binding in bindings ) {
|
||||||
if( keyboard.registeredKeyBindings[binding].key && keyboard.registeredKeyBindings[binding].description ) {
|
if( bindings[binding].key && bindings[binding].description ) {
|
||||||
html += `<tr><td>${keyboard.registeredKeyBindings[binding].key}</td><td>${keyboard.registeredKeyBindings[binding].description}</td></tr>`;
|
html += `<tr><td>${bindings[binding].key}</td><td>${bindings[binding].description}</td></tr>`;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -775,7 +778,7 @@ export default function( revealElement, options ) {
|
||||||
// property where 100x adds up to the correct height.
|
// property where 100x adds up to the correct height.
|
||||||
//
|
//
|
||||||
// https://css-tricks.com/the-trick-to-viewport-units-on-mobile/
|
// https://css-tricks.com/the-trick-to-viewport-units-on-mobile/
|
||||||
if( Device.isMobile ) {
|
if( Device.isMobile && !config.embedded ) {
|
||||||
document.documentElement.style.setProperty( '--vh', ( window.innerHeight * 0.01 ) + 'px' );
|
document.documentElement.style.setProperty( '--vh', ( window.innerHeight * 0.01 ) + 'px' );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -379,6 +379,31 @@
|
||||||
await test( '#/2/0/1', { h: 2, v: 0, f: 1 } ); // fragment
|
await test( '#/2/0/1', { h: 2, v: 0, f: 1 } ); // fragment
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// ---------------------------------------------------------------
|
||||||
|
// KEYBOARD TESTS
|
||||||
|
|
||||||
|
QUnit.module( 'Keyboard' );
|
||||||
|
|
||||||
|
QUnit.test( 'Add key bindings', function( assert ) {
|
||||||
|
var done = assert.async( 1 );
|
||||||
|
|
||||||
|
Reveal.addKeyBinding({keyCode: 88, key: 'X', description: 'X-SHORTCUT-X'}, function() {
|
||||||
|
assert.ok( true, 'callback triggered' );
|
||||||
|
done();
|
||||||
|
} );
|
||||||
|
|
||||||
|
Reveal.toggleHelp( true );
|
||||||
|
assert.ok( /X\-SHORTCUT\-X/.test( document.body.innerHTML ), 'binding is added to help overlay' );
|
||||||
|
Reveal.toggleHelp( false );
|
||||||
|
|
||||||
|
let event = new KeyboardEvent( 'keydown', { 'keyCode':88 } );
|
||||||
|
document.dispatchEvent( event );
|
||||||
|
|
||||||
|
Reveal.removeKeyBinding( 88 );
|
||||||
|
|
||||||
|
// should do nothing
|
||||||
|
document.dispatchEvent( event );
|
||||||
|
});
|
||||||
|
|
||||||
// ---------------------------------------------------------------
|
// ---------------------------------------------------------------
|
||||||
// FRAGMENT TESTS
|
// FRAGMENT TESTS
|
||||||
|
|
Loading…
Reference in New Issue