Changeset 22683 for trunk/admin/themes/default/js
- Timestamp:
- May 16, 2013, 6:31:48 AM (12 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/admin/themes/default/js/jquery.geoip.js
r22664 r22683 5 5 6 6 get: function(ip, callback){ 7 if (!GeoIp.storageInit && window.localStorage) { 8 GeoIp.storageInit = true; 9 var cache = localStorage.getItem("freegeoip"); 10 if (cache) { 11 cache = JSON.parse(cache); 12 for (var ip in cache) { 13 var data = cache[ip]; 14 if ( (new Date()).getTime() - data.reqTime > 36 * 3600000) 15 delete cache[ip]; 16 } 17 GeoIp.cache = cache; 18 } 19 jQuery(window).on("unload", function() { 20 localStorage.setItem("freegeoip", JSON.stringify(GeoIp.cache) ); 21 } ); 22 } 23 7 24 if (GeoIp.cache.hasOwnProperty(ip)) 8 25 callback(GeoIp.cache[ip]); … … 13 30 jQuery.ajax( { 14 31 url: "http://freegeoip.net/json/" + ip, 15 dataType: "json", 32 dataType: "jsonp", 33 cache: true, 16 34 success: function(data) { 35 data.reqTime = (new Date()).getTime(); 17 36 var res=[]; 18 37 if (data.city) res.push(data.city); … … 29 48 30 49 error: function() { 31 var data = {ip:ip, fullName:"" };50 var data = {ip:ip, fullName:"", reqTime: (new Date()).getTime()}; 32 51 33 52 GeoIp.cache[ip] = data;
Note: See TracChangeset
for help on using the changeset viewer.