openEventsPlatformApp/plugins/cordova-plugin-statusbar/src/windows/StatusBarProxy.js
plugins/cordova-plugin-statusbar/src/windows/StatusBarProxy.jsRaw
1/*
2 * Licensed to the Apache Software Foundation (ASF) under one
3 * or more contributor license agreements. See the NOTICE file
4 * distributed with this work for additional information
5 * regarding copyright ownership. The ASF licenses this file
6 * to you under the Apache License, Version 2.0 (the
7 * "License"); you may not use this file except in compliance
8 * with the License. You may obtain a copy of the License at
9 *
10 * http://www.apache.org/licenses/LICENSE-2.0
11 *
12 * Unless required by applicable law or agreed to in writing,
13 * software distributed under the License is distributed on an
14 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15 * KIND, either express or implied. See the License for the
16 * specific language governing permissions and limitations
17 * under the License.
18 *
19 */
20
21/* global Windows */
22
23var _supported = null; // set to null so we can check first time
24
25function isSupported() {
26 // if not checked before, run check
27 if (_supported === null) {
28 var viewMan = Windows.UI.ViewManagement;
29 _supported = (viewMan.StatusBar && viewMan.StatusBar.getForCurrentView);
30 }
31 return _supported;
32}
33
34function getViewStatusBar() {
35 if (!isSupported()) {
36 throw new Error("Status bar is not supported");
37 }
38 return Windows.UI.ViewManagement.StatusBar.getForCurrentView();
39}
40
41function hexToRgb(hex) {
42 // Expand shorthand form (e.g. "03F") to full form (e.g. "0033FF")
43 var shorthandRegex = /^#?([a-f\d])([a-f\d])([a-f\d])$/i;
44 hex = hex.replace(shorthandRegex, function (m, r, g, b) {
45 return r + r + g + g + b + b;
46 });
47
48 var result = /^#?([a-f\d]{2})([a-f\d]{2})([a-f\d]{2})$/i.exec(hex);
49 return result ? {
50 r: parseInt(result[1], 16),
51 g: parseInt(result[2], 16),
52 b: parseInt(result[3], 16)
53 } : null;
54}
55
56module.exports = {
57 _ready: function(win, fail) {
58 if(isSupported()) {
59 var statusBar = getViewStatusBar();
60 win(statusBar.occludedRect.height !== 0);
61 }
62 },
63 overlaysWebView: function () {
64 // not supported
65 },
66
67 styleDefault: function () {
68 // dark text ( to be used on a light background )
69 if (isSupported()) {
70 getViewStatusBar().foregroundColor = { a: 0, r: 0, g: 0, b: 0 };
71 }
72 },
73
74 styleLightContent: function () {
75 // light text ( to be used on a dark background )
76 if (isSupported()) {
77 getViewStatusBar().foregroundColor = { a: 0, r: 255, g: 255, b: 255 };
78 }
79 },
80
81 styleBlackTranslucent: function () {
82 // #88000000 ? Apple says to use lightContent instead
83 return module.exports.styleLightContent();
84 },
85
86 styleBlackOpaque: function () {
87 // #FF000000 ? Apple says to use lightContent instead
88 return module.exports.styleLightContent();
89 },
90
91 backgroundColorByHexString: function (win, fail, args) {
92 var rgb = hexToRgb(args[0]);
93 if(isSupported()) {
94 var statusBar = getViewStatusBar();
95 statusBar.backgroundColor = { a: 0, r: rgb.r, g: rgb.g, b: rgb.b };
96 statusBar.backgroundOpacity = 1;
97 }
98 },
99
100 show: function (win, fail) {
101 // added support check so no error thrown, when calling this method
102 if (isSupported()) {
103 getViewStatusBar().showAsync().done(win, fail);
104 }
105 },
106
107 hide: function (win, fail) {
108 // added support check so no error thrown, when calling this method
109 if (isSupported()) {
110 getViewStatusBar().hideAsync().done(win, fail);
111 }
112 }
113};
114require("cordova/exec/proxy").add("StatusBar", module.exports);