Guest User

tabapp

a guest
Feb 3rd, 2014
414
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. $(document).ready(function () {
  2.     $('ul.tabs').each(function () {
  3.         // For each set of tabs, we want to keep track of
  4.         // which tab is active and it's associated content
  5.         var $active, $content, $links = $(this).find('a');
  6.  
  7.         if ($('#_ctl0_hdnCurrentTabSelection').val() == "") {
  8.             $('#_ctl0_hdnCurrentTabSelection').val(location.hash)
  9.         }
  10.  
  11.         // If the location.hash matches one of the links, use that as the active tab.
  12.         // If no match is found, use the first link as the initial active tab.
  13.         $active = $($links.filter('[href="' + $('#_ctl0_hdnCurrentTabSelection').val() + '"]')[0] || $links[0]);
  14.         $active.addClass('active');
  15.         $content = $($active.attr('href'));
  16.         window.location.href = window.location.href.toString().split('#')[0] + $active.attr('href');
  17.  
  18.         // Hide the remaining content
  19.         $links.not($active).each(function () {
  20.             $($(this).attr('href')).hide();
  21.         });
  22.  
  23.         // Bind the click event handler
  24.         $(this).on('click', 'a', function (e) {
  25.             // Make the old tab inactive.
  26.             $active.removeClass('active');
  27.             //window.location.href = window.location.href.toString().replace($active.attr('href'), '');
  28.             $content.hide();
  29.  
  30.             // Update the variables with the new link and content
  31.             $active = $(this);
  32.             $('#_ctl0_hdnCurrentTabSelection').val($active.attr("href"))
  33.             $content = $($(this).attr('href'));
  34.             window.location.href = window.location.href.toString().split('#')[0] + $active.attr('href');
  35.  
  36.             // Make the tab active.
  37.             $active.addClass('active');
  38.             $content.show();
  39.  
  40.             // Prevent the anchor's default click action
  41.             e.preventDefault();
  42.         });
  43.     });
  44.  
  45.     $(document).on('keydown',function(e) {
  46.         var keyCode = e.keyCode || e.which;
  47.        
  48.         if (keyCode === 9) {
  49.             if(!$('#tab1:last-child').is(':focus') && window.location.href.search('tab1') != -1){
  50.                 $('#ATab1').removeClass('active');
  51.                 $('#ATab2').addClass('active');
  52.  
  53.                 $('#tab1').hide();
  54.                 $('#tab2').show();
  55.                 $('#tab3').hide();
  56.                 $('#tab4').hide();
  57.                 $('#tab5').hide();
  58.                  
  59.                  
  60.                 window.location = "#tab2";
  61.             }
  62.             else if(!$('#tab2:last-child').is(':focus') && window.location.href.search('tab2') != -1){
  63.                 $('#ATab2').removeClass('active');
  64.                 $('#ATab3').addClass('active');
  65.  
  66.                 $('#tab1').hide();
  67.                 $('#tab2').hide();
  68.                 $('#tab3').show();
  69.                
  70.                 window.location = "#tab3";
  71.             }
  72.             else if(!$('#tab3:last-child').is(':focus') && window.location.href.search('tab3') != -1){
  73.                 $('#ATab3').removeClass('active');
  74.                 $('#ATab4').addClass('active');
  75.  
  76.                 $('#tab1').hide();
  77.                 $('#tab2').hide();
  78.                 $('#tab3').hide();
  79.                 $('#tab4').show();
  80.                 window.location = "#tab4";
  81.             }
  82.  
  83.             else if(!$('#tab4:last-child').is(':focus') && window.location.href.search('tab4') != -1){
  84.                 $('#ATab4').removeClass('active');
  85.                 $('#ATab5').addClass('active');
  86.  
  87.                 $('#tab1').hide();
  88.                 $('#tab2').hide();
  89.                 $('#tab3').hide();
  90.                 $('#tab4').hide();
  91.                 $('#tab5').show();
  92.                 window.location = "#tab5";
  93.             }
  94.  
  95.             else if(!$('#tab5:last-child').is(':focus') && window.location.href.search('tab5') != -1){
  96.                 $('#ATab5').removeClass('active');
  97.                 $('#ATab6').addClass('active');
  98.  
  99.                 $('#tab1').hide();
  100.                 $('#tab2').hide();
  101.                 $('#tab3').hide();
  102.                 $('#tab4').hide();
  103.                 $('#tab5').hide();
  104.                  $('#tab6').show();
  105.                 window.location = "#tab6";
  106.             }
  107.  
  108.             else if(!$('#tab6:last-child').is(':focus') && window.location.href.search('tab6') != -1){
  109.                 $('#ATab6').removeClass('active');
  110.                 $('#ATab1').addClass('active');
  111.  
  112.                 $('#tab1').show();
  113.                 $('#tab2').hide();
  114.                 $('#tab3').hide();
  115.                 $('#tab4').hide();
  116.                 $('#tab5').hide();
  117.                 $('#tab6').hide();
  118.                 $('#tab7').hide();
  119.                 window.location = "#tab1";
  120.             }
  121.  
  122.  
  123.                
  124.         }
  125.             e.preventDefault();
  126.  
  127.      });
  128. });
  129.  
  130.  
  131. <!DOCTYPE html>
  132. <html>
  133.     <head>
  134.         <meta charset='utf-8'/>
  135.         <title>jQuery Tabs Demo</title>
  136.         <style>
  137.             * {padding:0; margin:0;}
  138.  
  139.             html {
  140.                 background:url(/img/tiles/wood.png) 0 0 repeat;
  141.                 padding:15px 15px 0;
  142.                 font-family:sans-serif;
  143.                 font-size:14px;
  144.             }
  145.  
  146.             p, h3 {
  147.                 margin-bottom:15px;
  148.             }
  149.  
  150.             div {
  151.                 padding:10px;
  152.                 width:600px;
  153.                 background:#fff;
  154.             }
  155.  
  156.             .tabs li {
  157.                 list-style:none;
  158.                 display:inline;
  159.             }
  160.  
  161.             .tabs a {
  162.                 padding:5px 10px;
  163.                 display:inline-block;
  164.                 background:#666;
  165.                 color:#fff;
  166.                 text-decoration:none;
  167.             }
  168.  
  169.             .tabs a.active {
  170.                 background:#fff;
  171.                 color:#000;
  172.             }
  173.  
  174.         </style>
  175.         <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js"></script>
  176.         <script src="global.js"></script>
  177.         <script src="http://code.jquery.com/ui/1.10.3/jquery-ui.js"></script>
  178.     </head>
  179.     <body>
  180.     <div id="tabs">
  181.         <ul class='tabs'>
  182.             <li><a id="ATab1" href='#tab1'>Tab 1</a></li>
  183.             <li><a id="ATab2" href='#tab2' >Tab 2</a></li>
  184.             <li><a id="ATab3" href='#tab3' >Tab 3</a></li>
  185.             <li><a id="ATab4" href='#tab4' >Tab 4</a></li>
  186.             <li><a id="ATab5" href='#tab5' >Tab 5</a></li>
  187.             <li><a id="ATab6" href='#tab6' >Tab 6</a></li>
  188.            
  189.         </ul>
  190.         <div id='tab1'>
  191.             <h3>Section 1</h3>
  192.             Fisrt: <input type="textbox" />
  193.             <br />
  194.             Second: <input type="textbox" />
  195.             <br />
  196.             Third: <input type="textbox" />
  197.             <br />
  198.             Fourth: <input type="textbox" />
  199.         </div>
  200.         <div id='tab2'>
  201.             <h3>Section 2</h3>
  202.             Fifth: <input type="textbox" />
  203.             <br />
  204.             Sixth: <input type="textbox" />
  205.         </div>
  206.         <div id='tab3'>
  207.             <h3>Section 3</h3>
  208.             Seventh: <input type="textbox" />
  209.             <br />
  210.             Eighth: <input type="textbox" />
  211.         </div>
  212.         <div id='tab4'>
  213.         <h3>Section 4</h3>
  214.             ninth: <input type="textbox" />
  215.             <br />
  216.             tength: <input type="textbox" />
  217.         </div>
  218.         <div id='tab5'>
  219.         <h3>section 5</h3>
  220.         11: <input type="textbox" />
  221.         <br />
  222.         12: <input type="textbox" />
  223.     </div>
  224.  
  225.         <div id='tab6'>
  226.         <h3>section 6</h3>
  227.         13: <input type="textbox" />
  228.         <br />
  229.         14: <input type="textbox" />
  230.     </div>
  231.  
  232.        
  233.    
  234.     </body>
  235. </html>
Advertisement
Add Comment
Please, Sign In to add comment