Merge branch 'keyboard_shortcuts_overlay' of https://github.com/navateja/reveal.js into dev
This commit is contained in:
		
							
								
								
									
										65
									
								
								js/reveal.js
									
									
									
									
									
								
							
							
						
						
									
										65
									
								
								js/reveal.js
									
									
									
									
									
								
							@@ -196,6 +196,20 @@
 | 
			
		||||
			startCount: 0,
 | 
			
		||||
			captured: false,
 | 
			
		||||
			threshold: 40
 | 
			
		||||
		},
 | 
			
		||||
 | 
			
		||||
		// Holds information about the keyboard shortcuts
 | 
			
		||||
		keyboard_shortcuts = {
 | 
			
		||||
			'p': 'Previous slide',
 | 
			
		||||
			'n': 'Next slide',
 | 
			
		||||
			'h': 'Navigate left',
 | 
			
		||||
			'l': 'Navigate right',
 | 
			
		||||
			'k': 'Navigate up',
 | 
			
		||||
			'j': 'Navigate down',
 | 
			
		||||
			'Home': 'First slide',
 | 
			
		||||
			'End': 'Last slide',
 | 
			
		||||
			'b': 'Pause',
 | 
			
		||||
			'f': 'Fullscreen'
 | 
			
		||||
		};
 | 
			
		||||
 | 
			
		||||
	/**
 | 
			
		||||
@@ -863,6 +877,7 @@
 | 
			
		||||
 | 
			
		||||
		if( config.keyboard ) {
 | 
			
		||||
			document.addEventListener( 'keydown', onDocumentKeyDown, false );
 | 
			
		||||
			document.addEventListener( 'keypress', onDocumentKeyPress, false );
 | 
			
		||||
		}
 | 
			
		||||
 | 
			
		||||
		if( config.progress && dom.progress ) {
 | 
			
		||||
@@ -906,6 +921,7 @@
 | 
			
		||||
		eventsAreBound = false;
 | 
			
		||||
 | 
			
		||||
		document.removeEventListener( 'keydown', onDocumentKeyDown, false );
 | 
			
		||||
		document.removeEventListener( 'keypress', onDocumentKeyPress, false );
 | 
			
		||||
		window.removeEventListener( 'hashchange', onWindowHashChange, false );
 | 
			
		||||
		window.removeEventListener( 'resize', onWindowResize, false );
 | 
			
		||||
 | 
			
		||||
@@ -1268,6 +1284,44 @@
 | 
			
		||||
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	/**
 | 
			
		||||
	 * Opens a overlay window for the keyboard shortcuts.
 | 
			
		||||
	 */
 | 
			
		||||
	function openShortcutsOverlay() {
 | 
			
		||||
 | 
			
		||||
		closePreview();
 | 
			
		||||
 | 
			
		||||
		dom.preview = document.createElement( 'div' );
 | 
			
		||||
		dom.preview.classList.add( 'preview-link-overlay' );
 | 
			
		||||
		dom.wrapper.appendChild( dom.preview );
 | 
			
		||||
 | 
			
		||||
		var html = '<h5>Keyboard Shortcuts</h5><br/>';
 | 
			
		||||
		html += '<table> <th>KEY</th> <th>ACTION</th>';
 | 
			
		||||
		for( var key in keyboard_shortcuts ) {
 | 
			
		||||
			html += '<tr> <td>' + key + '</td> <td>' + keyboard_shortcuts[key] + '</td> </tr>'
 | 
			
		||||
		}
 | 
			
		||||
		html += '</table>';
 | 
			
		||||
 | 
			
		||||
		dom.preview.innerHTML = [
 | 
			
		||||
			'<header>',
 | 
			
		||||
				'<a class="close" href="#"><span class="icon"></span></a>',
 | 
			
		||||
			'</header>',
 | 
			
		||||
			'<div class="viewport">',
 | 
			
		||||
				'<div class="shortcuts">'+html+'</div>',
 | 
			
		||||
			'</div>'
 | 
			
		||||
		].join('');
 | 
			
		||||
 | 
			
		||||
		dom.preview.querySelector( '.close' ).addEventListener( 'click', function( event ) {
 | 
			
		||||
			closePreview();
 | 
			
		||||
			event.preventDefault();
 | 
			
		||||
		}, false );
 | 
			
		||||
 | 
			
		||||
		setTimeout( function() {
 | 
			
		||||
			dom.preview.classList.add( 'visible' );
 | 
			
		||||
		}, 1 );
 | 
			
		||||
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	/**
 | 
			
		||||
	 * Applies JavaScript-controlled layout rules to the
 | 
			
		||||
	 * presentation.
 | 
			
		||||
@@ -3232,6 +3286,17 @@
 | 
			
		||||
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	/**
 | 
			
		||||
	 * Handler for the document level 'keypress' event.
 | 
			
		||||
	 */
 | 
			
		||||
 | 
			
		||||
	function onDocumentKeyPress( event ) {
 | 
			
		||||
		// Check if the pressed key is question mark
 | 
			
		||||
		if( event.shiftKey && event.charCode == 63 ) {
 | 
			
		||||
			openShortcutsOverlay();
 | 
			
		||||
		}
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	/**
 | 
			
		||||
	 * Handler for the document level 'keydown' event.
 | 
			
		||||
	 */
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user