statusbar.js 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  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. /* global cordova */
  22. var exec = require('cordova/exec');
  23. var namedColors = {
  24. "black": "#000000",
  25. "darkGray": "#A9A9A9",
  26. "lightGray": "#D3D3D3",
  27. "white": "#FFFFFF",
  28. "gray": "#808080",
  29. "red": "#FF0000",
  30. "green": "#00FF00",
  31. "blue": "#0000FF",
  32. "cyan": "#00FFFF",
  33. "yellow": "#FFFF00",
  34. "magenta": "#FF00FF",
  35. "orange": "#FFA500",
  36. "purple": "#800080",
  37. "brown": "#A52A2A"
  38. };
  39. var StatusBar = {
  40. isVisible: true,
  41. overlaysWebView: function (doOverlay) {
  42. exec(null, null, "StatusBar", "overlaysWebView", [doOverlay]);
  43. },
  44. styleDefault: function () {
  45. // dark text ( to be used on a light background )
  46. exec(null, null, "StatusBar", "styleDefault", []);
  47. },
  48. styleLightContent: function () {
  49. // light text ( to be used on a dark background )
  50. exec(null, null, "StatusBar", "styleLightContent", []);
  51. },
  52. styleBlackTranslucent: function () {
  53. // #88000000 ? Apple says to use lightContent instead
  54. exec(null, null, "StatusBar", "styleBlackTranslucent", []);
  55. },
  56. styleBlackOpaque: function () {
  57. // #FF000000 ? Apple says to use lightContent instead
  58. exec(null, null, "StatusBar", "styleBlackOpaque", []);
  59. },
  60. backgroundColorByName: function (colorname) {
  61. return StatusBar.backgroundColorByHexString(namedColors[colorname]);
  62. },
  63. backgroundColorByHexString: function (hexString) {
  64. if (hexString.charAt(0) !== "#") {
  65. hexString = "#" + hexString;
  66. }
  67. if (hexString.length === 4) {
  68. var split = hexString.split("");
  69. hexString = "#" + split[1] + split[1] + split[2] + split[2] + split[3] + split[3];
  70. }
  71. exec(null, null, "StatusBar", "backgroundColorByHexString", [hexString]);
  72. },
  73. hide: function () {
  74. exec(null, null, "StatusBar", "hide", []);
  75. StatusBar.isVisible = false;
  76. },
  77. show: function () {
  78. exec(null, null, "StatusBar", "show", []);
  79. StatusBar.isVisible = true;
  80. }
  81. };
  82. // prime it. setTimeout so that proxy gets time to init
  83. window.setTimeout(function () {
  84. exec(function (res) {
  85. if (typeof res == 'object') {
  86. if (res.type == 'tap') {
  87. cordova.fireWindowEvent('statusTap');
  88. }
  89. } else {
  90. StatusBar.isVisible = res;
  91. }
  92. }, null, "StatusBar", "_ready", []);
  93. }, 0);
  94. module.exports = StatusBar;