diff --git a/.gitignore b/.gitignore index 52b558e4..6964ea05 100644 --- a/.gitignore +++ b/.gitignore @@ -12,7 +12,7 @@ Thumbs.db *.swp *.user - +node_modules diff --git a/.jshintrc b/.jshintrc new file mode 100644 index 00000000..df324821 --- /dev/null +++ b/.jshintrc @@ -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 + } +} diff --git a/.travis.yml b/.travis.yml new file mode 100644 index 00000000..b9af4c58 --- /dev/null +++ b/.travis.yml @@ -0,0 +1,4 @@ +language: node_js +sudo: false +node_js: + - "4.2" diff --git a/README.md b/README.md index 74695ea4..28b67a88 100644 --- a/README.md +++ b/README.md @@ -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 diff --git a/package.json b/package.json index 83e4c1f7..984899d0 100644 --- a/package.json +++ b/package.json @@ -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" + } } diff --git a/src/windows/GeolocationProxy.js b/src/windows/GeolocationProxy.js index 3f1a42dc..03ed4950 100644 --- a/src/windows/GeolocationProxy.js +++ b/src/windows/GeolocationProxy.js @@ -14,6 +14,8 @@ * limitations under the License. */ +/* global Windows, WinJS */ + var PositionError = require('./PositionError'); var callbacks = {}; var locs = {}; @@ -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: @@ -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); diff --git a/tests/tests.js b/tests/tests.js index 65a9c69c..50c5bfb2 100644 --- a/tests/tests.js +++ b/tests/tests.js @@ -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 @@ -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 */ @@ -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 */ @@ -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 = '
' + @@ -423,8 +427,8 @@ exports.defineManualTests = function (contentEl, createActionButton) { note = '

Allow use of current location, if prompted

'; - 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(); diff --git a/www/android/geolocation.js b/www/android/geolocation.js index 57b81220..7265bec0 100644 --- a/www/android/geolocation.js +++ b/www/android/geolocation.js @@ -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'); @@ -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 = {};