Advertisement
Guest User

stackoverflow

a guest
Aug 5th, 2010
116
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function loadAvatar(o)
  2. {
  3.  
  4.     var s = {}
  5.     $.extend(s,o);
  6.    
  7.    
  8.  
  9.     var current = $('<li class="ul_ava_wr">'
  10.             +'<div class="ul_ava'+((s.data[s.i].avatar) ? ' ' : ' unknown')+'" id="cl_'+s.data[s.i].client_id+'" client_id="'+s.data[s.i].client_id+'">'
  11.                 +'<span class="add_i" style="visibility:hidden;"><img src="../images/plus.png" /></span>'
  12.             +'</div>'
  13.         +'</li>').appendTo(s.ul);
  14.  
  15.    
  16.  
  17.     if(s.data[s.i].avatar)
  18.     {
  19.        
  20.        
  21.         // setTimeout(function(u){
  22.            
  23.             var img = new Image();
  24.             img.onload = function(u){
  25.                
  26.                 return function()
  27.                 {
  28.                     $(this).appendTo(users_table.find('#cl_'+u.data.client_id)); // .removeClass('ajax')).hide().fadeIn(300,function(){
  29.                    
  30.                         bindInvite({ref: $(this).parents('*[client_id]'), filter:'.add_i'});
  31.                        
  32.                         // console.log(u.counter + 1);
  33.                         // console.log(u.overall);
  34.                         // console.log((u.counter + 1) == u.overall);
  35.                         /* If the last image is loaded successfully, only then we proceed to next ajax call  */
  36.                         if((u.i + 1) == u.overall)
  37.                         {                          
  38.                            
  39.                             /* Hiding upper photos for performance gain*/
  40.                             // if($(document).scrollTop() > $(window).height())
  41.                             // {
  42.                                 // var all_avatars = users_table.find('.ul_ava_wr').length;
  43.                                 // var hidden = users_table.find('.ul_ava_wr:lt('+(all_avatars - images_fit_page)+')');
  44.                                 // hidden.hide();
  45.                                 // // console.log(hidden);
  46.                             // }
  47.                            
  48.                             /* Setting ajax flag, to allow next ajax call */
  49.                             processing_users = false;
  50.                            
  51.                             /* If after ajax request conditions still doesn't meet, we loop ajax until it does */
  52.                             var to_top = $(document).scrollTop();
  53.                             var height = $(document).height();
  54.                             var to_bottom = height - to_top;
  55.  
  56.                             // console.log(to_top);
  57.                             // console.log(height);
  58.                             // console.log(to_bottom);
  59.                             // console.log($(window).height());
  60.                             // console.log(Math.round(((to_bottom - $(window).height()) / height) * 100));
  61.                            
  62.                             // console.log(to_top);
  63.                             // console.log(Math.round(((to_bottom - $(window).height()) / height) * 100));
  64.                             if(Math.round(((to_bottom - $(window).height()) / height) * 100) == 0)
  65.                             {
  66.  
  67.                                 listUsers({start_from:users_start_from});
  68.                            
  69.                             }
  70.                         }
  71.                         else
  72.                         {
  73.                             s.i++;
  74.                             loadAvatar(s);
  75.                        
  76.                         }
  77.                        
  78.                        
  79.                     // });
  80.                    
  81.                     // console.log($(document).scrollTop());
  82.                 }  
  83.                
  84.             }({data:s.data[s.i], i:s.i, overall:s.overall});
  85.             img.src = u.data.avatar;
  86.            
  87.             // console.log($(document).scrollTop());
  88.            
  89.         // },s.timer,{data:s.data[s.i], i:s.i, overall:s.overall});
  90.        
  91.         // s.timer += 10;
  92.        
  93.        
  94.     }
  95.     else
  96.     {
  97.        
  98.         bindInvite({ref: current.find('*[client_id]'), filter:'.add_i'});
  99.         s.i++;
  100.         loadAvatar(s);
  101.        
  102.    
  103.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement