From f3f5d7780afda0e419a55e16cda522321b0e2c3e Mon Sep 17 00:00:00 2001 From: Hakim El Hattab Date: Tue, 4 Jun 2013 19:42:33 +0200 Subject: started the new per-slide background implementation (#453) --- js/reveal.js | 87 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 83 insertions(+), 4 deletions(-) (limited to 'js/reveal.js') diff --git a/js/reveal.js b/js/reveal.js index 4ff34c9..7d8020f 100644 --- a/js/reveal.js +++ b/js/reveal.js @@ -186,6 +186,13 @@ var Reveal = (function(){ dom.wrapper = document.querySelector( '.reveal' ); dom.slides = document.querySelector( '.reveal .slides' ); + // Background element + if( !document.querySelector( '.reveal .background' ) ) { + dom.background = document.createElement( 'div' ); + dom.background.classList.add( 'background' ); + dom.wrapper.appendChild( dom.background ); + } + // Progress bar if( !dom.wrapper.querySelector( '.progress' ) ) { var progressElement = document.createElement( 'div' ); @@ -205,11 +212,11 @@ var Reveal = (function(){ dom.wrapper.appendChild( controlsElement ); } - // Presentation background element + // State background element [DEPRECATED] if( !dom.wrapper.querySelector( '.state-background' ) ) { - var backgroundElement = document.createElement( 'div' ); - backgroundElement.classList.add( 'state-background' ); - dom.wrapper.appendChild( backgroundElement ); + var stateBackgroundElement = document.createElement( 'div' ); + stateBackgroundElement.classList.add( 'state-background' ); + dom.wrapper.appendChild( stateBackgroundElement ); } // Overlay graphic which is displayed during the paused mode @@ -237,6 +244,54 @@ var Reveal = (function(){ } + /** + * Creates the slide background elements and appends them + * to the background container. + */ + function createBackgrounds() { + + // Clear prior backgrounds + dom.background.innerHTML = ''; + + // Helper method for creating a background element for the + // given slide + function _createBackground( slide, container ) { + + var background = slide.getAttribute( 'data-background' ); + var element = document.createElement( 'div' ); + + if( background ) { + // Auto-wrap image urls in url(...) + if( /\.(png|jpg|jpeg|gif|bmp|)$/gi.test( background ) ) { + element.style.backgroundImage = 'url('+ background +')'; + } + else { + element.style.background = background; + } + } + + container.appendChild( element ); + + return element; + + } + + // Iterate over all horizontal slides + toArray( document.querySelectorAll( HORIZONTAL_SLIDES_SELECTOR ) ).forEach( function( slideh ) { + + var backgroundStack = _createBackground( slideh, dom.background ); + + // Iterate over all vertical slides + toArray( slideh.querySelectorAll( 'section' ) ).forEach( function( slidev ) { + + _createBackground( slidev, backgroundStack ); + + } ); + + } ); + + } + /** * Hides the address bar if we're on a mobile device. */ @@ -1173,6 +1228,7 @@ var Reveal = (function(){ updateControls(); updateProgress(); + updateBackground(); } @@ -1196,8 +1252,12 @@ var Reveal = (function(){ // Start auto-sliding if it's enabled cueAutoSlide(); + // Re-create the slide backgrounds + createBackgrounds(); + updateControls(); updateProgress(); + updateBackground(); } @@ -1402,6 +1462,25 @@ var Reveal = (function(){ } + /** + * + */ + function updateBackground() { + + toArray( dom.background.childNodes ).forEach( function( backgroundh, h ) { + + backgroundh.className = ( h < indexh ? 'past' : h > indexh ? 'future' : 'present' ); + + toArray( backgroundh.childNodes ).forEach( function( backgroundv, v ) { + + backgroundv.className = ( v < indexv ? 'past' : v > indexv ? 'future' : 'present' ); + + } ); + + } ); + + } + /** * Determine what available routes there are for navigation. * -- cgit v1.2.3