diff options
author | Hakim El Hattab <hakim.elhattab@gmail.com> | 2014-09-10 10:53:24 +0200 |
---|---|---|
committer | Hakim El Hattab <hakim.elhattab@gmail.com> | 2014-09-10 10:53:24 +0200 |
commit | 0d14d87f1a039584eaa5c9720b30b154e6b2e10e (patch) | |
tree | d4a961808712452d67af910d66208fb64abd68f1 /js | |
parent | 41f20301b6a634003ed89f222f5fe1995ca29ce5 (diff) | |
download | fosdem-2018-presentation-0d14d87f1a039584eaa5c9720b30b154e6b2e10e.tar fosdem-2018-presentation-0d14d87f1a039584eaa5c9720b30b154e6b2e10e.tar.gz |
rgba color parsing support, ignore brightness of transparent colors
Diffstat (limited to 'js')
-rw-r--r-- | js/reveal.js | 33 |
1 files changed, 25 insertions, 8 deletions
diff --git a/js/reveal.js b/js/reveal.js index 7cc551c..3cc1cae 100644 --- a/js/reveal.js +++ b/js/reveal.js @@ -721,11 +721,18 @@ // color, no class will be set var computedBackgroundColor = window.getComputedStyle( element ).backgroundColor; if( computedBackgroundColor ) { - if( colorBrightness( computedBackgroundColor ) < 128 ) { - slide.classList.add( 'has-dark-background' ); - } - else { - slide.classList.add( 'has-light-background' ); + var rgb = colorToRgb( computedBackgroundColor ); + + // 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( computedBackgroundColor ) < 128 ) { + slide.classList.add( 'has-dark-background' ); + } + else { + slide.classList.add( 'has-light-background' ); + } } } @@ -1112,9 +1119,19 @@ var rgb = color.match( /^rgb\s*\(\s*(\d+)\s*,\s*(\d+)\s*,\s*(\d+)\s*\)$/i ); if( rgb ) { return { - r: rgb[1], - g: rgb[2], - b: rgb[3] + r: parseInt( rgb[1], 10 ), + g: parseInt( rgb[2], 10 ), + b: parseInt( rgb[3], 10 ) + }; + } + + var rgba = color.match( /^rgba\s*\(\s*(\d+)\s*,\s*(\d+)\s*,\s*(\d+)\s*\,\s*([\d]+|[\d]*.[\d]+)\s*\)$/i ); + if( rgba ) { + return { + r: parseInt( rgba[1], 10 ), + g: parseInt( rgba[2], 10 ), + b: parseInt( rgba[3], 10 ), + a: parseFloat( rgba[4] ) }; } |