Explorar o código

fix and tests for custom key bindings in help overlay

Hakim El Hattab %!s(int64=5) %!d(string=hai) anos
pai
achega
f04a00672c
Modificáronse 6 ficheiros con 49 adicións e 9 borrados
  1. 1 1
      dist/reveal.css
  2. 1 1
      dist/reveal.esm.js
  3. 1 1
      dist/reveal.js
  4. 12 0
      js/controllers/keyboard.js
  5. 9 6
      js/reveal.js
  6. 25 0
      test/test.html

+ 1 - 1
dist/reveal.css

@@ -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
 * MIT licensed
 *

A diferenza do arquivo foi suprimida porque é demasiado grande
+ 1 - 1
dist/reveal.esm.js


A diferenza do arquivo foi suprimida porque é demasiado grande
+ 1 - 1
dist/reveal.js


+ 12 - 0
js/controllers/keyboard.js

@@ -122,6 +122,18 @@ export default class Keyboard {
 
 	}
 
+	getShortcuts() {
+
+		return this.shortcuts;
+
+	}
+
+	getBindings() {
+
+		return this.bindings;
+
+	}
+
 	/**
 	 * Handler for the document level 'keypress' event.
 	 *

+ 9 - 6
js/reveal.js

@@ -712,15 +712,18 @@ export default function( revealElement, options ) {
 
 			let html = '<p class="title">Keyboard Shortcuts</p><br/>';
 
+			let shortcuts = keyboard.getShortcuts(),
+				bindings = keyboard.getBindings();
+
 			html += '<table><th>KEY</th><th>ACTION</th>';
-			for( let key in keyboard.shortcuts ) {
-				html += `<tr><td>${key}</td><td>${keyboard.shortcuts[ key ]}</td></tr>`;
+			for( let key in shortcuts ) {
+				html += `<tr><td>${key}</td><td>${shortcuts[ key ]}</td></tr>`;
 			}
 
 			// Add custom key bindings that have associated descriptions
-			for( let binding in keyboard.registeredKeyBindings ) {
-				if( keyboard.registeredKeyBindings[binding].key && keyboard.registeredKeyBindings[binding].description ) {
-					html += `<tr><td>${keyboard.registeredKeyBindings[binding].key}</td><td>${keyboard.registeredKeyBindings[binding].description}</td></tr>`;
+			for( let binding in bindings ) {
+				if( bindings[binding].key && bindings[binding].description ) {
+					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.
 				//
 				// 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' );
 				}
 

+ 25 - 0
test/test.html

@@ -379,6 +379,31 @@
 					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

Algúns arquivos non se mostraron porque demasiados arquivos cambiaron neste cambio