mirror of
https://github.com/hakimel/reveal.js.git
synced 2025-10-29 04:40:02 +01:00
refactor hash parsing, fixes issue with autoplaying media not starting from internal links on mobile devices
This commit is contained in:
28
js/reveal.js
28
js/reveal.js
@@ -529,6 +529,7 @@ export default function( revealElement, options ) {
|
||||
controls.bind();
|
||||
focus.bind();
|
||||
|
||||
dom.slides.addEventListener( 'click', onSlidesClicked, false );
|
||||
dom.slides.addEventListener( 'transitionend', onTransitionEnd, false );
|
||||
dom.pauseOverlay.addEventListener( 'click', resume, false );
|
||||
|
||||
@@ -554,6 +555,7 @@ export default function( revealElement, options ) {
|
||||
|
||||
window.removeEventListener( 'resize', onWindowResize, false );
|
||||
|
||||
dom.slides.removeEventListener( 'click', onSlidesClicked, false );
|
||||
dom.slides.removeEventListener( 'transitionend', onTransitionEnd, false );
|
||||
dom.pauseOverlay.removeEventListener( 'click', resume, false );
|
||||
|
||||
@@ -2374,6 +2376,32 @@ export default function( revealElement, options ) {
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* A global listener for all click events inside of the
|
||||
* .slides container.
|
||||
*
|
||||
* @param {object} [event]
|
||||
*/
|
||||
function onSlidesClicked( event ) {
|
||||
|
||||
// If a hash link is clicked, we find the target slide
|
||||
// and navigate to it. We previously relied on 'hashchange'
|
||||
// for links like these but that prevented media with
|
||||
// audio tracks from playing in mobile browsers since it
|
||||
// wasn't considered a direct interaction with the document.
|
||||
if( event.target.nodeName === 'A' ) {
|
||||
const hash = event.target.getAttribute( 'href' );
|
||||
if( /^#/.test( hash ) ) {
|
||||
const indices = location.getIndicesFromHash( hash );
|
||||
if( indices ) {
|
||||
Reveal.slide( indices.h, indices.v, indices.f );
|
||||
event.preventDefault();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Handler for the window level 'resize' event.
|
||||
*
|
||||
|
||||
Reference in New Issue
Block a user