From e57ff233a4830de7729a7235b2ec120179feb581 Mon Sep 17 00:00:00 2001 From: Jeroen Hermans Date: Mon, 16 Nov 2020 09:47:58 +0100 Subject: [PATCH] Group background reads and writes --- js/controllers/backgrounds.js | 40 +++++++++++++++++------------------ 1 file changed, 20 insertions(+), 20 deletions(-) diff --git a/js/controllers/backgrounds.js b/js/controllers/backgrounds.js index e8cc996..1327b9f 100644 --- a/js/controllers/backgrounds.js +++ b/js/controllers/backgrounds.js @@ -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' ); @@ -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' ); @@ -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 ) ) { @@ -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; @@ -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 @@ -394,4 +394,4 @@ export default class Backgrounds { } -} \ No newline at end of file +}