Ver código fonte

enable reveal.js keyboard shortcuts anywhere in notes window

Hakim El Hattab 10 anos atrás
pai
commit
1e5ca748a4
2 arquivos alterados com 19 adições e 0 exclusões
  1. 5 0
      js/reveal.js
  2. 14 0
      plugin/notes/notes.html

+ 5 - 0
js/reveal.js

@@ -3702,6 +3702,11 @@ var Reveal = (function(){
 			if( 'addEventListener' in window ) {
 				( dom.wrapper || document.querySelector( '.reveal' ) ).removeEventListener( type, listener, useCapture );
 			}
+		},
+
+		// Programatically triggers a keyboard event
+		triggerKey: function( keyCode ) {
+			onDocumentKeyDown( { keyCode: keyCode } );
 		}
 	};
 

+ 14 - 0
plugin/notes/notes.html

@@ -208,6 +208,7 @@
 						connected = true;
 
 						setupIframes( data );
+						setupKeyboard();
 						setupNotes();
 						setupTimer();
 					}
@@ -248,6 +249,19 @@
 				handleStateMessage = debounce( handleStateMessage, 200 );
 
 				/**
+				 * Forward keyboard events to the current slide window.
+				 * This enables keyboard events to work even if focus
+				 * isn't set on the current slide iframe.
+				 */
+				function setupKeyboard() {
+
+					document.addEventListener( 'keydown', function( event ) {
+						currentSlide.contentWindow.postMessage( JSON.stringify({ method: 'triggerKey', args: [ event.keyCode ] }), '*' );
+					} );
+
+				}
+
+				/**
 				 * Creates the preview iframes.
 				 */
 				function setupIframes( data ) {