diff options
author | rvelices <rv-github@modusoptimus.com> | 2013-05-16 04:31:48 +0000 |
---|---|---|
committer | rvelices <rv-github@modusoptimus.com> | 2013-05-16 04:31:48 +0000 |
commit | 42bdfe8c8da23aba61c43b74b484849b48b3d25c (patch) | |
tree | 93d5adbf80a9e310519937de3bfffab822c02532 /admin/themes/default/js | |
parent | 237a642dda08ae6057355fdd377fe8dca9cc25d8 (diff) |
feature 2885: Add geoip info in the stats / history page
- use jsonp (cross origin)
- use localStorage cache
- use tiptip instead of ui tooltip
git-svn-id: http://piwigo.org/svn/trunk@22683 68402e56-0260-453c-a942-63ccdbb3a9ee
Diffstat (limited to 'admin/themes/default/js')
-rw-r--r-- | admin/themes/default/js/jquery.geoip.js | 23 |
1 files changed, 21 insertions, 2 deletions
diff --git a/admin/themes/default/js/jquery.geoip.js b/admin/themes/default/js/jquery.geoip.js index fae389190..eb4a58b4d 100644 --- a/admin/themes/default/js/jquery.geoip.js +++ b/admin/themes/default/js/jquery.geoip.js @@ -4,6 +4,23 @@ GeoIp = { pending: {}, get: function(ip, callback){ + if (!GeoIp.storageInit && window.localStorage) { + GeoIp.storageInit = true; + var cache = localStorage.getItem("freegeoip"); + if (cache) { + cache = JSON.parse(cache); + for (var ip in cache) { + var data = cache[ip]; + if ( (new Date()).getTime() - data.reqTime > 36 * 3600000) + delete cache[ip]; + } + GeoIp.cache = cache; + } + jQuery(window).on("unload", function() { + localStorage.setItem("freegeoip", JSON.stringify(GeoIp.cache) ); + } ); + } + if (GeoIp.cache.hasOwnProperty(ip)) callback(GeoIp.cache[ip]); else if (GeoIp.pending[ip]) @@ -12,8 +29,10 @@ GeoIp = { GeoIp.pending[ip] = [callback]; jQuery.ajax( { url: "http://freegeoip.net/json/" + ip, - dataType: "json", + dataType: "jsonp", + cache: true, success: function(data) { + data.reqTime = (new Date()).getTime(); var res=[]; if (data.city) res.push(data.city); if (data.region_name) res.push(data.region_name); @@ -28,7 +47,7 @@ GeoIp = { }, error: function() { - var data = {ip:ip, fullName:""}; + var data = {ip:ip, fullName:"", reqTime: (new Date()).getTime()}; GeoIp.cache[ip] = data; var callbacks = GeoIp.pending[ip]; |