Browse Source

add is-background-light class to slides/backgrounds that are > 128 brightness

Hakim El Hattab 10 years ago
parent
commit
20e72df4bf
1 changed files with 10 additions and 6 deletions
  1. 10 6
      js/reveal.js

+ 10 - 6
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,