aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorHakim El Hattab <hakim.elhattab@gmail.com>2018-12-18 14:21:11 +0100
committerHakim El Hattab <hakim.elhattab@gmail.com>2018-12-18 14:21:11 +0100
commitdb9c346b412be5dca4ea7ca820f8f39007ef146f (patch)
treeba036d379cc09fb97606511241e1af994c31b64c
parent9f1856d55be7b6ddb5df0df5d06f579966233822 (diff)
downloadperl-software-in-gnu-guix-db9c346b412be5dca4ea7ca820f8f39007ef146f.tar
perl-software-in-gnu-guix-db9c346b412be5dca4ea7ca820f8f39007ef146f.tar.gz
optimization; avoid reading computed styles unless necessary
-rw-r--r--js/reveal.js21
1 files changed, 15 insertions, 6 deletions
diff --git a/js/reveal.js b/js/reveal.js
index 637ea63..4cf43f7 100644
--- a/js/reveal.js
+++ b/js/reveal.js
@@ -1131,18 +1131,27 @@
if( data.backgroundPosition ) contentElement.style.backgroundPosition = data.backgroundPosition;
if( data.backgroundOpacity ) contentElement.style.opacity = data.backgroundOpacity;
- // If this slide has a background color, add a class that
+ // If this slide has a background color, we add a class that
// signals if it is light or dark. If the slide has no background
- // color, no class will be set
- var computedBackgroundStyle = window.getComputedStyle( element );
- if( computedBackgroundStyle && computedBackgroundStyle.backgroundColor ) {
- var rgb = colorToRgb( computedBackgroundStyle.backgroundColor );
+ // color, no class will be added
+ var contrastColor = data.backgroundColor;
+
+ // If no bg color was found, check the computed background
+ if( !contrastColor ) {
+ var computedBackgroundStyle = window.getComputedStyle( element );
+ if( computedBackgroundStyle && computedBackgroundStyle.backgroundColor ) {
+ contrastColor = computedBackgroundStyle.backgroundColor;
+ }
+ }
+
+ if( contrastColor ) {
+ var rgb = colorToRgb( contrastColor );
// Ignore fully transparent backgrounds. Some browsers return
// rgba(0,0,0,0) when reading the computed background color of
// an element with no background
if( rgb && rgb.a !== 0 ) {
- if( colorBrightness( computedBackgroundStyle.backgroundColor ) < 128 ) {
+ if( colorBrightness( contrastColor ) < 128 ) {
slide.classList.add( 'has-dark-background' );
}
else {