Skip to content

Commit

Permalink
fix issue with loading base64 images #2978
Browse files Browse the repository at this point in the history
  • Loading branch information
hakimel committed Sep 28, 2021
1 parent 0da9821 commit 05e57de
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 6 deletions.
2 changes: 1 addition & 1 deletion dist/reveal.esm.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/reveal.js

Large diffs are not rendered by default.

13 changes: 10 additions & 3 deletions js/controllers/slidecontent.js
Original file line number Diff line number Diff line change
Expand Up @@ -102,9 +102,16 @@ export default class SlideContent {

// Images
if( backgroundImage ) {
backgroundContent.style.backgroundImage = backgroundImage.split( ',' ).map( background => {
return `url(${encodeURI(background.trim())})`;
}).join( ',' );
// base64
if( /^data:/.test( backgroundImage.trim() ) ) {
backgroundContent.style.backgroundImage = `url(${backgroundImage.trim()})`;
}
// URL(s)
else {
backgroundContent.style.backgroundImage = backgroundImage.split( ',' ).map( background => {
return `url(${encodeURI(background.trim())})`;
}).join( ',' );
}
}
// Videos
else if ( backgroundVideo && !this.Reveal.isSpeakerNotes() ) {
Expand Down
4 changes: 3 additions & 1 deletion test/test.html
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ <h1>1</h1>
<section data-background="examples/assets/image2.png" data-notes="speaker notes 2">
<h1>2.1</h1>
</section>
<section>
<section data-background-image="data:image/jpeg;base64,/9j/4AAQSkZJRgABAQEASABIAAD/4gIcSUNDX1BST0ZJTEUAAQEAAAIMbGNtcwIQAABtbnRyUkdCIFhZWiAH3AABABkAAwApADlhY3NwQVBQTAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA9tYAAQAAAADTLWxjbXMAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAApkZXNjAAAA/">
<h1>2.2</h1>
</section>
<section>
Expand Down Expand Up @@ -769,10 +769,12 @@ <h1>4</h1>
QUnit.test( 'background images', function( assert ) {
var imageSource1 = Reveal.getSlide( 0 ).getAttribute( 'data-background-image' );
var imageSource2 = Reveal.getSlide( 1, 0 ).getAttribute( 'data-background' );
var imageSource3 = Reveal.getSlide( 1, 1 ).getAttribute( 'data-background-image' );

// check that the images are applied to the background elements
assert.ok( Reveal.getSlideBackground( 0 ).querySelector( '.slide-background-content' ).style.backgroundImage.indexOf( imageSource1 ) !== -1, 'data-background-image worked' );
assert.ok( Reveal.getSlideBackground( 1, 0 ).querySelector( '.slide-background-content' ).style.backgroundImage.indexOf( imageSource2 ) !== -1, 'data-background worked' );
assert.ok( Reveal.getSlideBackground( 1, 1 ).querySelector( '.slide-background-content' ).style.backgroundImage.indexOf( imageSource3 ) !== -1, 'data-background worked' );
});


Expand Down

0 comments on commit 05e57de

Please sign in to comment.