support shorthand css color values like #F3D and sanity check for leading octothorp

This commit is contained in:
Jesse MacFadyen 2014-03-11 14:23:13 -07:00
parent 83cc8464e1
commit 7b648411cd

View File

@ -17,71 +17,84 @@
* specific language governing permissions and limitations * specific language governing permissions and limitations
* under the License. * under the License.
* *
*/ */
var argscheck = require('cordova/argscheck'), var argscheck = require('cordova/argscheck'),
utils = require('cordova/utils'), utils = require('cordova/utils'),
exec = require('cordova/exec'); exec = require('cordova/exec');
var namedColors = { var namedColors = {
"black":"#000000", "black": "#000000",
"darkGray":"#A9A9A9", "darkGray": "#A9A9A9",
"lightGray":"#D3D3D3", "lightGray": "#D3D3D3",
"white":"#FFFFFF", "white": "#FFFFFF",
"gray":"#808080", "gray": "#808080",
"red":"#FF0000", "red": "#FF0000",
"green":"#00FF00", "green": "#00FF00",
"blue":"#0000FF", "blue": "#0000FF",
"cyan":"#00FFFF", "cyan": "#00FFFF",
"yellow":"#FFFF00", "yellow": "#FFFF00",
"magenta":"#FF00FF", "magenta": "#FF00FF",
"orange":"##FFA500", "orange": "##FFA500",
"purple":"#800080", "purple": "#800080",
"brown":"#A52A2A" "brown": "#A52A2A"
}; };
// prime it // prime it
exec(null, null, "StatusBar", "_ready", []); exec(null, null, "StatusBar", "_ready", []);
var StatusBar = function() { var StatusBar = function () {
}; };
StatusBar.overlaysWebView = function(doOverlay) { StatusBar.overlaysWebView = function (doOverlay) {
exec(null, null, "StatusBar", "overlaysWebView", [doOverlay]); exec(null, null, "StatusBar", "overlaysWebView", [doOverlay]);
}; };
StatusBar.styleDefault = function() { StatusBar.styleDefault = function () {
// dark text on a light background
exec(null, null, "StatusBar", "styleDefault", []); exec(null, null, "StatusBar", "styleDefault", []);
}; };
StatusBar.styleLightContent = function() { StatusBar.styleLightContent = function () {
// light text on a dark background
exec(null, null, "StatusBar", "styleLightContent", []); exec(null, null, "StatusBar", "styleLightContent", []);
}; };
StatusBar.styleBlackTranslucent = function() { StatusBar.styleBlackTranslucent = function () {
// #88000000 ? Apple says to use lightContent instead
exec(null, null, "StatusBar", "styleBlackTranslucent", []); exec(null, null, "StatusBar", "styleBlackTranslucent", []);
}; };
StatusBar.styleBlackOpaque = function() { StatusBar.styleBlackOpaque = function () {
// #FF000000 ? Apple says to use lightContent instead
exec(null, null, "StatusBar", "styleBlackOpaque", []); exec(null, null, "StatusBar", "styleBlackOpaque", []);
}; };
StatusBar.backgroundColorByName = function(colorname) { StatusBar.backgroundColorByName = function (colorname) {
return StatusBar.backgroundColorByHexString(namedColors[colorname]); return StatusBar.backgroundColorByHexString(namedColors[colorname]);
} }
StatusBar.backgroundColorByHexString = function (hexString) {
if (hexString.indexOf("#") < 0) {
hexString = "#" + hexString;
}
if (hexString.length == 4) {
var split = hexString.split("");
hexString = "#" + hexString[1] + hexString[1] + hexString[2] + hexString[2] + hexString[3] + hexString[3];
}
StatusBar.backgroundColorByHexString = function(hexString) {
exec(null, null, "StatusBar", "backgroundColorByHexString", [hexString]); exec(null, null, "StatusBar", "backgroundColorByHexString", [hexString]);
} }
StatusBar.hide = function() { StatusBar.hide = function () {
exec(null, null, "StatusBar", "hide", []); exec(null, null, "StatusBar", "hide", []);
} }
StatusBar.show = function() { StatusBar.show = function () {
exec(null, null, "StatusBar", "show", []); exec(null, null, "StatusBar", "show", []);
} }
StatusBar.isVisible = true; StatusBar.isVisible = true;
module.exports = StatusBar; module.exports = StatusBar;