aboutsummaryrefslogtreecommitdiff
path: root/js/reveal.js
diff options
context:
space:
mode:
authorHakim El Hattab <hakim.elhattab@gmail.com>2013-10-10 09:14:35 -0400
committerHakim El Hattab <hakim.elhattab@gmail.com>2013-10-10 09:14:35 -0400
commita14386147812f487572066b1f8b69df6bff46d2e (patch)
tree87ab0d355cfd57959e8b8d37546acc668c3ef759 /js/reveal.js
parentac1dbd9d6158616756be54c5ad1bd91675004e39 (diff)
parent6043756b2e280f4488ecc22f5b81f12188eee851 (diff)
downloadfosdem-2018-presentation-a14386147812f487572066b1f8b69df6bff46d2e.tar
fosdem-2018-presentation-a14386147812f487572066b1f8b69df6bff46d2e.tar.gz
Merge branch 'focus-body-on-visibility-change' of https://github.com/rexxars/reveal.js into dev
Diffstat (limited to 'js/reveal.js')
-rw-r--r--js/reveal.js36
1 files changed, 35 insertions, 1 deletions
diff --git a/js/reveal.js b/js/reveal.js
index d3d6b23..600a763 100644
--- a/js/reveal.js
+++ b/js/reveal.js
@@ -80,6 +80,9 @@ var Reveal = (function(){
// Opens links in an iframe preview overlay
previewLinks: false,
+ // Focuses body when page changes visiblity to ensure keyboard shortcuts work
+ focusBodyOnPageVisiblityChange: true,
+
// Theme (see /css/theme)
theme: null,
@@ -606,10 +609,23 @@ var Reveal = (function(){
document.addEventListener( 'keydown', onDocumentKeyDown, false );
}
- if ( config.progress && dom.progress ) {
+ if( config.progress && dom.progress ) {
dom.progress.addEventListener( 'click', onProgressClicked, false );
}
+ if( config.focusBodyOnPageVisiblityChange ) {
+ var visibilityChange;
+ if ('hidden' in document) {
+ visibilityChange = 'visibilitychange';
+ } else if ('msHidden' in document) {
+ visibilityChange = 'msvisibilitychange';
+ } else if ('webkitHidden' in document) {
+ visibilityChange = 'webkitvisibilitychange';
+ }
+
+ document.addEventListener(visibilityChange, onPageVisibilityChange, false);
+ }
+
[ 'touchstart', 'click' ].forEach( function( eventName ) {
dom.controlsLeft.forEach( function( el ) { el.addEventListener( eventName, onNavigateLeftClicked, false ); } );
dom.controlsRight.forEach( function( el ) { el.addEventListener( eventName, onNavigateRightClicked, false ); } );
@@ -2656,6 +2672,24 @@ var Reveal = (function(){
}
/**
+ * Handle for the window level 'visibilitychange' event.
+ */
+ function onPageVisibilityChange( event ) {
+
+ var isHidden = document.webkitHidden ||
+ document.msHidden ||
+ document.hidden;
+
+ // If, after clicking a link or similar and we're coming back,
+ // focus the document.body to ensure we can use keyboard shortcuts
+ if( isHidden === false && document.activeElement !== document.body ) {
+ document.activeElement.blur();
+ document.body.focus();
+ }
+
+ }
+
+ /**
* Invoked when a slide is and we're in the overview.
*/
function onOverviewSlideClicked( event ) {