merge and tweak key shortcuts overlay #943
This commit is contained in:
parent
d539c645c3
commit
9ff00a72ae
File diff suppressed because one or more lines are too long
109
js/reveal.js
109
js/reveal.js
|
@ -199,13 +199,13 @@
|
||||||
},
|
},
|
||||||
|
|
||||||
// Holds information about the keyboard shortcuts
|
// Holds information about the keyboard shortcuts
|
||||||
keyboard_shortcuts = {
|
keyboardShortcuts = {
|
||||||
'p': 'Previous slide',
|
'P': 'Previous slide',
|
||||||
'n': 'Next slide',
|
'N': 'Next slide',
|
||||||
'h': 'Navigate left',
|
'H': 'Navigate left',
|
||||||
'l': 'Navigate right',
|
'L': 'Navigate right',
|
||||||
'k': 'Navigate up',
|
'K': 'Navigate up',
|
||||||
'j': 'Navigate down',
|
'J': 'Navigate down',
|
||||||
'Home': 'First slide',
|
'Home': 'First slide',
|
||||||
'End': 'Last slide',
|
'End': 'Last slide',
|
||||||
'b': 'Pause',
|
'b': 'Pause',
|
||||||
|
@ -1233,15 +1233,16 @@
|
||||||
/**
|
/**
|
||||||
* Opens a preview window for the target URL.
|
* Opens a preview window for the target URL.
|
||||||
*/
|
*/
|
||||||
function openPreview( url ) {
|
function showPreview( url ) {
|
||||||
|
|
||||||
closePreview();
|
closeOverlay();
|
||||||
|
|
||||||
dom.preview = document.createElement( 'div' );
|
dom.overlay = document.createElement( 'div' );
|
||||||
dom.preview.classList.add( 'preview-link-overlay' );
|
dom.overlay.classList.add( 'overlay' );
|
||||||
dom.wrapper.appendChild( dom.preview );
|
dom.overlay.classList.add( 'overlay-preview' );
|
||||||
|
dom.wrapper.appendChild( dom.overlay );
|
||||||
|
|
||||||
dom.preview.innerHTML = [
|
dom.overlay.innerHTML = [
|
||||||
'<header>',
|
'<header>',
|
||||||
'<a class="close" href="#"><span class="icon"></span></a>',
|
'<a class="close" href="#"><span class="icon"></span></a>',
|
||||||
'<a class="external" href="'+ url +'" target="_blank"><span class="icon"></span></a>',
|
'<a class="external" href="'+ url +'" target="_blank"><span class="icon"></span></a>',
|
||||||
|
@ -1252,76 +1253,79 @@
|
||||||
'</div>'
|
'</div>'
|
||||||
].join('');
|
].join('');
|
||||||
|
|
||||||
dom.preview.querySelector( 'iframe' ).addEventListener( 'load', function( event ) {
|
dom.overlay.querySelector( 'iframe' ).addEventListener( 'load', function( event ) {
|
||||||
dom.preview.classList.add( 'loaded' );
|
dom.overlay.classList.add( 'loaded' );
|
||||||
}, false );
|
}, false );
|
||||||
|
|
||||||
dom.preview.querySelector( '.close' ).addEventListener( 'click', function( event ) {
|
dom.overlay.querySelector( '.close' ).addEventListener( 'click', function( event ) {
|
||||||
closePreview();
|
closeOverlay();
|
||||||
event.preventDefault();
|
event.preventDefault();
|
||||||
}, false );
|
}, false );
|
||||||
|
|
||||||
dom.preview.querySelector( '.external' ).addEventListener( 'click', function( event ) {
|
dom.overlay.querySelector( '.external' ).addEventListener( 'click', function( event ) {
|
||||||
closePreview();
|
closeOverlay();
|
||||||
}, false );
|
}, false );
|
||||||
|
|
||||||
setTimeout( function() {
|
setTimeout( function() {
|
||||||
dom.preview.classList.add( 'visible' );
|
dom.overlay.classList.add( 'visible' );
|
||||||
}, 1 );
|
}, 1 );
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Closes the iframe preview window.
|
* Opens a overlay window with help material.
|
||||||
*/
|
*/
|
||||||
function closePreview() {
|
function showHelp() {
|
||||||
|
|
||||||
if( dom.preview ) {
|
closeOverlay();
|
||||||
dom.preview.setAttribute( 'src', '' );
|
|
||||||
dom.preview.parentNode.removeChild( dom.preview );
|
|
||||||
dom.preview = null;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
dom.overlay = document.createElement( 'div' );
|
||||||
|
dom.overlay.classList.add( 'overlay' );
|
||||||
|
dom.overlay.classList.add( 'overlay-help' );
|
||||||
|
dom.wrapper.appendChild( dom.overlay );
|
||||||
|
|
||||||
/**
|
var html = '<p class="title">Keyboard Shortcuts</p><br/>';
|
||||||
* 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>';
|
html += '<table><th>KEY</th><th>ACTION</th>';
|
||||||
for( var key in keyboard_shortcuts ) {
|
for( var key in keyboardShortcuts ) {
|
||||||
html += '<tr> <td>' + key + '</td> <td>' + keyboard_shortcuts[key] + '</td> </tr>'
|
html += '<tr><td>' + key + '</td><td>' + keyboardShortcuts[ key ] + '</td></tr>';
|
||||||
}
|
}
|
||||||
|
|
||||||
html += '</table>';
|
html += '</table>';
|
||||||
|
|
||||||
dom.preview.innerHTML = [
|
dom.overlay.innerHTML = [
|
||||||
'<header>',
|
'<header>',
|
||||||
'<a class="close" href="#"><span class="icon"></span></a>',
|
'<a class="close" href="#"><span class="icon"></span></a>',
|
||||||
'</header>',
|
'</header>',
|
||||||
'<div class="viewport">',
|
'<div class="viewport">',
|
||||||
'<div class="shortcuts">'+html+'</div>',
|
'<div class="viewport-inner">'+ html +'</div>',
|
||||||
'</div>'
|
'</div>'
|
||||||
].join('');
|
].join('');
|
||||||
|
|
||||||
dom.preview.querySelector( '.close' ).addEventListener( 'click', function( event ) {
|
dom.overlay.querySelector( '.close' ).addEventListener( 'click', function( event ) {
|
||||||
closePreview();
|
closeOverlay();
|
||||||
event.preventDefault();
|
event.preventDefault();
|
||||||
}, false );
|
}, false );
|
||||||
|
|
||||||
setTimeout( function() {
|
setTimeout( function() {
|
||||||
dom.preview.classList.add( 'visible' );
|
dom.overlay.classList.add( 'visible' );
|
||||||
}, 1 );
|
}, 1 );
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Closes any currently open overlay.
|
||||||
|
*/
|
||||||
|
function closeOverlay() {
|
||||||
|
|
||||||
|
if( dom.overlay ) {
|
||||||
|
dom.overlay.setAttribute( 'src', '' );
|
||||||
|
dom.overlay.parentNode.removeChild( dom.overlay );
|
||||||
|
dom.overlay = null;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Applies JavaScript-controlled layout rules to the
|
* Applies JavaScript-controlled layout rules to the
|
||||||
* presentation.
|
* presentation.
|
||||||
|
@ -3289,12 +3293,13 @@
|
||||||
/**
|
/**
|
||||||
* Handler for the document level 'keypress' event.
|
* Handler for the document level 'keypress' event.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
function onDocumentKeyPress( event ) {
|
function onDocumentKeyPress( event ) {
|
||||||
|
|
||||||
// Check if the pressed key is question mark
|
// Check if the pressed key is question mark
|
||||||
if( event.shiftKey && event.charCode == 63 ) {
|
if( event.shiftKey && event.charCode === 63 ) {
|
||||||
openShortcutsOverlay();
|
showHelp();
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -3402,8 +3407,8 @@
|
||||||
}
|
}
|
||||||
// ESC or O key
|
// ESC or O key
|
||||||
else if ( ( event.keyCode === 27 || event.keyCode === 79 ) && features.transforms3d ) {
|
else if ( ( event.keyCode === 27 || event.keyCode === 79 ) && features.transforms3d ) {
|
||||||
if( dom.preview ) {
|
if( dom.overlay ) {
|
||||||
closePreview();
|
closeOverlay();
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
toggleOverview();
|
toggleOverview();
|
||||||
|
@ -3701,7 +3706,7 @@
|
||||||
|
|
||||||
var url = event.target.getAttribute( 'href' );
|
var url = event.target.getAttribute( 'href' );
|
||||||
if( url ) {
|
if( url ) {
|
||||||
openPreview( url );
|
showPreview( url );
|
||||||
event.preventDefault();
|
event.preventDefault();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user