Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Keyboard shortcuts overlay on pressing question mark #943

Merged
merged 5 commits into from
Jun 9, 2014
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 33 additions & 0 deletions css/reveal.css
Original file line number Diff line number Diff line change
Expand Up @@ -1742,6 +1742,39 @@ body {
}


.reveal .preview-link-overlay .viewport .shortcuts {
-webkit-column-count: 2;
-moz-column-count: 2;
column-count: 2;
font-size: 20px;
height: 100%;
margin-left: 35%;
margin-top: 20px;
text-align: center;
}

.reveal .preview-link-overlay .viewport .shortcuts table {
border: 1px solid #fff;
border-collapse: collapse;
font-size: 14px;
}

.reveal .preview-link-overlay .viewport .shortcuts table th{
border: 1px solid #fff;
height: 30px;
width: 200px;
padding: 10px;
vertical-align: middle;
}

.reveal .preview-link-overlay .viewport .shortcuts table tr td{
border: 1px solid #fff;
height: 30px;
vertical-align: middle;
padding: 5px;
}



/*********************************************
* PLAYBACK COMPONENT
Expand Down
65 changes: 65 additions & 0 deletions js/reveal.js
Original file line number Diff line number Diff line change
Expand Up @@ -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'
};

/**
Expand Down Expand Up @@ -836,6 +850,7 @@

if( config.keyboard ) {
document.addEventListener( 'keydown', onDocumentKeyDown, false );
document.addEventListener( 'keypress', onDocumentKeyPress, false );
}

if( config.progress && dom.progress ) {
Expand Down Expand Up @@ -879,6 +894,7 @@
eventsAreBound = false;

document.removeEventListener( 'keydown', onDocumentKeyDown, false );
document.removeEventListener( 'keypress', onDocumentKeyPress, false );
window.removeEventListener( 'hashchange', onWindowHashChange, false );
window.removeEventListener( 'resize', onWindowResize, false );

Expand Down Expand Up @@ -1241,6 +1257,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.
Expand Down Expand Up @@ -3195,6 +3249,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.
*/
Expand Down