aboutsummaryrefslogtreecommitdiffstats
path: root/admin/themes/default/js/jquery.geoip.js
diff options
context:
space:
mode:
authorrvelices <rv-github@modusoptimus.com>2013-05-14 19:30:26 +0000
committerrvelices <rv-github@modusoptimus.com>2013-05-14 19:30:26 +0000
commitd2c695ee899446f179878e746d5b65d03cb5816e (patch)
tree05d5da08cb4acde0ae24c10167ece3b67f628f7e /admin/themes/default/js/jquery.geoip.js
parente97963464beeaa0c1447fdd23091473781a2a46c (diff)
feature 2885: Add geoip info in the stats / history page
git-svn-id: http://piwigo.org/svn/trunk@22664 68402e56-0260-453c-a942-63ccdbb3a9ee
Diffstat (limited to '')
-rw-r--r--admin/themes/default/js/jquery.geoip.js42
1 files changed, 42 insertions, 0 deletions
diff --git a/admin/themes/default/js/jquery.geoip.js b/admin/themes/default/js/jquery.geoip.js
new file mode 100644
index 000000000..fae389190
--- /dev/null
+++ b/admin/themes/default/js/jquery.geoip.js
@@ -0,0 +1,42 @@
+
+GeoIp = {
+ cache: {},
+ pending: {},
+
+ get: function(ip, callback){
+ if (GeoIp.cache.hasOwnProperty(ip))
+ callback(GeoIp.cache[ip]);
+ else if (GeoIp.pending[ip])
+ GeoIp.pending[ip].push(callback);
+ else {
+ GeoIp.pending[ip] = [callback];
+ jQuery.ajax( {
+ url: "http://freegeoip.net/json/" + ip,
+ dataType: "json",
+ success: function(data) {
+ var res=[];
+ if (data.city) res.push(data.city);
+ if (data.region_name) res.push(data.region_name);
+ if (data.country_name) res.push(data.country_name);
+ data.fullName = res.join(", ");
+
+ GeoIp.cache[ip] = data;
+ var callbacks = GeoIp.pending[ip];
+ delete GeoIp.pending[ip];
+ for (var i=0; i<callbacks.length; i++)
+ callbacks[i].call(null, data);
+ },
+
+ error: function() {
+ var data = {ip:ip, fullName:""};
+
+ GeoIp.cache[ip] = data;
+ var callbacks = GeoIp.pending[ip];
+ delete GeoIp.pending[ip];
+ for (var i=0; i<callbacks.length; i++)
+ callbacks[i].call(null, data);
+ }
+ });
+ }
+ }
+} \ No newline at end of file