Skip to content
Browse files

Add , remove direct navigator access. Add msg constants

  • Loading branch information...
1 parent c81868d commit caeae92b44d7f0f236ef1b9229344efbbd6a6939 @mikepugh committed Feb 2, 2014
Showing with 39 additions and 31 deletions.
  1. +0 −8 Gruntfile.js
  2. +1 −1 bower.json
  3. +18 −10 dist/angulargeo.js
  4. +1 −1 dist/angulargeo.min.js
  5. +1 −1 package.json
  6. +18 −10 scripts/angulargeo.js
View
8 Gruntfile.js
@@ -151,14 +151,6 @@ module.exports = function (grunt) {
src: [
'**/*.js'
]
- },
- {
- expand: true,
- cwd: '.tmp/images',
- dest: '<%= yeoman.dist %>/images',
- src: [
- 'generated/*'
- ]
}
]
}
View
2 bower.json
@@ -1,6 +1,6 @@
{
"name": "AngularGeo",
- "version": "0.1.0",
+ "version": "0.2.0",
"homepage": "https://github.com/mikepugh/AngularGeo",
"authors": [
"Mike Pugh <mikepugh82@gmail.com>"
View
28 dist/angulargeo.js
@@ -6,12 +6,17 @@
"use strict";
var angularGeo = angular.module('angular-geo', []);
+ angularGeo.constant('angularGeo_msgs', {
+ 'errors.unsupportedBrowser':'Browser geolocation not supported',
+ 'errors.noServices':'angularGeo could not locate any of the geo providers specified, verify that you have them properly linked',
+ 'errors.noProviders':'angularGeo requires at least one geo provider'
+ });
angularGeo.provider('angularGeo', function() {
var $$geoConfig = {
providerSvcNames: [],
providers: []
};
- var $$supportsGeolocation = 'geolocation' in navigator;
+ var $$supportsGeolocation = false;
var $$watchId;
var $$currentProvider = 0;
@@ -20,9 +25,12 @@
$$geoConfig.providerSvcNames.push(providerSvcName);
return this;
},
- $get: function ($log, $q, $timeout, $rootScope, $injector) {
+ $get: function ($log, $q, $timeout, $rootScope, $injector, $window, angularGeo_msgs) {
+
+ $$supportsGeolocation = 'geolocation' in $window.navigator;
+
if($$geoConfig.providerSvcNames.length === 0) {
- throw new Error("AngularGeo requires at least 1 geo provider");
+ throw new Error(angularGeo_msgs.errors.noProviders);
}
// Instantiate the geo providers and store them within the $$geoConfig object
for(var i = 0; i < $$geoConfig.providerSvcNames.length; i++) {
@@ -34,7 +42,7 @@
}
var $$providers = $$geoConfig.providers;
if($$providers.length === 0) {
- throw new Error('angularGeo could not locate any of the geo providers specified, verify that you have them properly linked');
+ throw new Error(angularGeo_msgs.errors.noServices);
}
var $$geocode = function(address, bounds, region, restrictions, filters, promise) {
@@ -64,10 +72,10 @@
getCurrentPosition: function(options, autoReverseGeocode) {
var self = this;
if(!$$supportsGeolocation) {
- throw new Error("Browser geolocation not supported");
+ throw new Error(angularGeo_msgs.errors.unsupportedBrowser);
}
var deferred = $q.defer();
- navigator.geolocation.getCurrentPosition(function(pos) {
+ $window.navigator.geolocation.getCurrentPosition(function(pos) {
if(autoReverseGeocode) {
var p = self.reverseGeocode({latitude: pos.coords.latitude, longitude: pos.coords.longitude}, null, null, null, null);
p.then(function(results) {
@@ -85,10 +93,10 @@
watchPosition: function(options) {
var self = this;
if(!$$supportsGeolocation) {
- throw new Error("Browser geolocation not supported");
+ throw new Error(angularGeo_msgs.errors.unsupportedBrowser);
}
var deferred = $q.defer();
- $$watchId = navigator.geolocation.watchPosition(function(pos) {
+ $$watchId = $window.navigator.geolocation.watchPosition(function(pos) {
$rootScope.$broadcast("angulargeo:watchposition", pos);
}, function(err) {
deferred.reject(err);
@@ -98,9 +106,9 @@
},
clearWatch: function() {
if(!$$supportsGeolocation) {
- throw new Error("Browser geolocation not supported");
+ throw new Error(angularGeo_msgs.errors.unsupportedBrowser);
}
- navigator.geolocation.clearWatch($$watchId);
+ $window.navigator.geolocation.clearWatch($$watchId);
}
}
}
View
2 dist/angulargeo.min.js
@@ -1 +1 @@
-(function(){"use strict";var a=angular.module("angular-geo",[]);a.provider("angularGeo",function(){var a,b={providerSvcNames:[],providers:[]},c="geolocation"in navigator,d=0;return{addProvider:function(a){return b.providerSvcNames.push(a),this},$get:function(e,f,g,h,i){if(0===b.providerSvcNames.length)throw new Error("AngularGeo requires at least 1 geo provider");for(var j=0;j<b.providerSvcNames.length;j++)i.has(b.providerSvcNames[j])?b.providers.push(i.get(b.providerSvcNames[j])):e.error("angularGeo could not locate service "+b.providerSvcNames[j]);var k=b.providers;if(0===k.length)throw new Error("angularGeo could not locate any of the geo providers specified, verify that you have them properly linked");var l=function(a,b,c,e,g,h){var i=h||f.defer(),j=k[d].geocode(a,b,c,e,g);return j.then(function(a){i.resolve(a)},function(f){return 1===k.length&&i.reject(f),d<k.length-1?d++:d=0,l(a,b,c,e,g,i)}),i.promise};return{geocode:function(a,b,c,d,e){return l(a,b,c,d,e,null)},reverseGeocode:function(){},getCurrentPosition:function(a,b){var d=this;if(!c)throw new Error("Browser geolocation not supported");var e=f.defer();return navigator.geolocation.getCurrentPosition(function(a){if(b){var c=d.reverseGeocode({latitude:a.coords.latitude,longitude:a.coords.longitude},null,null,null,null);c.then(function(a){e.resolve(a)},function(a){e.reject(a)})}e.resolve(a)},function(a){e.reject(a)},a),e.promise},watchPosition:function(b){if(!c)throw new Error("Browser geolocation not supported");var d=f.defer();return a=navigator.geolocation.watchPosition(function(a){h.$broadcast("angulargeo:watchposition",a)},function(a){d.reject(a)},b),d.promise},clearWatch:function(){if(!c)throw new Error("Browser geolocation not supported");navigator.geolocation.clearWatch(a)}}}}})}).call(this);
+(function(){"use strict";var a=angular.module("angular-geo",[]);a.constant("angularGeo_msgs",{"errors.unsupportedBrowser":"Browser geolocation not supported","errors.noServices":"angularGeo could not locate any of the geo providers specified, verify that you have them properly linked","errors.noProviders":"angularGeo requires at least one geo provider"}),a.provider("angularGeo",function(){var a,b={providerSvcNames:[],providers:[]},c=!1,d=0;return{addProvider:function(a){return b.providerSvcNames.push(a),this},$get:function(e,f,g,h,i,j,k){if(c="geolocation"in j.navigator,0===b.providerSvcNames.length)throw new Error(k.errors.noProviders);for(var l=0;l<b.providerSvcNames.length;l++)i.has(b.providerSvcNames[l])?b.providers.push(i.get(b.providerSvcNames[l])):e.error("angularGeo could not locate service "+b.providerSvcNames[l]);var m=b.providers;if(0===m.length)throw new Error(k.errors.noServices);var n=function(a,b,c,e,g,h){var i=h||f.defer(),j=m[d].geocode(a,b,c,e,g);return j.then(function(a){i.resolve(a)},function(f){return 1===m.length&&i.reject(f),d<m.length-1?d++:d=0,n(a,b,c,e,g,i)}),i.promise};return{geocode:function(a,b,c,d,e){return n(a,b,c,d,e,null)},reverseGeocode:function(){},getCurrentPosition:function(a,b){var d=this;if(!c)throw new Error(k.errors.unsupportedBrowser);var e=f.defer();return j.navigator.geolocation.getCurrentPosition(function(a){if(b){var c=d.reverseGeocode({latitude:a.coords.latitude,longitude:a.coords.longitude},null,null,null,null);c.then(function(a){e.resolve(a)},function(a){e.reject(a)})}e.resolve(a)},function(a){e.reject(a)},a),e.promise},watchPosition:function(b){if(!c)throw new Error(k.errors.unsupportedBrowser);var d=f.defer();return a=j.navigator.geolocation.watchPosition(function(a){h.$broadcast("angulargeo:watchposition",a)},function(a){d.reject(a)},b),d.promise},clearWatch:function(){if(!c)throw new Error(k.errors.unsupportedBrowser);j.navigator.geolocation.clearWatch(a)}}}}})}).call(this);
View
2 package.json
@@ -1,6 +1,6 @@
{
"name": "AngularGeo",
- "version": "0.1.0",
+ "version": "0.2.0",
"description": "AngularGeo\r ==========",
"main": "angulargeo.js",
"scripts": {
View
28 scripts/angulargeo.js
@@ -6,12 +6,17 @@
"use strict";
var angularGeo = angular.module('angular-geo', []);
+ angularGeo.constant('angularGeo_msgs', {
+ 'errors.unsupportedBrowser':'Browser geolocation not supported',
+ 'errors.noServices':'angularGeo could not locate any of the geo providers specified, verify that you have them properly linked',
+ 'errors.noProviders':'angularGeo requires at least one geo provider'
+ });
angularGeo.provider('angularGeo', function() {
var $$geoConfig = {
providerSvcNames: [],
providers: []
};
- var $$supportsGeolocation = 'geolocation' in navigator;
+ var $$supportsGeolocation = false;
var $$watchId;
var $$currentProvider = 0;
@@ -20,9 +25,12 @@
$$geoConfig.providerSvcNames.push(providerSvcName);
return this;
},
- $get: function ($log, $q, $timeout, $rootScope, $injector) {
+ $get: function ($log, $q, $timeout, $rootScope, $injector, $window, angularGeo_msgs) {
+
+ $$supportsGeolocation = 'geolocation' in $window.navigator;
+
if($$geoConfig.providerSvcNames.length === 0) {
- throw new Error("AngularGeo requires at least 1 geo provider");
+ throw new Error(angularGeo_msgs.errors.noProviders);
}
// Instantiate the geo providers and store them within the $$geoConfig object
for(var i = 0; i < $$geoConfig.providerSvcNames.length; i++) {
@@ -34,7 +42,7 @@
}
var $$providers = $$geoConfig.providers;
if($$providers.length === 0) {
- throw new Error('angularGeo could not locate any of the geo providers specified, verify that you have them properly linked');
+ throw new Error(angularGeo_msgs.errors.noServices);
}
var $$geocode = function(address, bounds, region, restrictions, filters, promise) {
@@ -64,10 +72,10 @@
getCurrentPosition: function(options, autoReverseGeocode) {
var self = this;
if(!$$supportsGeolocation) {
- throw new Error("Browser geolocation not supported");
+ throw new Error(angularGeo_msgs.errors.unsupportedBrowser);
}
var deferred = $q.defer();
- navigator.geolocation.getCurrentPosition(function(pos) {
+ $window.navigator.geolocation.getCurrentPosition(function(pos) {
if(autoReverseGeocode) {
var p = self.reverseGeocode({latitude: pos.coords.latitude, longitude: pos.coords.longitude}, null, null, null, null);
p.then(function(results) {
@@ -85,10 +93,10 @@
watchPosition: function(options) {
var self = this;
if(!$$supportsGeolocation) {
- throw new Error("Browser geolocation not supported");
+ throw new Error(angularGeo_msgs.errors.unsupportedBrowser);
}
var deferred = $q.defer();
- $$watchId = navigator.geolocation.watchPosition(function(pos) {
+ $$watchId = $window.navigator.geolocation.watchPosition(function(pos) {
$rootScope.$broadcast("angulargeo:watchposition", pos);
}, function(err) {
deferred.reject(err);
@@ -98,9 +106,9 @@
},
clearWatch: function() {
if(!$$supportsGeolocation) {
- throw new Error("Browser geolocation not supported");
+ throw new Error(angularGeo_msgs.errors.unsupportedBrowser);
}
- navigator.geolocation.clearWatch($$watchId);
+ $window.navigator.geolocation.clearWatch($$watchId);
}
}
}

0 comments on commit caeae92

Please sign in to comment.
Something went wrong with that request. Please try again.