new api method: getBackgroundSlide
This commit is contained in:
parent
1623b3782e
commit
eea437f4be
48
js/reveal.js
48
js/reveal.js
|
@ -2286,7 +2286,7 @@ var Reveal = (function(){
|
||||||
element.removeAttribute( 'data-src' );
|
element.removeAttribute( 'data-src' );
|
||||||
} );
|
} );
|
||||||
|
|
||||||
// Media elements with multiple <source>s
|
// Media elements with <source> children
|
||||||
toArray( slide.querySelectorAll( 'video, audio' ) ).forEach( function( media ) {
|
toArray( slide.querySelectorAll( 'video, audio' ) ).forEach( function( media ) {
|
||||||
var sources = 0;
|
var sources = 0;
|
||||||
|
|
||||||
|
@ -2634,6 +2634,38 @@ var Reveal = (function(){
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function getSlide( x, y ) {
|
||||||
|
|
||||||
|
var horizontalSlide = document.querySelectorAll( HORIZONTAL_SLIDES_SELECTOR )[ x ];
|
||||||
|
var verticalSlides = horizontalSlide && horizontalSlide.querySelectorAll( 'section' );
|
||||||
|
|
||||||
|
if( typeof y === 'number' ) {
|
||||||
|
return verticalSlides ? verticalSlides[ y ] : undefined;
|
||||||
|
}
|
||||||
|
|
||||||
|
return horizontalSlide;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns the background element for the given slide.
|
||||||
|
* All slides, even the ones with no background properties
|
||||||
|
* defined, have a background element so this never returns
|
||||||
|
* null.
|
||||||
|
*/
|
||||||
|
function getSlideBackground( x, y ) {
|
||||||
|
|
||||||
|
var horizontalBackground = document.querySelectorAll( '.backgrounds>.slide-background' )[ x ];
|
||||||
|
var verticalBackgrounds = horizontalBackground && horizontalBackground.querySelectorAll( '.slide-background' );
|
||||||
|
|
||||||
|
if( typeof y === 'number' ) {
|
||||||
|
return verticalBackgrounds ? verticalBackgrounds[ y ] : undefined;
|
||||||
|
}
|
||||||
|
|
||||||
|
return horizontalBackground;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Retrieves the current state of the presentation as
|
* Retrieves the current state of the presentation as
|
||||||
* an object. This state can then be restored at any
|
* an object. This state can then be restored at any
|
||||||
|
@ -3720,17 +3752,11 @@ var Reveal = (function(){
|
||||||
|
|
||||||
getTotalSlides: getTotalSlides,
|
getTotalSlides: getTotalSlides,
|
||||||
|
|
||||||
// Returns the slide at the specified index, y is optional
|
// Returns the slide element at the specified index
|
||||||
getSlide: function( x, y ) {
|
getSlide: getSlide,
|
||||||
var horizontalSlide = document.querySelectorAll( HORIZONTAL_SLIDES_SELECTOR )[ x ];
|
|
||||||
var verticalSlides = horizontalSlide && horizontalSlide.querySelectorAll( 'section' );
|
|
||||||
|
|
||||||
if( typeof y !== 'undefined' ) {
|
// Returns the slide background element at the specified index
|
||||||
return verticalSlides ? verticalSlides[ y ] : undefined;
|
getSlideBackground: getSlideBackground,
|
||||||
}
|
|
||||||
|
|
||||||
return horizontalSlide;
|
|
||||||
},
|
|
||||||
|
|
||||||
// Returns the previous slide element, may be null
|
// Returns the previous slide element, may be null
|
||||||
getPreviousSlide: function() {
|
getPreviousSlide: function() {
|
||||||
|
|
|
@ -109,6 +109,14 @@ Reveal.addEventListener( 'ready', function() {
|
||||||
strictEqual( Reveal.getSlide( 100 ), undefined, 'returns undefined when slide can\'t be found' );
|
strictEqual( Reveal.getSlide( 100 ), undefined, 'returns undefined when slide can\'t be found' );
|
||||||
});
|
});
|
||||||
|
|
||||||
|
test( 'Reveal.getSlideBackground', function() {
|
||||||
|
var firstBackground = document.querySelector( '.reveal .backgrounds>.slide-background:first-child' );
|
||||||
|
|
||||||
|
equal( Reveal.getSlideBackground( 0 ), firstBackground, 'gets correct first background' );
|
||||||
|
|
||||||
|
strictEqual( Reveal.getSlideBackground( 100 ), undefined, 'returns undefined when background can\'t be found' );
|
||||||
|
});
|
||||||
|
|
||||||
test( 'Reveal.getPreviousSlide/getCurrentSlide', function() {
|
test( 'Reveal.getPreviousSlide/getCurrentSlide', function() {
|
||||||
Reveal.slide( 0, 0 );
|
Reveal.slide( 0, 0 );
|
||||||
Reveal.slide( 1, 0 );
|
Reveal.slide( 1, 0 );
|
||||||
|
|
Loading…
Reference in New Issue