Skip to content

Commit

Permalink
Cleanup of Eric's changes
Browse files Browse the repository at this point in the history
  • Loading branch information
Nicholas committed May 9, 2011
1 parent f105120 commit aae6b75
Show file tree
Hide file tree
Showing 4 changed files with 49 additions and 17 deletions.
30 changes: 23 additions & 7 deletions build/gallery-geo/gallery-geo-debug.js
Expand Up @@ -22,8 +22,11 @@ YUI.add('gallery-geo', function(Y) {
* 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 @@ -45,9 +48,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 @@ -56,11 +60,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 @@ -84,9 +96,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
2 changes: 1 addition & 1 deletion build/gallery-geo/gallery-geo-min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

30 changes: 23 additions & 7 deletions build/gallery-geo/gallery-geo.js
Expand Up @@ -22,8 +22,11 @@ YUI.add('gallery-geo', function(Y) {
* 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 @@ -45,9 +48,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 @@ -56,11 +60,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 @@ -84,9 +96,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
4 changes: 2 additions & 2 deletions src/gallery-geo/js/geo.js
Expand Up @@ -58,7 +58,7 @@ function getCurrentPositionByAPI(callback, scope, opts){
* @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:
Expand All @@ -67,7 +67,7 @@ function getCurrentPositionByAPI(callback, scope, opts){
*/
function getCurrentPositionByGeoIP(callback, scope, opts){

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

Expand Down

0 comments on commit aae6b75

Please sign in to comment.