From 20e72df4bf3f284604e15c6384983055b3641baa Mon Sep 17 00:00:00 2001 From: Hakim El Hattab Date: Tue, 9 Sep 2014 16:50:23 +0200 Subject: [PATCH] add is-background-light class to slides/backgrounds that are > 128 brightness --- js/reveal.js | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/js/reveal.js b/js/reveal.js index f92eca9..df4e8a0 100644 --- a/js/reveal.js +++ b/js/reveal.js @@ -714,8 +714,11 @@ if( data.backgroundPosition ) element.style.backgroundPosition = data.backgroundPosition; if( data.backgroundTransition ) element.setAttribute( 'data-background-transition', data.backgroundTransition ); - if( data.backgroundColor ) { - + // If this slide has a background color, add a class that + // signals if it is light + if( element.style.backgroundColor && colorBrightness( element.style.backgroundColor ) > 128 ) { + slide.classList.add( 'is-background-light' ); + element.classList.add( 'is-background-light' ); } container.appendChild( element ); @@ -1122,7 +1125,11 @@ if( typeof color === 'string' ) color = colorToRgb( color ); - return ( color.r * 299 + color.g * 587 + color.b * 114 ) / 1000; + if( color ) { + return ( color.r * 299 + color.g * 587 + color.b * 114 ) / 1000; + } + + return null; } @@ -4100,9 +4107,6 @@ addEventListeners: addEventListeners, removeEventListeners: removeEventListeners, - colorToRgb: colorToRgb, - colorBrightness: colorBrightness, - // Facility for persisting and restoring the presentation state getState: getState, setState: setState,