Skip to content

Commit

Permalink
Group background reads and writes
Browse files Browse the repository at this point in the history
  • Loading branch information
hermansje committed Nov 16, 2020
1 parent 10f02ec commit e57ff23
Showing 1 changed file with 20 additions and 20 deletions.
40 changes: 20 additions & 20 deletions js/controllers/backgrounds.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,6 @@ export default class Backgrounds {
*/
create() {

let printMode = this.Reveal.isPrintingPDF();

// Clear prior backgrounds
this.element.innerHTML = '';
this.element.classList.add( 'no-transition' );
Expand Down Expand Up @@ -114,9 +112,24 @@ export default class Backgrounds {
*/
sync( slide ) {

let element = slide.slideBackgroundElement,
const element = slide.slideBackgroundElement,
contentElement = slide.slideBackgroundContentElement;

const data = {
background: slide.getAttribute( 'data-background' ),
backgroundSize: slide.getAttribute( 'data-background-size' ),
backgroundImage: slide.getAttribute( 'data-background-image' ),
backgroundVideo: slide.getAttribute( 'data-background-video' ),
backgroundIframe: slide.getAttribute( 'data-background-iframe' ),
backgroundColor: slide.getAttribute( 'data-background-color' ),
backgroundRepeat: slide.getAttribute( 'data-background-repeat' ),
backgroundPosition: slide.getAttribute( 'data-background-position' ),
backgroundTransition: slide.getAttribute( 'data-background-transition' ),
backgroundOpacity: slide.getAttribute( 'data-background-opacity' ),
};

const dataPreload = slide.hasAttribute( 'data-preload' );

// Reset the prior background state in case this is not the
// initial sync
slide.classList.remove( 'has-dark-background' );
Expand All @@ -135,19 +148,6 @@ export default class Backgrounds {
contentElement.style.opacity = '';
contentElement.innerHTML = '';

let data = {
background: slide.getAttribute( 'data-background' ),
backgroundSize: slide.getAttribute( 'data-background-size' ),
backgroundImage: slide.getAttribute( 'data-background-image' ),
backgroundVideo: slide.getAttribute( 'data-background-video' ),
backgroundIframe: slide.getAttribute( 'data-background-iframe' ),
backgroundColor: slide.getAttribute( 'data-background-color' ),
backgroundRepeat: slide.getAttribute( 'data-background-repeat' ),
backgroundPosition: slide.getAttribute( 'data-background-position' ),
backgroundTransition: slide.getAttribute( 'data-background-transition' ),
backgroundOpacity: slide.getAttribute( 'data-background-opacity' )
};

if( data.background ) {
// Auto-wrap image urls in url(...)
if( /^(http|file|\/\/)/gi.test( data.background ) || /\.(svg|png|jpg|jpeg|gif|bmp)([?#\s]|$)/gi.test( data.background ) ) {
Expand Down Expand Up @@ -179,7 +179,7 @@ export default class Backgrounds {
if( data.backgroundColor ) element.style.backgroundColor = data.backgroundColor;
if( data.backgroundTransition ) element.setAttribute( 'data-background-transition', data.backgroundTransition );

if( slide.hasAttribute( 'data-preload' ) ) element.setAttribute( 'data-preload', '' );
if( dataPreload ) element.setAttribute( 'data-preload', '' );

// Background image options are set on the content wrapper
if( data.backgroundSize ) contentElement.style.backgroundSize = data.backgroundSize;
Expand All @@ -194,14 +194,14 @@ export default class Backgrounds {

// If no bg color was found, check the computed background
if( !contrastColor ) {
let computedBackgroundStyle = window.getComputedStyle( element );
const computedBackgroundStyle = window.getComputedStyle( element );
if( computedBackgroundStyle && computedBackgroundStyle.backgroundColor ) {
contrastColor = computedBackgroundStyle.backgroundColor;
}
}

if( contrastColor ) {
let rgb = colorToRgb( contrastColor );
const rgb = colorToRgb( contrastColor );

// Ignore fully transparent backgrounds. Some browsers return
// rgba(0,0,0,0) when reading the computed background color of
Expand Down Expand Up @@ -394,4 +394,4 @@ export default class Backgrounds {

}

}
}

0 comments on commit e57ff23

Please sign in to comment.