Guest User

Untitled

a guest
Nov 19th, 2017
89
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.04 KB | None | 0 0
  1. // for tab 1
  2. aria-selected="{!$CurrentPage.parameters.selectedTab == 'tab1' ]}"
  3.  
  4. <li class="slds-tabs--scoped {!IF( $CurrentPage.parameters.selectedTab == 'tab1', 'slds-active', '' )}" id="tab1" role="presentation">
  5. <a href="javascript:void(0)" onclick="setSelectedTab( 'tab1' )" role="tab" aria-selected="{!$CurrentPage.parameters.selectedTab == 'tab1'}" class="slds-tab--scoped__link">Tab 1</a>
  6. </li>
  7. <li class="slds-tabs--scoped {!IF( $CurrentPage.parameters.selectedTab == 'tab1', 'slds-active', '' )}" id="tab2" role="presentation">
  8. <a href="javascript:void(0)" onclick="setSelectedTab( 'tab1' )" role="tab" aria-selected="{!$CurrentPage.parameters.selectedTab == 'tab2'}" class="slds-tab--scoped__link">Tab 2</a>
  9. </li>
  10.  
  11. ...
  12.  
  13. String selectedTab { get; set; }
  14.  
  15. public PageReference changeTab(){
  16.  
  17. ... do your DML work here ...
  18.  
  19. PageReference pg = Page.CurrentPage;
  20.  
  21. pg.getParameters().put( "selectedTab", selectedTab );
  22.  
  23. pg.setRedirect( true );
  24.  
  25. return pg;
  26. }
  27.  
  28. <script>
  29. var j$ = jQuery.noConflict();
  30.  
  31. // get the tab value from the URL
  32. var urlParameter = function getURLParam( param ){
  33. var pageUrl = decodeURIComponent( window.location.search.substring( 1 )),
  34. urlVars = pageUrl.split( "&" ),
  35. parmName;
  36.  
  37. for( var i = 0; i < urlVars.length; i++ ){
  38.  
  39. parmName = urlVars[ i ].split( '=' );
  40.  
  41. if( parmName[ 0 ] === param ){
  42. return ( parmName[ 1 ] === undefined ? "tab1" : parmName[ 1 ] ); // default return first tab - otherwise selected tab
  43. }
  44. }
  45.  
  46. };
  47.  
  48. j#( window ).on( "load", function(){
  49. getSelectedTab();
  50. }
  51.  
  52. // get the selected tab and set the others unselected
  53. function getSelectedTab(){
  54. var tab = urlParameter( "selectedTab" );
  55.  
  56. j$( "#" + tab ).attr( "aria-selected", true );
  57.  
  58. j$( "[ class^='slds-tab' ]" ).each( function( index ){
  59. if( j$( this ).id !== tab ){
  60. j$( this ).attr( "aria-selected", false );
  61. }
  62. });
  63. }
  64.  
  65.  
  66. </script>
Add Comment
Please, Sign In to add comment