mirror of
https://github.com/apache/cordova-plugin-statusbar.git
synced 2025-01-19 01:12: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"
|
"cordova-windows"
|
||||||
],
|
],
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"test": "npm run jshint",
|
"test": "npm run lint",
|
||||||
"jshint": "node node_modules/jshint/bin/jshint www && node node_modules/jshint/bin/jshint src && node node_modules/jshint/bin/jshint tests"
|
"lint": "eslint ."
|
||||||
},
|
},
|
||||||
"engines": {
|
"engines": {
|
||||||
"cordovaDependencies": {
|
"cordovaDependencies": {
|
||||||
@ -38,6 +38,6 @@
|
|||||||
"author": "Apache Software Foundation",
|
"author": "Apache Software Foundation",
|
||||||
"license": "Apache-2.0",
|
"license": "Apache-2.0",
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"jshint": "^2.6.0"
|
"@cordova/eslint-config": "^3.0.0"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -46,5 +46,4 @@ module.exports = {
|
|||||||
_ready: notSupported
|
_ready: notSupported
|
||||||
};
|
};
|
||||||
|
|
||||||
require("cordova/exec/proxy").add("StatusBar", module.exports);
|
require('cordova/exec/proxy').add('StatusBar', module.exports);
|
||||||
|
|
||||||
|
@ -26,14 +26,14 @@ function isSupported() {
|
|||||||
// if not checked before, run check
|
// if not checked before, run check
|
||||||
if (_supported === null) {
|
if (_supported === null) {
|
||||||
var viewMan = Windows.UI.ViewManagement;
|
var viewMan = Windows.UI.ViewManagement;
|
||||||
_supported = (viewMan.StatusBar && viewMan.StatusBar.getForCurrentView);
|
_supported = viewMan.StatusBar && viewMan.StatusBar.getForCurrentView;
|
||||||
}
|
}
|
||||||
return _supported;
|
return _supported;
|
||||||
}
|
}
|
||||||
|
|
||||||
function getViewStatusBar () {
|
function getViewStatusBar () {
|
||||||
if (!isSupported()) {
|
if (!isSupported()) {
|
||||||
throw new Error("Status bar is not supported");
|
throw new Error('Status bar is not supported');
|
||||||
}
|
}
|
||||||
return Windows.UI.ViewManagement.StatusBar.getForCurrentView();
|
return Windows.UI.ViewManagement.StatusBar.getForCurrentView();
|
||||||
}
|
}
|
||||||
@ -46,11 +46,13 @@ function hexToRgb(hex) {
|
|||||||
});
|
});
|
||||||
|
|
||||||
var result = /^#?([a-f\d]{2})([a-f\d]{2})([a-f\d]{2})$/i.exec(hex);
|
var result = /^#?([a-f\d]{2})([a-f\d]{2})([a-f\d]{2})$/i.exec(hex);
|
||||||
return result ? {
|
return result
|
||||||
|
? {
|
||||||
r: parseInt(result[1], 16),
|
r: parseInt(result[1], 16),
|
||||||
g: parseInt(result[2], 16),
|
g: parseInt(result[2], 16),
|
||||||
b: parseInt(result[3], 16)
|
b: parseInt(result[3], 16)
|
||||||
} : null;
|
}
|
||||||
|
: null;
|
||||||
}
|
}
|
||||||
|
|
||||||
module.exports = {
|
module.exports = {
|
||||||
@ -111,4 +113,4 @@ module.exports = {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
require("cordova/exec/proxy").add("StatusBar", module.exports);
|
require('cordova/exec/proxy').add('StatusBar', module.exports);
|
||||||
|
@ -19,53 +19,52 @@
|
|||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/* jshint jasmine: true */
|
|
||||||
/* global StatusBar */
|
/* global StatusBar */
|
||||||
|
|
||||||
exports.defineAutoTests = function () {
|
exports.defineAutoTests = function () {
|
||||||
describe("StatusBar", function () {
|
describe('StatusBar', function () {
|
||||||
it("statusbar.spec.1 should exist", function() {
|
it('statusbar.spec.1 should exist', function () {
|
||||||
expect(window.StatusBar).toBeDefined();
|
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(window.StatusBar.show).toBeDefined();
|
||||||
expect(typeof window.StatusBar.show).toBe("function");
|
expect(typeof window.StatusBar.show).toBe('function');
|
||||||
|
|
||||||
expect(window.StatusBar.hide).toBeDefined();
|
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(window.StatusBar.backgroundColorByName).toBeDefined();
|
||||||
expect(typeof window.StatusBar.backgroundColorByName).toBe("function");
|
expect(typeof window.StatusBar.backgroundColorByName).toBe('function');
|
||||||
|
|
||||||
expect(window.StatusBar.backgroundColorByHexString).toBeDefined();
|
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(window.StatusBar.styleBlackTranslucent).toBeDefined();
|
||||||
expect(typeof window.StatusBar.styleBlackTranslucent).toBe("function");
|
expect(typeof window.StatusBar.styleBlackTranslucent).toBe('function');
|
||||||
|
|
||||||
expect(window.StatusBar.styleDefault).toBeDefined();
|
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(window.StatusBar.styleLightContent).toBeDefined();
|
||||||
expect(typeof window.StatusBar.styleLightContent).toBe("function");
|
expect(typeof window.StatusBar.styleLightContent).toBe('function');
|
||||||
|
|
||||||
expect(window.StatusBar.styleBlackOpaque).toBeDefined();
|
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(window.StatusBar.overlaysWebView).toBeDefined();
|
||||||
expect(typeof window.StatusBar.overlaysWebView).toBe("function");
|
expect(typeof window.StatusBar.overlaysWebView).toBe('function');
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
exports.defineManualTests = function (contentEl, createActionButton) {
|
exports.defineManualTests = function (contentEl, createActionButton) {
|
||||||
function log (msg) {
|
function log (msg) {
|
||||||
var el = document.getElementById("info");
|
var el = document.getElementById('info');
|
||||||
var logLine = document.createElement('div');
|
var logLine = document.createElement('div');
|
||||||
logLine.innerHTML = msg;
|
logLine.innerHTML = msg;
|
||||||
el.appendChild(logLine);
|
el.appendChild(logLine);
|
||||||
@ -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.' +
|
'Also: tapping bar on iOS should emit a log.' +
|
||||||
'<div id="action-show"></div>' +
|
'<div id="action-show"></div>' +
|
||||||
'Expected result: Status bar will be visible' +
|
'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';
|
'Expected result: If overlay false, background color for status bar will be red';
|
||||||
|
|
||||||
log('StatusBar.isVisible=' + StatusBar.isVisible);
|
log('StatusBar.isVisible=' + StatusBar.isVisible);
|
||||||
window.addEventListener('statusTap', function () {
|
window.addEventListener(
|
||||||
|
'statusTap',
|
||||||
|
function () {
|
||||||
log('tap!');
|
log('tap!');
|
||||||
}, false);
|
},
|
||||||
|
false
|
||||||
|
);
|
||||||
|
|
||||||
createActionButton("Show", function () {
|
createActionButton(
|
||||||
|
'Show',
|
||||||
|
function () {
|
||||||
doShow();
|
doShow();
|
||||||
}, 'action-show');
|
},
|
||||||
|
'action-show'
|
||||||
|
);
|
||||||
|
|
||||||
createActionButton("Hide", function () {
|
createActionButton(
|
||||||
|
'Hide',
|
||||||
|
function () {
|
||||||
doHide();
|
doHide();
|
||||||
}, 'action-hide');
|
},
|
||||||
|
'action-hide'
|
||||||
|
);
|
||||||
|
|
||||||
createActionButton("Style=red (background)", function () {
|
createActionButton(
|
||||||
|
'Style=red (background)',
|
||||||
|
function () {
|
||||||
doColor1();
|
doColor1();
|
||||||
}, 'action-color1');
|
},
|
||||||
|
'action-color1'
|
||||||
|
);
|
||||||
|
|
||||||
createActionButton("Style=translucent black", function () {
|
createActionButton(
|
||||||
|
'Style=translucent black',
|
||||||
|
function () {
|
||||||
doColor2();
|
doColor2();
|
||||||
}, 'action-color2');
|
},
|
||||||
|
'action-color2'
|
||||||
|
);
|
||||||
|
|
||||||
createActionButton("Style=default", function () {
|
createActionButton(
|
||||||
|
'Style=default',
|
||||||
|
function () {
|
||||||
doColor3();
|
doColor3();
|
||||||
}, 'action-color3');
|
},
|
||||||
|
'action-color3'
|
||||||
|
);
|
||||||
|
|
||||||
createActionButton("Toggle Overlays", function () {
|
createActionButton(
|
||||||
|
'Toggle Overlays',
|
||||||
|
function () {
|
||||||
doOverlay();
|
doOverlay();
|
||||||
}, 'action-overlays');
|
},
|
||||||
|
'action-overlays'
|
||||||
|
);
|
||||||
};
|
};
|
||||||
|
@ -24,48 +24,47 @@
|
|||||||
var exec = require('cordova/exec');
|
var 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'
|
||||||
};
|
};
|
||||||
|
|
||||||
var StatusBar = {
|
var StatusBar = {
|
||||||
|
|
||||||
isVisible: true,
|
isVisible: true,
|
||||||
|
|
||||||
overlaysWebView: function (doOverlay) {
|
overlaysWebView: function (doOverlay) {
|
||||||
exec(null, null, "StatusBar", "overlaysWebView", [doOverlay]);
|
exec(null, null, 'StatusBar', 'overlaysWebView', [doOverlay]);
|
||||||
},
|
},
|
||||||
|
|
||||||
styleDefault: function () {
|
styleDefault: function () {
|
||||||
// dark text ( to be used on a light background )
|
// dark text ( to be used on a light background )
|
||||||
exec(null, null, "StatusBar", "styleDefault", []);
|
exec(null, null, 'StatusBar', 'styleDefault', []);
|
||||||
},
|
},
|
||||||
|
|
||||||
styleLightContent: function () {
|
styleLightContent: function () {
|
||||||
// light text ( to be used on a dark background )
|
// light text ( to be used on a dark background )
|
||||||
exec(null, null, "StatusBar", "styleLightContent", []);
|
exec(null, null, 'StatusBar', 'styleLightContent', []);
|
||||||
},
|
},
|
||||||
|
|
||||||
styleBlackTranslucent: function () {
|
styleBlackTranslucent: function () {
|
||||||
console.warn('styleBlackTranslucent is deprecated and will be removed in next major release, use styleLightContent');
|
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 () {
|
styleBlackOpaque: function () {
|
||||||
console.warn('styleBlackOpaque is deprecated and will be removed in next major release, use styleLightContent');
|
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) {
|
backgroundColorByName: function (colorname) {
|
||||||
@ -73,41 +72,46 @@ var StatusBar = {
|
|||||||
},
|
},
|
||||||
|
|
||||||
backgroundColorByHexString: function (hexString) {
|
backgroundColorByHexString: function (hexString) {
|
||||||
if (hexString.charAt(0) !== "#") {
|
if (hexString.charAt(0) !== '#') {
|
||||||
hexString = "#" + hexString;
|
hexString = '#' + hexString;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (hexString.length === 4) {
|
if (hexString.length === 4) {
|
||||||
var split = hexString.split("");
|
var split = hexString.split('');
|
||||||
hexString = "#" + split[1] + split[1] + split[2] + split[2] + split[3] + split[3];
|
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 () {
|
hide: function () {
|
||||||
exec(null, null, "StatusBar", "hide", []);
|
exec(null, null, 'StatusBar', 'hide', []);
|
||||||
StatusBar.isVisible = false;
|
StatusBar.isVisible = false;
|
||||||
},
|
},
|
||||||
|
|
||||||
show: function () {
|
show: function () {
|
||||||
exec(null, null, "StatusBar", "show", []);
|
exec(null, null, 'StatusBar', 'show', []);
|
||||||
StatusBar.isVisible = true;
|
StatusBar.isVisible = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
// prime it. setTimeout so that proxy gets time to init
|
// prime it. setTimeout so that proxy gets time to init
|
||||||
window.setTimeout(function () {
|
window.setTimeout(function () {
|
||||||
exec(function (res) {
|
exec(
|
||||||
if (typeof res == 'object') {
|
function (res) {
|
||||||
if (res.type == 'tap') {
|
if (typeof res === 'object') {
|
||||||
|
if (res.type === 'tap') {
|
||||||
cordova.fireWindowEvent('statusTap');
|
cordova.fireWindowEvent('statusTap');
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
StatusBar.isVisible = res;
|
StatusBar.isVisible = res;
|
||||||
}
|
}
|
||||||
}, null, "StatusBar", "_ready", []);
|
},
|
||||||
|
null,
|
||||||
|
'StatusBar',
|
||||||
|
'_ready',
|
||||||
|
[]
|
||||||
|
);
|
||||||
}, 0);
|
}, 0);
|
||||||
|
|
||||||
module.exports = StatusBar;
|
module.exports = StatusBar;
|
||||||
|
Loading…
Reference in New Issue
Block a user