From a03e8036289a49f0b4e0b43b1d8547f9ee439d42 Mon Sep 17 00:00:00 2001 From: Hakim El Hattab Date: Tue, 21 Nov 2017 15:38:44 +0100 Subject: make it possible to load/unload slides via the api --- js/reveal.js | 31 +++++++++++++++---------------- 1 file changed, 15 insertions(+), 16 deletions(-) (limited to 'js') diff --git a/js/reveal.js b/js/reveal.js index 72c4373..bf4194f 100644 --- a/js/reveal.js +++ b/js/reveal.js @@ -2748,10 +2748,10 @@ // Show the horizontal slide if it's within the view distance if( distanceX < viewDistance ) { - showSlide( horizontalSlide ); + loadSlide( horizontalSlide ); } else { - hideSlide( horizontalSlide ); + unloadSlide( horizontalSlide ); } if( verticalSlidesLength ) { @@ -2764,10 +2764,10 @@ distanceY = x === ( indexh || 0 ) ? Math.abs( ( indexv || 0 ) - y ) : Math.abs( y - oy ); if( distanceX + distanceY < viewDistance ) { - showSlide( verticalSlide ); + loadSlide( verticalSlide ); } else { - hideSlide( verticalSlide ); + unloadSlide( verticalSlide ); } } @@ -3166,14 +3166,9 @@ * * @param {HTMLElement} slide Slide to show */ - /** - * Called when the given slide is within the configured view - * distance. Shows the slide element and loads any content - * that is set to load lazily (data-src). - * - * @param {HTMLElement} slide Slide to show - */ - function showSlide( slide ) { + function loadSlide( slide, options ) { + + options = options || {}; // Show the slide element slide.style.display = config.display; @@ -3253,7 +3248,7 @@ background.appendChild( video ); } // Iframes - else if( backgroundIframe ) { + else if( backgroundIframe && options.excludeIframes !== true ) { var iframe = document.createElement( 'iframe' ); iframe.setAttribute( 'allowfullscreen', '' ); iframe.setAttribute( 'mozallowfullscreen', '' ); @@ -3282,12 +3277,12 @@ } /** - * Called when the given slide is moved outside of the - * configured view distance. + * Unloads and hides the given slide. This is called when the + * slide is moved outside of the configured view distance. * * @param {HTMLElement} slide */ - function hideSlide( slide ) { + function unloadSlide( slide ) { // Hide the slide element slide.style.display = 'none'; @@ -5117,6 +5112,10 @@ isAutoSliding: isAutoSliding, isSpeakerNotes: isSpeakerNotes, + // Slide preloading + loadSlide: loadSlide, + unloadSlide: unloadSlide, + // Adds or removes all internal event listeners (such as keyboard) addEventListeners: addEventListeners, removeEventListeners: removeEventListeners, -- cgit v1.2.3