mirror of
https://github.com/apache/cordova-plugin-statusbar.git
synced 2025-01-18 17:02:49 +08:00
refactor(eslint): use cordova-eslint (#194)
This commit is contained in:
parent
d472e382d8
commit
1aaa960683
23
.eslintrc.yml
Normal file
23
.eslintrc.yml
Normal file
@ -0,0 +1,23 @@
|
||||
# Licensed to the Apache Software Foundation (ASF) under one
|
||||
# or more contributor license agreements. See the NOTICE file
|
||||
# distributed with this work for additional information
|
||||
# regarding copyright ownership. The ASF licenses this file
|
||||
# to you under the Apache License, Version 2.0 (the
|
||||
# "License"); you may not use this file except in compliance
|
||||
# with the License. You may obtain a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing,
|
||||
# software distributed under the License is distributed on an
|
||||
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
# KIND, either express or implied. See the License for the
|
||||
# specific language governing permissions and limitations
|
||||
# under the License.
|
||||
|
||||
root: true
|
||||
extends: '@cordova/eslint-config/browser'
|
||||
|
||||
overrides:
|
||||
- files: [tests/**/*.js]
|
||||
extends: '@cordova/eslint-config/node-tests'
|
16
.jshintrc
16
.jshintrc
@ -1,16 +0,0 @@
|
||||
{
|
||||
"browser": true
|
||||
, "devel": true
|
||||
, "bitwise": true
|
||||
, "undef": true
|
||||
, "trailing": true
|
||||
, "quotmark": false
|
||||
, "indent": 4
|
||||
, "unused": "vars"
|
||||
, "latedef": "nofunc"
|
||||
, "globals": {
|
||||
"module": false,
|
||||
"exports": false,
|
||||
"require": false
|
||||
}
|
||||
}
|
@ -22,8 +22,8 @@
|
||||
"cordova-windows"
|
||||
],
|
||||
"scripts": {
|
||||
"test": "npm run jshint",
|
||||
"jshint": "node node_modules/jshint/bin/jshint www && node node_modules/jshint/bin/jshint src && node node_modules/jshint/bin/jshint tests"
|
||||
"test": "npm run lint",
|
||||
"lint": "eslint ."
|
||||
},
|
||||
"engines": {
|
||||
"cordovaDependencies": {
|
||||
@ -38,6 +38,6 @@
|
||||
"author": "Apache Software Foundation",
|
||||
"license": "Apache-2.0",
|
||||
"devDependencies": {
|
||||
"jshint": "^2.6.0"
|
||||
"@cordova/eslint-config": "^3.0.0"
|
||||
}
|
||||
}
|
||||
|
@ -18,33 +18,32 @@
|
||||
*
|
||||
*/
|
||||
|
||||
function notSupported(win,fail) {
|
||||
function notSupported (win, fail) {
|
||||
//
|
||||
console.log('StatusBar is not supported');
|
||||
setTimeout(function(){
|
||||
setTimeout(function () {
|
||||
if (win) {
|
||||
win();
|
||||
}
|
||||
// note that while it is not explicitly supported, it does not fail
|
||||
// this is really just here to allow developers to test their code in the browser
|
||||
// and if we fail, then their app might as well. -jm
|
||||
},0);
|
||||
}, 0);
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
isVisible: false,
|
||||
styleBlackTranslucent:notSupported,
|
||||
styleDefault:notSupported,
|
||||
styleLightContent:notSupported,
|
||||
styleBlackOpaque:notSupported,
|
||||
overlaysWebView:notSupported,
|
||||
styleBlackTranslucent: notSupported,
|
||||
styleDefault: notSupported,
|
||||
styleLightContent: notSupported,
|
||||
styleBlackOpaque: notSupported,
|
||||
overlaysWebView: notSupported,
|
||||
styleLightContect: notSupported,
|
||||
backgroundColorByName: notSupported,
|
||||
backgroundColorByHexString: notSupported,
|
||||
hide: notSupported,
|
||||
show: notSupported,
|
||||
_ready:notSupported
|
||||
_ready: notSupported
|
||||
};
|
||||
|
||||
require("cordova/exec/proxy").add("StatusBar", module.exports);
|
||||
|
||||
require('cordova/exec/proxy').add('StatusBar', module.exports);
|
||||
|
@ -22,23 +22,23 @@
|
||||
|
||||
var _supported = null; // set to null so we can check first time
|
||||
|
||||
function isSupported() {
|
||||
function isSupported () {
|
||||
// if not checked before, run check
|
||||
if (_supported === null) {
|
||||
var viewMan = Windows.UI.ViewManagement;
|
||||
_supported = (viewMan.StatusBar && viewMan.StatusBar.getForCurrentView);
|
||||
_supported = viewMan.StatusBar && viewMan.StatusBar.getForCurrentView;
|
||||
}
|
||||
return _supported;
|
||||
}
|
||||
|
||||
function getViewStatusBar() {
|
||||
function getViewStatusBar () {
|
||||
if (!isSupported()) {
|
||||
throw new Error("Status bar is not supported");
|
||||
throw new Error('Status bar is not supported');
|
||||
}
|
||||
return Windows.UI.ViewManagement.StatusBar.getForCurrentView();
|
||||
}
|
||||
|
||||
function hexToRgb(hex) {
|
||||
function hexToRgb (hex) {
|
||||
// Expand shorthand form (e.g. "03F") to full form (e.g. "0033FF")
|
||||
var shorthandRegex = /^#?([a-f\d])([a-f\d])([a-f\d])$/i;
|
||||
hex = hex.replace(shorthandRegex, function (m, r, g, b) {
|
||||
@ -46,16 +46,18 @@ function hexToRgb(hex) {
|
||||
});
|
||||
|
||||
var result = /^#?([a-f\d]{2})([a-f\d]{2})([a-f\d]{2})$/i.exec(hex);
|
||||
return result ? {
|
||||
r: parseInt(result[1], 16),
|
||||
g: parseInt(result[2], 16),
|
||||
b: parseInt(result[3], 16)
|
||||
} : null;
|
||||
return result
|
||||
? {
|
||||
r: parseInt(result[1], 16),
|
||||
g: parseInt(result[2], 16),
|
||||
b: parseInt(result[3], 16)
|
||||
}
|
||||
: null;
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
_ready: function(win, fail) {
|
||||
if(isSupported()) {
|
||||
_ready: function (win, fail) {
|
||||
if (isSupported()) {
|
||||
var statusBar = getViewStatusBar();
|
||||
win(statusBar.occludedRect.height !== 0);
|
||||
}
|
||||
@ -90,7 +92,7 @@ module.exports = {
|
||||
|
||||
backgroundColorByHexString: function (win, fail, args) {
|
||||
var rgb = hexToRgb(args[0]);
|
||||
if(isSupported()) {
|
||||
if (isSupported()) {
|
||||
var statusBar = getViewStatusBar();
|
||||
statusBar.backgroundColor = { a: 0, r: rgb.r, g: rgb.g, b: rgb.b };
|
||||
statusBar.backgroundOpacity = 1;
|
||||
@ -111,4 +113,4 @@ module.exports = {
|
||||
}
|
||||
}
|
||||
};
|
||||
require("cordova/exec/proxy").add("StatusBar", module.exports);
|
||||
require('cordova/exec/proxy').add('StatusBar', module.exports);
|
||||
|
120
tests/tests.js
120
tests/tests.js
@ -17,87 +17,86 @@
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*
|
||||
*/
|
||||
*/
|
||||
|
||||
/* jshint jasmine: true */
|
||||
/* global StatusBar */
|
||||
|
||||
exports.defineAutoTests = function () {
|
||||
describe("StatusBar", function () {
|
||||
it("statusbar.spec.1 should exist", function() {
|
||||
describe('StatusBar', function () {
|
||||
it('statusbar.spec.1 should exist', function () {
|
||||
expect(window.StatusBar).toBeDefined();
|
||||
});
|
||||
|
||||
it("statusbar.spec.2 should have show|hide methods", function() {
|
||||
it('statusbar.spec.2 should have show|hide methods', function () {
|
||||
expect(window.StatusBar.show).toBeDefined();
|
||||
expect(typeof window.StatusBar.show).toBe("function");
|
||||
expect(typeof window.StatusBar.show).toBe('function');
|
||||
|
||||
expect(window.StatusBar.hide).toBeDefined();
|
||||
expect(typeof window.StatusBar.hide).toBe("function");
|
||||
expect(typeof window.StatusBar.hide).toBe('function');
|
||||
});
|
||||
|
||||
it("statusbar.spec.3 should have set backgroundColor methods", function() {
|
||||
it('statusbar.spec.3 should have set backgroundColor methods', function () {
|
||||
expect(window.StatusBar.backgroundColorByName).toBeDefined();
|
||||
expect(typeof window.StatusBar.backgroundColorByName).toBe("function");
|
||||
expect(typeof window.StatusBar.backgroundColorByName).toBe('function');
|
||||
|
||||
expect(window.StatusBar.backgroundColorByHexString).toBeDefined();
|
||||
expect(typeof window.StatusBar.backgroundColorByHexString).toBe("function");
|
||||
expect(typeof window.StatusBar.backgroundColorByHexString).toBe('function');
|
||||
});
|
||||
|
||||
it("statusbar.spec.4 should have set style methods", function() {
|
||||
it('statusbar.spec.4 should have set style methods', function () {
|
||||
expect(window.StatusBar.styleBlackTranslucent).toBeDefined();
|
||||
expect(typeof window.StatusBar.styleBlackTranslucent).toBe("function");
|
||||
expect(typeof window.StatusBar.styleBlackTranslucent).toBe('function');
|
||||
|
||||
expect(window.StatusBar.styleDefault).toBeDefined();
|
||||
expect(typeof window.StatusBar.styleDefault).toBe("function");
|
||||
expect(typeof window.StatusBar.styleDefault).toBe('function');
|
||||
|
||||
expect(window.StatusBar.styleLightContent).toBeDefined();
|
||||
expect(typeof window.StatusBar.styleLightContent).toBe("function");
|
||||
expect(typeof window.StatusBar.styleLightContent).toBe('function');
|
||||
|
||||
expect(window.StatusBar.styleBlackOpaque).toBeDefined();
|
||||
expect(typeof window.StatusBar.styleBlackOpaque).toBe("function");
|
||||
expect(typeof window.StatusBar.styleBlackOpaque).toBe('function');
|
||||
|
||||
expect(window.StatusBar.overlaysWebView).toBeDefined();
|
||||
expect(typeof window.StatusBar.overlaysWebView).toBe("function");
|
||||
expect(typeof window.StatusBar.overlaysWebView).toBe('function');
|
||||
});
|
||||
});
|
||||
};
|
||||
|
||||
exports.defineManualTests = function (contentEl, createActionButton) {
|
||||
function log(msg) {
|
||||
var el = document.getElementById("info");
|
||||
function log (msg) {
|
||||
var el = document.getElementById('info');
|
||||
var logLine = document.createElement('div');
|
||||
logLine.innerHTML = msg;
|
||||
el.appendChild(logLine);
|
||||
}
|
||||
|
||||
function doShow() {
|
||||
function doShow () {
|
||||
StatusBar.show();
|
||||
log('StatusBar.isVisible=' + StatusBar.isVisible);
|
||||
}
|
||||
|
||||
function doHide() {
|
||||
function doHide () {
|
||||
StatusBar.hide();
|
||||
log('StatusBar.isVisible=' + StatusBar.isVisible);
|
||||
}
|
||||
|
||||
function doColor1() {
|
||||
function doColor1 () {
|
||||
log('set color=red');
|
||||
StatusBar.backgroundColorByName('red');
|
||||
}
|
||||
|
||||
function doColor2() {
|
||||
function doColor2 () {
|
||||
log('set style=translucent black');
|
||||
StatusBar.styleBlackTranslucent();
|
||||
}
|
||||
|
||||
function doColor3() {
|
||||
function doColor3 () {
|
||||
log('set style=default');
|
||||
StatusBar.styleDefault();
|
||||
}
|
||||
|
||||
var showOverlay = true;
|
||||
function doOverlay() {
|
||||
function doOverlay () {
|
||||
showOverlay = !showOverlay;
|
||||
StatusBar.overlaysWebView(showOverlay);
|
||||
log('Set overlay=' + showOverlay);
|
||||
@ -105,7 +104,8 @@ exports.defineManualTests = function (contentEl, createActionButton) {
|
||||
|
||||
/******************************************************************************/
|
||||
|
||||
contentEl.innerHTML = '<div id="info"></div>' +
|
||||
contentEl.innerHTML =
|
||||
'<div id="info"></div>' +
|
||||
'Also: tapping bar on iOS should emit a log.' +
|
||||
'<div id="action-show"></div>' +
|
||||
'Expected result: Status bar will be visible' +
|
||||
@ -121,31 +121,59 @@ exports.defineManualTests = function (contentEl, createActionButton) {
|
||||
'Expected result: If overlay false, background color for status bar will be red';
|
||||
|
||||
log('StatusBar.isVisible=' + StatusBar.isVisible);
|
||||
window.addEventListener('statusTap', function () {
|
||||
log('tap!');
|
||||
}, false);
|
||||
window.addEventListener(
|
||||
'statusTap',
|
||||
function () {
|
||||
log('tap!');
|
||||
},
|
||||
false
|
||||
);
|
||||
|
||||
createActionButton("Show", function () {
|
||||
doShow();
|
||||
}, 'action-show');
|
||||
createActionButton(
|
||||
'Show',
|
||||
function () {
|
||||
doShow();
|
||||
},
|
||||
'action-show'
|
||||
);
|
||||
|
||||
createActionButton("Hide", function () {
|
||||
doHide();
|
||||
}, 'action-hide');
|
||||
createActionButton(
|
||||
'Hide',
|
||||
function () {
|
||||
doHide();
|
||||
},
|
||||
'action-hide'
|
||||
);
|
||||
|
||||
createActionButton("Style=red (background)", function () {
|
||||
doColor1();
|
||||
}, 'action-color1');
|
||||
createActionButton(
|
||||
'Style=red (background)',
|
||||
function () {
|
||||
doColor1();
|
||||
},
|
||||
'action-color1'
|
||||
);
|
||||
|
||||
createActionButton("Style=translucent black", function () {
|
||||
doColor2();
|
||||
}, 'action-color2');
|
||||
createActionButton(
|
||||
'Style=translucent black',
|
||||
function () {
|
||||
doColor2();
|
||||
},
|
||||
'action-color2'
|
||||
);
|
||||
|
||||
createActionButton("Style=default", function () {
|
||||
doColor3();
|
||||
}, 'action-color3');
|
||||
createActionButton(
|
||||
'Style=default',
|
||||
function () {
|
||||
doColor3();
|
||||
},
|
||||
'action-color3'
|
||||
);
|
||||
|
||||
createActionButton("Toggle Overlays", function () {
|
||||
doOverlay();
|
||||
}, 'action-overlays');
|
||||
createActionButton(
|
||||
'Toggle Overlays',
|
||||
function () {
|
||||
doOverlay();
|
||||
},
|
||||
'action-overlays'
|
||||
);
|
||||
};
|
||||
|
@ -17,55 +17,54 @@
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*
|
||||
*/
|
||||
*/
|
||||
|
||||
/* global cordova */
|
||||
|
||||
var exec = require('cordova/exec');
|
||||
|
||||
var namedColors = {
|
||||
"black": "#000000",
|
||||
"darkGray": "#A9A9A9",
|
||||
"lightGray": "#D3D3D3",
|
||||
"white": "#FFFFFF",
|
||||
"gray": "#808080",
|
||||
"red": "#FF0000",
|
||||
"green": "#00FF00",
|
||||
"blue": "#0000FF",
|
||||
"cyan": "#00FFFF",
|
||||
"yellow": "#FFFF00",
|
||||
"magenta": "#FF00FF",
|
||||
"orange": "#FFA500",
|
||||
"purple": "#800080",
|
||||
"brown": "#A52A2A"
|
||||
black: '#000000',
|
||||
darkGray: '#A9A9A9',
|
||||
lightGray: '#D3D3D3',
|
||||
white: '#FFFFFF',
|
||||
gray: '#808080',
|
||||
red: '#FF0000',
|
||||
green: '#00FF00',
|
||||
blue: '#0000FF',
|
||||
cyan: '#00FFFF',
|
||||
yellow: '#FFFF00',
|
||||
magenta: '#FF00FF',
|
||||
orange: '#FFA500',
|
||||
purple: '#800080',
|
||||
brown: '#A52A2A'
|
||||
};
|
||||
|
||||
var StatusBar = {
|
||||
|
||||
isVisible: true,
|
||||
|
||||
overlaysWebView: function (doOverlay) {
|
||||
exec(null, null, "StatusBar", "overlaysWebView", [doOverlay]);
|
||||
exec(null, null, 'StatusBar', 'overlaysWebView', [doOverlay]);
|
||||
},
|
||||
|
||||
styleDefault: function () {
|
||||
// dark text ( to be used on a light background )
|
||||
exec(null, null, "StatusBar", "styleDefault", []);
|
||||
exec(null, null, 'StatusBar', 'styleDefault', []);
|
||||
},
|
||||
|
||||
styleLightContent: function () {
|
||||
// light text ( to be used on a dark background )
|
||||
exec(null, null, "StatusBar", "styleLightContent", []);
|
||||
exec(null, null, 'StatusBar', 'styleLightContent', []);
|
||||
},
|
||||
|
||||
styleBlackTranslucent: function () {
|
||||
console.warn('styleBlackTranslucent is deprecated and will be removed in next major release, use styleLightContent');
|
||||
exec(null, null, "StatusBar", "styleBlackTranslucent", []);
|
||||
exec(null, null, 'StatusBar', 'styleBlackTranslucent', []);
|
||||
},
|
||||
|
||||
styleBlackOpaque: function () {
|
||||
console.warn('styleBlackOpaque is deprecated and will be removed in next major release, use styleLightContent');
|
||||
exec(null, null, "StatusBar", "styleBlackOpaque", []);
|
||||
exec(null, null, 'StatusBar', 'styleBlackOpaque', []);
|
||||
},
|
||||
|
||||
backgroundColorByName: function (colorname) {
|
||||
@ -73,41 +72,46 @@ var StatusBar = {
|
||||
},
|
||||
|
||||
backgroundColorByHexString: function (hexString) {
|
||||
if (hexString.charAt(0) !== "#") {
|
||||
hexString = "#" + hexString;
|
||||
if (hexString.charAt(0) !== '#') {
|
||||
hexString = '#' + hexString;
|
||||
}
|
||||
|
||||
if (hexString.length === 4) {
|
||||
var split = hexString.split("");
|
||||
hexString = "#" + split[1] + split[1] + split[2] + split[2] + split[3] + split[3];
|
||||
var split = hexString.split('');
|
||||
hexString = '#' + split[1] + split[1] + split[2] + split[2] + split[3] + split[3];
|
||||
}
|
||||
|
||||
exec(null, null, "StatusBar", "backgroundColorByHexString", [hexString]);
|
||||
exec(null, null, 'StatusBar', 'backgroundColorByHexString', [hexString]);
|
||||
},
|
||||
|
||||
hide: function () {
|
||||
exec(null, null, "StatusBar", "hide", []);
|
||||
exec(null, null, 'StatusBar', 'hide', []);
|
||||
StatusBar.isVisible = false;
|
||||
},
|
||||
|
||||
show: function () {
|
||||
exec(null, null, "StatusBar", "show", []);
|
||||
exec(null, null, 'StatusBar', 'show', []);
|
||||
StatusBar.isVisible = true;
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
// prime it. setTimeout so that proxy gets time to init
|
||||
window.setTimeout(function () {
|
||||
exec(function (res) {
|
||||
if (typeof res == 'object') {
|
||||
if (res.type == 'tap') {
|
||||
cordova.fireWindowEvent('statusTap');
|
||||
exec(
|
||||
function (res) {
|
||||
if (typeof res === 'object') {
|
||||
if (res.type === 'tap') {
|
||||
cordova.fireWindowEvent('statusTap');
|
||||
}
|
||||
} else {
|
||||
StatusBar.isVisible = res;
|
||||
}
|
||||
} else {
|
||||
StatusBar.isVisible = res;
|
||||
}
|
||||
}, null, "StatusBar", "_ready", []);
|
||||
},
|
||||
null,
|
||||
'StatusBar',
|
||||
'_ready',
|
||||
[]
|
||||
);
|
||||
}, 0);
|
||||
|
||||
module.exports = StatusBar;
|
||||
|
Loading…
Reference in New Issue
Block a user