openEventsPlatformApp/plugins/cordova-plugin-statusbar/www/statusbar.js
plugins/cordova-plugin-statusbar/www/statusbar.jsRaw
1/*
2 *
3 * Licensed to the Apache Software Foundation (ASF) under one
4 * or more contributor license agreements. See the NOTICE file
5 * distributed with this work for additional information
6 * regarding copyright ownership. The ASF licenses this file
7 * to you under the Apache License, Version 2.0 (the
8 * "License"); you may not use this file except in compliance
9 * with the License. You may obtain a copy of the License at
10 *
11 * http://www.apache.org/licenses/LICENSE-2.0
12 *
13 * Unless required by applicable law or agreed to in writing,
14 * software distributed under the License is distributed on an
15 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16 * KIND, either express or implied. See the License for the
17 * specific language governing permissions and limitations
18 * under the License.
19 *
20*/
21
22/* global cordova */
23
24var exec = require('cordova/exec');
25
26var namedColors = {
27 "black": "#000000",
28 "darkGray": "#A9A9A9",
29 "lightGray": "#D3D3D3",
30 "white": "#FFFFFF",
31 "gray": "#808080",
32 "red": "#FF0000",
33 "green": "#00FF00",
34 "blue": "#0000FF",
35 "cyan": "#00FFFF",
36 "yellow": "#FFFF00",
37 "magenta": "#FF00FF",
38 "orange": "#FFA500",
39 "purple": "#800080",
40 "brown": "#A52A2A"
41};
42
43var StatusBar = {
44
45 isVisible: true,
46
47 overlaysWebView: function (doOverlay) {
48 exec(null, null, "StatusBar", "overlaysWebView", [doOverlay]);
49 },
50
51 styleDefault: function () {
52 // dark text ( to be used on a light background )
53 exec(null, null, "StatusBar", "styleDefault", []);
54 },
55
56 styleLightContent: function () {
57 // light text ( to be used on a dark background )
58 exec(null, null, "StatusBar", "styleLightContent", []);
59 },
60
61 styleBlackTranslucent: function () {
62 // #88000000 ? Apple says to use lightContent instead
63 exec(null, null, "StatusBar", "styleBlackTranslucent", []);
64 },
65
66 styleBlackOpaque: function () {
67 // #FF000000 ? Apple says to use lightContent instead
68 exec(null, null, "StatusBar", "styleBlackOpaque", []);
69 },
70
71 backgroundColorByName: function (colorname) {
72 return StatusBar.backgroundColorByHexString(namedColors[colorname]);
73 },
74
75 backgroundColorByHexString: function (hexString) {
76 if (hexString.charAt(0) !== "#") {
77 hexString = "#" + hexString;
78 }
79
80 if (hexString.length === 4) {
81 var split = hexString.split("");
82 hexString = "#" + split[1] + split[1] + split[2] + split[2] + split[3] + split[3];
83 }
84
85 exec(null, null, "StatusBar", "backgroundColorByHexString", [hexString]);
86 },
87
88 hide: function () {
89 exec(null, null, "StatusBar", "hide", []);
90 StatusBar.isVisible = false;
91 },
92
93 show: function () {
94 exec(null, null, "StatusBar", "show", []);
95 StatusBar.isVisible = true;
96 }
97
98};
99
100// prime it. setTimeout so that proxy gets time to init
101window.setTimeout(function () {
102 exec(function (res) {
103 if (typeof res == 'object') {
104 if (res.type == 'tap') {
105 cordova.fireWindowEvent('statusTap');
106 }
107 } else {
108 StatusBar.isVisible = res;
109 }
110 }, null, "StatusBar", "_ready", []);
111}, 0);
112
113module.exports = StatusBar;