includes/clientside/static/userpage.js
changeset 672 08a7875258b4
child 699 c7d737202d59
equal deleted inserted replaced
671:267c9f93b51f 672:08a7875258b4
       
     1 // Tabs on userpage
       
     2 
       
     3 var userpage_blocks = [];
       
     4 
       
     5 var userpage_onload = function()
       
     6 {
       
     7   var wrapper = document.getElementById('userpage_wrap');
       
     8   var links = document.getElementById('userpage_links');
       
     9   
       
    10   wrapper.className = 'userpage_wrap';
       
    11   links.className = 'userpage_links';
       
    12   
       
    13   var blocks = wrapper.getElementsByTagName('div');
       
    14   var first_block = false;
       
    15   for ( var i = 0; i < blocks.length; i++ )
       
    16   {
       
    17     var block = blocks[i];
       
    18     if ( /^tab:/.test(block.id) )
       
    19     {
       
    20       $(block).addClass('userpage_block');
       
    21       var block_id = block.id.substr(4);
       
    22       userpage_blocks.push(block_id);
       
    23       if ( !first_block )
       
    24       {
       
    25         // this is the first block on the page, memorize it
       
    26         first_block = block_id;
       
    27       }
       
    28     }
       
    29   }
       
    30   // init links
       
    31   var as = links.getElementsByTagName('a');
       
    32   for ( var i = 0; i < as.length; i++ )
       
    33   {
       
    34     var a = as[i];
       
    35     if ( a.href.indexOf('#') > -1 )
       
    36     {
       
    37       var hash = a.href.substr(a.href.indexOf('#'));
       
    38       var blockid = hash.substr(5);
       
    39       a.blockid = blockid;
       
    40       a.onclick = function()
       
    41       {
       
    42         userpage_select_block(this.blockid);
       
    43         return false;
       
    44       }
       
    45       a.id = 'userpage_blocklink_' + blockid;
       
    46     }
       
    47   }
       
    48   if ( $_REQUEST['tab'] )
       
    49   {
       
    50     userpage_select_block($_REQUEST['tab'], true);
       
    51   }
       
    52   else
       
    53   {
       
    54     userpage_select_block(first_block, true);
       
    55   }
       
    56 }
       
    57 
       
    58 addOnloadHook(userpage_onload);
       
    59 
       
    60 /**
       
    61  * Select (show) the specified block on the userpage.
       
    62  * @param string block name
       
    63  * @param bool If true, omits transition effects.
       
    64  */
       
    65 
       
    66 function userpage_select_block(block, nofade)
       
    67 {
       
    68   // memorize existing scroll position, reset the hash, then scroll back to where we were
       
    69   // a little hackish and might cause a flash, but it's better than hiding the tabs on each click
       
    70   var currentScroll = getScrollOffset();
       
    71   
       
    72   var current_block = false;
       
    73   nofade = true;
       
    74   for ( var i = 0; i < userpage_blocks.length; i++ )
       
    75   {
       
    76     var div = document.getElementById('tab:' + userpage_blocks[i]);
       
    77     if ( div )
       
    78     {
       
    79       if ( div.style.display != 'none' )
       
    80       {
       
    81         current_block = userpage_blocks[i];
       
    82         if ( nofade || aclDisableTransitionFX )
       
    83         {
       
    84           div.style.display = 'none';
       
    85         }
       
    86       }
       
    87     }
       
    88     var a = document.getElementById('userpage_blocklink_' + userpage_blocks[i]);
       
    89     if ( a )
       
    90     {
       
    91       if ( $(a.parentNode).hasClass('userpage_tab_active') )
       
    92       {
       
    93         $(a.parentNode).rmClass('userpage_tab_active');
       
    94       }
       
    95     }
       
    96   }
       
    97   if ( nofade || !current_block || aclDisableTransitionFX )
       
    98   {
       
    99     var div = document.getElementById('tab:' + block);
       
   100     div.style.display = 'block';
       
   101   }
       
   102   /*
       
   103   else
       
   104   {
       
   105     // do this in a slightly fancier fashion
       
   106     load_component('SpryEffects');
       
   107     (new Spry.Effect.Blind('tab:' + current_block, { from: '100%', to: '0%', finish: function()
       
   108         {
       
   109           (new Spry.Effect.Blind('tab:' + block, { from: '0%', to: '100%' })).start();
       
   110         }
       
   111       })).start();
       
   112   }
       
   113   */
       
   114   var a = document.getElementById('userpage_blocklink_' + block);
       
   115   $(a.parentNode).addClass('userpage_tab_active');
       
   116   
       
   117   window.location.hash = 'tab:' + block;
       
   118   setScrollOffset(currentScroll);
       
   119 }