Changeset 22683


Ignore:
Timestamp:
May 16, 2013, 6:31:48 AM (11 years ago)
Author:
rvelices
Message:

feature 2885: Add geoip info in the stats / history page

  • use jsonp (cross origin)
  • use localStorage cache
  • use tiptip instead of ui tooltip
Location:
trunk/admin/themes/default
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/admin/themes/default/js/jquery.geoip.js

    r22664 r22683  
    55       
    66        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
    724                if (GeoIp.cache.hasOwnProperty(ip))
    825                        callback(GeoIp.cache[ip]);
     
    1330                        jQuery.ajax( {
    1431                                url: "http://freegeoip.net/json/" + ip,
    15                                 dataType: "json",
     32                                dataType: "jsonp",
     33                                cache: true,
    1634                                success: function(data) {
     35                                        data.reqTime = (new Date()).getTime();
    1736                                        var res=[];
    1837                                        if (data.city) res.push(data.city);
     
    2948
    3049                                error: function() {
    31                                         var data = {ip:ip, fullName:""};
     50                                        var data = {ip:ip, fullName:"", reqTime: (new Date()).getTime()};
    3251
    3352                                        GeoIp.cache[ip] = data;
  • trunk/admin/themes/default/template/history.tpl

    r22664 r22683  
    137137
    138138{combine_script id='jquery.geoip' load='async' path='admin/themes/default/js/jquery.geoip.js'}
    139 {combine_script id='jquery.ui.tooltip' load='footer'}
    140139
    141140{footer_script}{literal}
    142 jQuery(".IP").tooltip( {
    143         items: "*",
    144         /*show: {delay:0, effect:"show"},
    145         hide: {delay:50, effect:"hide"},*/
    146         content: function(response) {
    147                 var that = $(this);
    148                 GeoIp.get( that.text(), function(data) {
    149                         response( data.fullName );
     141jQuery(".IP").one( "mouseenter", function(){
     142        var that = $(this);
     143        that
     144                .data("isOver", true)
     145                .one("mouseleave", function() {
     146                        that.removeData("isOver");
    150147                });
    151         }
    152 });
     148        GeoIp.get( that.text(), function(data) {
     149                if (!data.fullName) return;
     150                that.tipTip( {
     151                        content: data.fullName
     152                        }       );
     153                if (that.data("isOver"))
     154                        that.trigger("mouseenter");
     155        });
     156} );
    153157{/literal}{/footer_script}
Note: See TracChangeset for help on using the changeset viewer.