Skip to content

Commit

Permalink
gallery-2011.05.12-13-26 nzakas gallery-geo
Browse files Browse the repository at this point in the history
  • Loading branch information
YUI Builder committed May 12, 2011
1 parent 7cc3854 commit 6a37199
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 10 deletions.
7 changes: 4 additions & 3 deletions src/gallery-geo/demo/geo.html
@@ -1,3 +1,5 @@
<!DOCTYPE html>

<html>
<head>
<title>Geo Demo</title>
Expand All @@ -9,7 +11,7 @@ <h1>Geo Tests</h1>
<script type="text/javascript">

YUI({
gallery: 'gallery-2009.12.08-22',
gallery: 'gallery-2011.05.04-20-03',
modules: {
'gallery-geo': {
fullpath: '../../../build/gallery-geo/gallery-geo.js',
Expand All @@ -29,11 +31,10 @@ <h1>Geo Tests</h1>
console.log(data.coords.longitude);
console.log(data.coords.accuracy);
}
});
}, null, { enableHighAccuracy: true });

});


</script>
</body>
</html>
30 changes: 23 additions & 7 deletions src/gallery-geo/js/geo.js
Expand Up @@ -20,8 +20,11 @@
* four properties: success (true/false), coords (an object),
* timestamp, and source ("native" or "geoplugin").
* @param scope {Object} (Optional) The this value for the callback function.
* @param opts {Object} (Optional) The PositionOptions object passed to
* the getCurrentPosition function and has three optional properties:
* enableHighAccuracy (true/false), timeout (number), maximumAge (number).
*/
function getCurrentPositionByAPI(callback, scope){
function getCurrentPositionByAPI(callback, scope, opts){
navigator.geolocation.getCurrentPosition(
function(data){
callback.call(scope, {
Expand All @@ -43,9 +46,10 @@ function getCurrentPositionByAPI(callback, scope){
if (error.code == 1) { //user denied permission, so don't do anything
callback.call(scope, { success: false, denied: true });
} else { //try Geo IP Lookup instead
getCurrentPositionByGeoIp(callback,scope);
getCurrentPositionByGeoIP(callback,scope);
}
}
},
opts
);
}

Expand All @@ -54,11 +58,19 @@ function getCurrentPositionByAPI(callback, scope){
* @param callback {Function} The callback function to call when the
* request is complete. The object passed into the request has
* four properties: success (true/false), coords (an object),
* timestamp, and source ("native" or "geoplugin").
* timestamp, and source ("native" or "pidgets.geoip").
* @param scope {Object} (Optional) The this value for the callback function.
* @param opts {Object} (Optional) The PositionOptions object passed to
* the getCurrentPosition function and has three optional properties:
* enableHighAccuracy (true/false) which is ingored, timeout (number),
* maximumAge (number) passed to YQL request as maxAge URL-query param.
*/
function getCurrentPositionByGeoIP(callback, scope){
function getCurrentPositionByGeoIP(callback, scope, opts){

opts = opts || {};
var yqlParams = Y.Lang.isNumber(opts.maximumAge) ?
{ _maxage: opts.maximumAge } : {};

Y.YQL("select * from pidgets.geoip", {
on: {
success: function(response){
Expand All @@ -82,9 +94,13 @@ function getCurrentPositionByGeoIP(callback, scope){
},
failure: function(){
callback.call(scope, { success: false });
},
timeout: function(){
callback.call(scope, { success: false });
}
}
});
},
timeout: opts.timeout
}, yqlParams);

}

Expand Down

0 comments on commit 6a37199

Please sign in to comment.