Update backgroundColorByHexString function

The implementation when `hexString.length == 4` was a bit off. The current version either doesn't actually use the `split` variable, so that variable could be removed, or used in place accessing the string characters as they are now. Opted for the former in this case, though it doesn't really matter.

Since the length is always going to be a number, also changed to `===` instead, as well as updated the check for `#` at the beginning of the string. Since it's always looking for the `#` tat the beginning `charAt(0)` seems to be a better fit.
This commit is contained in:
Brad Berger 2014-07-21 09:42:44 +02:00
parent be8a3e5947
commit d9a8528c8b

View File

@ -71,13 +71,13 @@ var StatusBar = {
},
backgroundColorByHexString: function (hexString) {
if (hexString.indexOf("#") < 0) {
if (hexString.charAt(0) === "#") {
hexString = "#" + hexString;
}
if (hexString.length == 4) {
if (hexString.length === 4) {
var split = hexString.split("");
hexString = "#" + hexString[1] + hexString[1] + hexString[2] + hexString[2] + hexString[3] + hexString[3];
hexString = "#" + split[1] + split[1] + split[2] + split[2] + split[3] + split[3];
}
exec(null, null, "StatusBar", "backgroundColorByHexString", [hexString]);