Skip to content

Commit

Permalink
CB-10636 Add JSHint for plugins
Browse files Browse the repository at this point in the history
  • Loading branch information
daserge committed Feb 26, 2016
1 parent aa69e1b commit d56ab5b
Show file tree
Hide file tree
Showing 8 changed files with 82 additions and 48 deletions.
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ Thumbs.db
*.swp
*.user


node_modules



Expand Down
17 changes: 17 additions & 0 deletions .jshintrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
{
"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,
"cordova": true
}
}
4 changes: 4 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
language: node_js
sudo: false
node_js:
- "4.2"
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@
# under the License.
-->

[![Build Status](https://travis-ci.org/apache/cordova-plugin-geolocation.svg?branch=master)](https://travis-ci.org/apache/cordova-plugin-geolocation)

# cordova-plugin-geolocation

This plugin provides information about the device's location, such as
Expand Down
9 changes: 8 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,13 @@
"cordova-windows",
"cordova-firefoxos"
],
"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"
},
"author": "Apache Software Foundation",
"license": "Apache-2.0"
"license": "Apache-2.0",
"devDependencies": {
"jshint": "^2.6.0"
}
}
10 changes: 6 additions & 4 deletions src/windows/GeolocationProxy.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@
* limitations under the License.
*/

/* global Windows, WinJS */

var PositionError = require('./PositionError');
var callbacks = {};
var locs = {};
Expand Down Expand Up @@ -128,11 +130,11 @@ module.exports = {
var clientId = args[0];
var highAccuracy = args[1];

onPositionChanged = function (e) {
var onPositionChanged = function (e) {
success(createResult(e.position), { keepCallback: true });
},
};

onStatusChanged = function (e) {
var onStatusChanged = function (e) {
switch (e.status) {
case Windows.Devices.Geolocation.PositionStatus.noData:
case Windows.Devices.Geolocation.PositionStatus.notAvailable:
Expand Down Expand Up @@ -183,7 +185,7 @@ module.exports = {
clearWatch: function (success, fail, args, env) {
var clientId = args[0];
var callback = callbacks[clientId];
var loc = locs[clientId]
var loc = locs[clientId];

if (callback && loc) {
loc.removeEventListener("positionchanged", callback.pos);
Expand Down
76 changes: 40 additions & 36 deletions tests/tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,10 @@
* under the License.
*
*/

/* jshint jasmine: true */
/* global WinJS, device */

exports.defineAutoTests = function () {
var fail = function (done, context, message) {
// prevents done() to be called several times
Expand Down Expand Up @@ -266,6 +270,40 @@ exports.defineAutoTests = function () {
exports.defineManualTests = function (contentEl, createActionButton) {
var watchLocationId = null;

/**
* Set location status
*/
function setLocationStatus(status) {
document.getElementById('location_status').innerHTML = status;
}
function setLocationDetails(p) {
var date = (new Date(p.timestamp));
document.getElementById('latitude').innerHTML = p.coords.latitude;
document.getElementById('longitude').innerHTML = p.coords.longitude;
document.getElementById('altitude').innerHTML = p.coords.altitude;
document.getElementById('accuracy').innerHTML = p.coords.accuracy;
document.getElementById('heading').innerHTML = p.coords.heading;
document.getElementById('speed').innerHTML = p.coords.speed;
document.getElementById('altitude_accuracy').innerHTML = p.coords.altitudeAccuracy;
document.getElementById('timestamp').innerHTML = date.toDateString() + " " + date.toTimeString();
}

/**
* Stop watching the location
*/
function stopLocation() {
var geo = navigator.geolocation;
if (!geo) {
alert('navigator.geolocation object is missing.');
return;
}
setLocationStatus("Stopped");
if (watchLocationId) {
geo.clearWatch(watchLocationId);
watchLocationId = null;
}
}

/**
* Start watching location
*/
Expand All @@ -292,22 +330,6 @@ exports.defineManualTests = function (contentEl, createActionButton) {
setLocationStatus("Running");
};

/**
* Stop watching the location
*/
var stopLocation = function () {
var geo = navigator.geolocation;
if (!geo) {
alert('navigator.geolocation object is missing.');
return;
}
setLocationStatus("Stopped");
if (watchLocationId) {
geo.clearWatch(watchLocationId);
watchLocationId = null;
}
};

/**
* Get current location
*/
Expand Down Expand Up @@ -340,24 +362,6 @@ exports.defineManualTests = function (contentEl, createActionButton) {

};

/**
* Set location status
*/
var setLocationStatus = function (status) {
document.getElementById('location_status').innerHTML = status;
};
var setLocationDetails = function (p) {
var date = (new Date(p.timestamp));
document.getElementById('latitude').innerHTML = p.coords.latitude;
document.getElementById('longitude').innerHTML = p.coords.longitude;
document.getElementById('altitude').innerHTML = p.coords.altitude;
document.getElementById('accuracy').innerHTML = p.coords.accuracy;
document.getElementById('heading').innerHTML = p.coords.heading;
document.getElementById('speed').innerHTML = p.coords.speed;
document.getElementById('altitude_accuracy').innerHTML = p.coords.altitudeAccuracy;
document.getElementById('timestamp').innerHTML = date.toDateString() + " " + date.toTimeString();
};

/******************************************************************************/

var location_div = '<div id="info">' +
Expand Down Expand Up @@ -423,8 +427,8 @@ exports.defineManualTests = function (contentEl, createActionButton) {
note =
'<h3>Allow use of current location, if prompted</h3>';

contentEl.innerHTML = values_info + location_div + latitude + longitude + altitude + accuracy + heading + speed
+ altitude_accuracy + time + note + actions;
contentEl.innerHTML = values_info + location_div + latitude + longitude + altitude + accuracy + heading + speed +
altitude_accuracy + time + note + actions;

createActionButton('Get Location', function () {
getLocation();
Expand Down
10 changes: 4 additions & 6 deletions www/android/geolocation.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,15 @@
*
*/


var exec = cordova.require('cordova/exec');
var utils = require('cordova/utils');
var PositionError = require('./PositionError');

module.exports = {
// Native watchPosition method is called async after permissions prompt.
// So we use additional map and own ids to return watch id synchronously.
var pluginToNativeWatchMap = {};

module.exports = {
getCurrentPosition: function(success, error, args) {
var win = function() {
var geo = cordova.require('cordova/modulemapper').getOriginalSymbol(window, 'navigator.geolocation');
Expand Down Expand Up @@ -67,7 +69,3 @@ module.exports = {
exec(win, null, "Geolocation", "getPermission", []);
}
};

// Native watchPosition method is called async after permissions prompt.
// So we use additional map and own ids to return watch id synchronously.
var pluginToNativeWatchMap = {};

0 comments on commit d56ab5b

Please sign in to comment.