break showing/hiding of slides into separate methods

edit
Hakim El Hattab 2014-04-27 14:54:23 +02:00
parent eea437f4be
commit 902e36c022
1 changed files with 20 additions and 9 deletions

View File

@ -2029,11 +2029,10 @@ var Reveal = (function(){
// Show the horizontal slide if it's within the view distance // Show the horizontal slide if it's within the view distance
if( distanceX < viewDistance ) { if( distanceX < viewDistance ) {
horizontalSlide.style.display = 'block'; showSlide( horizontalSlide );
loadSlide( horizontalSlide );
} }
else { else {
horizontalSlide.style.display = 'none'; hideSlide( horizontalSlide );
} }
if( verticalSlidesLength ) { if( verticalSlidesLength ) {
@ -2046,11 +2045,10 @@ var Reveal = (function(){
distanceY = x === indexh ? Math.abs( indexv - y ) : Math.abs( y - oy ); distanceY = x === indexh ? Math.abs( indexv - y ) : Math.abs( y - oy );
if( distanceX + distanceY < viewDistance ) { if( distanceX + distanceY < viewDistance ) {
verticalSlide.style.display = 'block'; showSlide( verticalSlide );
loadSlide( verticalSlide );
} }
else { else {
verticalSlide.style.display = 'none'; hideSlide( verticalSlide );
} }
} }
@ -2275,10 +2273,13 @@ var Reveal = (function(){
} }
/** /**
* Loads any content that is set to load lazily (data-src) * Called when the given slide is within the configured view
* inside of the given slide. * distance. Shows the slide element and loads any content
* that is set to load lazily (data-src).
*/ */
function loadSlide( slide ) { function showSlide( slide ) {
slide.style.display = 'block';
// Media elements with data-src attributes // Media elements with data-src attributes
toArray( slide.querySelectorAll( 'img[data-src], video[data-src], audio[data-src], iframe[data-src]' ) ).forEach( function( element ) { toArray( slide.querySelectorAll( 'img[data-src], video[data-src], audio[data-src], iframe[data-src]' ) ).forEach( function( element ) {
@ -2305,6 +2306,16 @@ var Reveal = (function(){
} }
/**
* Called when the given slide is moved outside of the
* configured view distance.
*/
function hideSlide( slide ) {
slide.style.display = 'none';
}
/** /**
* Determine what available routes there are for navigation. * Determine what available routes there are for navigation.
* *