aboutsummaryrefslogtreecommitdiff
path: root/js
diff options
context:
space:
mode:
authorHakim El Hattab <hakim.elhattab@gmail.com>2014-04-22 15:41:08 +0200
committerHakim El Hattab <hakim.elhattab@gmail.com>2014-04-22 15:41:08 +0200
commit343765b7ab1ce5392389063b0513ce54a0a76506 (patch)
tree4274438b90dfbd336b8debb89c75f4e1e362ff68 /js
parent5d39b5eabf97a39936c70558e836253f9bbca931 (diff)
downloadfreenode-live-2017-presentation-343765b7ab1ce5392389063b0513ce54a0a76506.tar
freenode-live-2017-presentation-343765b7ab1ce5392389063b0513ce54a0a76506.tar.gz
images with data-src attribute are now lazy-loaded #793
Diffstat (limited to 'js')
-rw-r--r--js/reveal.js34
1 files changed, 32 insertions, 2 deletions
diff --git a/js/reveal.js b/js/reveal.js
index 160b90f..524678d 100644
--- a/js/reveal.js
+++ b/js/reveal.js
@@ -1905,6 +1905,11 @@ var Reveal = (function(){
viewDistance = isOverview() ? 6 : 1;
}
+ // Limit view distance on weaker devices
+ if( isPrintingPDF() ) {
+ viewDistance = Number.MAX_VALUE;
+ }
+
for( var x = 0; x < horizontalSlidesLength; x++ ) {
var horizontalSlide = horizontalSlides[x];
@@ -1915,7 +1920,13 @@ var Reveal = (function(){
distanceX = Math.abs( ( indexh - x ) % ( horizontalSlidesLength - viewDistance ) ) || 0;
// Show the horizontal slide if it's within the view distance
- horizontalSlide.style.display = distanceX > viewDistance ? 'none' : 'block';
+ if( distanceX < viewDistance ) {
+ horizontalSlide.style.display = 'block';
+ loadSlide( horizontalSlide );
+ }
+ else {
+ horizontalSlide.style.display = 'none';
+ }
if( verticalSlidesLength ) {
@@ -1926,7 +1937,13 @@ var Reveal = (function(){
distanceY = x === indexh ? Math.abs( indexv - y ) : Math.abs( y - oy );
- verticalSlide.style.display = ( distanceX + distanceY ) > viewDistance ? 'none' : 'block';
+ if( distanceX + distanceY < viewDistance ) {
+ verticalSlide.style.display = 'block';
+ loadSlide( verticalSlide );
+ }
+ else {
+ verticalSlide.style.display = 'none';
+ }
}
}
@@ -2150,6 +2167,19 @@ var Reveal = (function(){
}
/**
+ * Loads any content that is set to load lazily (data-src)
+ * inside of the given slide.
+ */
+ function loadSlide( slide ) {
+
+ toArray( slide.querySelectorAll( 'img[data-src]' ) ).forEach( function( element ) {
+ element.setAttribute( 'src', element.getAttribute( 'data-src' ) );
+ element.removeAttribute( 'data-src' );
+ } );
+
+ }
+
+ /**
* Determine what available routes there are for navigation.
*
* @return {Object} containing four booleans: left/right/up/down