Advertisement
bojanCG

JS for tabs

Aug 9th, 2015
19
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. var selectedCalcTab = 0;
  2.  
  3. function someFunction(idNumber) {
  4.     if(condition) {
  5.         $( "#tabs" ).tabs( "enable", "#tabs-" + idNumber );
  6.         if (idNumber === 2) {
  7.             $( "#secondary-tabs" ).tabs( "enable", "#graph-tabs-2" );
  8.         }
  9.     }
  10. }
  11.  
  12. $(document).ready(function() {
  13.  
  14.     // init tabs
  15.     $("#tabs").tabs();
  16.     $("#secondary-tabs").tabs();
  17.  
  18.     // disabling some tabs
  19.     $("#tabs").tabs("disable", "#tabs-2");
  20.     $("#tabs").tabs("disable", "#tabs-3");
  21.     $("#graph-tabs").tabs("disable", "#graph-tabs-2");
  22.  
  23.     // formatting spacing
  24.     $("#tabs").find("ul li").css({'margin-right':'0px'});
  25.     $("#graph-tabs").find("ul li").css({'margin-right':'-5px'});
  26.  
  27.     // stop scrolling to tab content
  28.     $('#tabs').click('tabsselect', function (event, ui) {
  29.         var selectedTab = $("#tabs").tabs('option','active');
  30.         $('html, body').stop();
  31.         if (selectedTab === 0) {
  32.             someFunction(1);
  33.             selectedCalcTab = 1;
  34.         } else if (selectedTab === 1) {
  35.             someFunction(2);
  36.             selectedCalcTab = 2;
  37.         } else if (selectedTab === 2) {
  38.             someFunction(3);
  39.             selectedCalcTab = 3;
  40.         }
  41.     });
  42.  
  43.     $('#secondary-tabs').click('tabsselect', function (event, ui) {
  44.         var selectedSecondaryTab = $('#secondary-tabs').tabs('option','active');
  45.         $('html, body').stop();
  46.         if (selectedSecondaryTab === 0) {
  47.             if (selectedCalcTab === 1) {
  48.                 someFunction(1);
  49.             } else if (selectedCalcTab === 2) {
  50.                 someFunction(2);
  51.             } else if (selectedCalcTab === 3) {
  52.                 someFunction(3);
  53.             }
  54.         } else if (selectedSecondaryTab === 1) {
  55.             someFunction(1);
  56.         }
  57.     });
  58.  
  59.     // more stuff happening to tabs later in code
  60.     $("#someButton").click(function() {
  61.         $("#tabs").tabs("disable", "#tabs-2");
  62.         $("#tabs").tabs("disable", "#tabs-3");
  63.         $("#secondary-tabs").tabs("option", "active", 0);
  64.         $("#secondary-tabs").tabs("disable", "#secondary-tabs-2");
  65.         return false;
  66.     });
  67.  
  68. });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement