Advertisement
Guest User

bubble-hover.js + groups functions

a guest
Dec 23rd, 2010
199
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. jQuery(document).ready(function($) {
  2.     function getClientWidth() { return document.compatMode=='CSS1Compat' && !window.opera?document.documentElement.clientWidth:document.body.clientWidth;   }
  3.     function getClientHeight() { return document.compatMode=='CSS1Compat' && !window.opera?document.documentElement.clientHeight:document.body.clientHeight; }
  4.    
  5.     $(function() {
  6.         var hideDelay = 0;
  7.         var hideTimer = null;
  8.         var x; // hack: variable for ajax object
  9.         var y; // hack: variable for ajax object
  10.         var showDelay = 0; // delay before the pop-up shows itself in ms
  11.  
  12.         var container = $('<div id="popupContainer"><table width="" border="0" cellspacing="0" cellpadding="0" align="center" class="popupBubble"><tr><td class="corner topLeft"></td><td class="top"></td><td class="corner topRight"></td></tr><tr><td class="left">&nbsp;</td><td><div id="popupContent"></div></td><td class="right">&nbsp;</td></tr><tr><td class="corner bottomLeft">&nbsp;</td><td class="bottom">&nbsp;</td><td class="corner bottomRight"></td></tr></table></div>');
  13.  
  14.         $('body').append(container);
  15.  
  16.         $('.avatar').live('mouseover', function() {
  17.  
  18.             // format of 'rel' tag: userID
  19.             var userID = $(this).attr('rel');
  20.            
  21.             if ( !userID )  {
  22.            
  23.                 var groupID = $(this).attr('class');
  24.                 var groupID = groupID.match(/\d+/);
  25.                 var groupID = parseInt(groupID);               
  26.  
  27.                 if (hideTimer)
  28.                 clearTimeout(hideTimer);
  29.            
  30.                 var pos = $(this).offset();
  31.                 var width = $(this).width();
  32.                
  33.                 $.data(this, 'timer', setTimeout(function() {                  
  34.  
  35.                 container.css({
  36.                         left: (pos.left + width) + 'px',
  37.                         top: pos.top - 5 + 'px'
  38.                 });
  39.  
  40.                 container.css('display', 'block');
  41.                    
  42.                 var loading = '<img src="'+ajax_image+'/ajax-loader.gif" alt="Loading" />';
  43.                 $('div#popupContent').html(loading);
  44.                
  45.                 if(y) {y.abort(); y = null; }
  46.                
  47.                 y = $.ajax({
  48.                     type: 'GET',
  49.                     url: ajax_url,
  50.                     data: {
  51.                         ID: groupID,
  52.                         action: 'the_groupinfo'
  53.                     },
  54.                     success: function(data) {
  55.  
  56.                         //if (data.indexOf(groupID) > 0) {
  57.                             var text = $(data).html();
  58.                             $('div#popupContent').html(text);
  59.                                 var right = getClientWidth() - pos.left - width;
  60.                                 var boxWidth = $('div#popupContainer').width();
  61.                                 if ( boxWidth < right ) {
  62.                                     container.css({
  63.                                         left: (pos.left + width) + 'px',
  64.                                         top: pos.top - 5 + 'px'
  65.                                     });
  66.                                 }else{
  67.                                     container.css({
  68.                                         left: (pos.left - boxWidth) + 'px',
  69.                                         top: pos.top - 5 + 'px'
  70.                                     })
  71.                                 }
  72.                             container.css('display', 'block');
  73.                         //}
  74.                     }
  75.                 });
  76.              
  77.  
  78.              }, showDelay ));
  79.  
  80.             };         
  81.          
  82.               // If no userID and groupiD in url tag, don't popup blank
  83.             if ( !userID && !groupID )             
  84.                 return;
  85.                
  86.             if ( userID )   {
  87.  
  88.             if (hideTimer)
  89.                 clearTimeout(hideTimer);
  90.            
  91.             var pos = $(this).offset();
  92.             var width = $(this).width();
  93.            
  94.             $.data(this, 'timer', setTimeout(function() {
  95.                
  96.                    
  97.                 // hack
  98.                 // display the container before the ajax request
  99.                 container.css({
  100.                         left: (pos.left + width) + 'px',
  101.                         top: pos.top - 5 + 'px'
  102.                 });
  103.  
  104.                 container.css('display', 'block');
  105.                    
  106.                 // populate the popup with a loader.gif
  107.                 var loading = '<img src="'+ajax_image+'/ajax-loader.gif" alt="Loading" />';
  108.                 $('div#popupContent').html(loading);
  109.                
  110.                 // check for the current ajax request and abort it if needed
  111.                 if(x) {x.abort(); x = null; }                  
  112.                 // end hack                            
  113.  
  114.                 x = $.ajax({
  115.                     type: 'GET',
  116.                     url: ajax_url,
  117.                     data: {
  118.                         ID: userID,
  119.                         action: 'the_personalinfo'
  120.                     },
  121.                     success: function(data) {
  122.  
  123.                         // Verify requested person is this person since we could have multiple ajax requests out if the server is taking a while.
  124.                         if (data.indexOf(userID) > 0) {
  125.                             var text = $(data).html();
  126.                             $('div#popupContent').html(text);
  127.                                 var right = getClientWidth() - pos.left - width;
  128.                                 var boxWidth = $('div#popupContainer').width();
  129.                                 if ( boxWidth < right ) {
  130.                                     container.css({
  131.                                         left: (pos.left + width) + 'px',
  132.                                         top: pos.top - 5 + 'px'
  133.                                     });
  134.                                 }else{
  135.                                     container.css({
  136.                                         left: (pos.left - boxWidth) + 'px',
  137.                                         top: pos.top - 5 + 'px'
  138.                                     })
  139.                                 }
  140.                             container.css('display', 'block');
  141.                         }
  142.                     }
  143.                 });
  144.              
  145.  
  146.              }, showDelay ));
  147.              
  148.              
  149. };
  150.  
  151.                      
  152.         }).live('mouseout', function() {
  153.             clearTimeout($.data(this, 'timer'));
  154.         });
  155.  
  156.         $('.avatar').live('mouseout', function() {
  157.             if (hideTimer)
  158.                 clearTimeout(hideTimer);
  159.             hideTimer = setTimeout(function() {
  160.                 // hack: abort the ajax request
  161.                 if(x) {x.abort(); x = null; }
  162.                 container.css('display', 'none');
  163.             }, hideDelay);
  164.         });
  165.  
  166.         // Allow mouseover of details without hiding details
  167.         $('#popupContainer').mouseover(function() {
  168.             if (hideTimer)
  169.                 clearTimeout(hideTimer);
  170.         });
  171.  
  172.         // Hide after mouseout
  173.         $('#popupContainer').mouseout(function() {
  174.             if (hideTimer)
  175.                 clearTimeout(hideTimer);
  176.             hideTimer = setTimeout(function() {
  177.                 // hack: abort the ajax request;
  178.                 if(x) {x.abort(); x = null; }
  179.                 container.css('display', 'none');
  180.             }, hideDelay);
  181.         });
  182.     });
  183.  
  184.     // Select all checkboxes after clicking the link All
  185.         $("a[href='#select_all']").click( function() {
  186.            $("input:checkbox.link").attr('checked', 'checked');
  187.             return false;
  188.         });
  189.  
  190. });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement