@@ -23,6 +23,10 @@ var exec = require('cordova/exec');
2323var statusBarVisible = true ;
2424var statusBar = { } ;
2525
26+ // This <script> element is explicitly used by Cordova's statusbar for computing color. (Do not use this element)
27+ const statusBarScript = document . createElement ( 'script' ) ;
28+ document . head . appendChild ( statusBarScript ) ;
29+
2630Object . defineProperty ( statusBar , 'visible' , {
2731 configurable : false ,
2832 enumerable : true ,
@@ -54,9 +58,8 @@ Object.defineProperty(statusBar, 'setBackgroundColor', {
5458 enumerable : false ,
5559 writable : false ,
5660 value : function ( value ) {
57- var script = document . querySelector ( 'script[src*="cordova.js"]' ) ;
58- script . style . color = value ;
59- var rgbStr = window . getComputedStyle ( script ) . getPropertyValue ( 'color' ) ;
61+ statusBarScript . style . color = value ;
62+ var rgbStr = window . getComputedStyle ( statusBarScript ) . getPropertyValue ( 'color' ) ;
6063
6164 if ( ! rgbStr . match ( / ^ r g b / ) ) { return ; }
6265
@@ -68,7 +71,11 @@ Object.defineProperty(statusBar, 'setBackgroundColor', {
6871 rgbVals = [ 255 ] . concat ( rgbVals ) ;
6972 }
7073
71- const padRgb = ( val ) => val . toString ( 16 ) . padStart ( 2 , '0' ) ;
74+ // TODO: Use `padStart(2, '0')` once SDK 24 is dropped.
75+ const padRgb = ( val ) => {
76+ const hex = val . toString ( 16 ) ;
77+ return hex . length === 1 ? '0' + hex : hex ;
78+ } ;
7279 const a = padRgb ( rgbVals [ 0 ] ) ;
7380 const r = padRgb ( rgbVals [ 1 ] ) ;
7481 const g = padRgb ( rgbVals [ 2 ] ) ;
0 commit comments