JQuery UI Tab History Sub Tab

I am using jQuery Address plug-in to make tabs in jQuery user interface tabs and compatible with last button. It works great.

However, I was wondering if it is possible to provide the same β€œdeep link” for sub tabs? For example, I have the following:

<div id="tabs">
 <ul class="links">
  <li><a href="#one">main tab one</a></li>     
  <li><a href="#two">main tab two</a></li>
  <li><a href="#three">main tab three</a></li>
  <li><a href="#four">main tab four</a></li>
 </ul>
 <div id="one">  Main tab one content </div> 
 <div id="two">
  Main tab two content 
  <div id="nested">
   <ul>
    <li><a href="#nestedone">nested tab one</a></li>
    <li><a href="#nestedtwo">nested tab two</a></li>
    <li><a href="#nestedthree">nested tab three</a></li>
   </ul>
   <div id="nestedone"> nested tab one </div>
   <div id="nestedtwo"> nested tab two </div>
   <div id="nestedthree"> nested tab three </div>
  </div> <!-- end nested -->
 </div> 
 <div id="three">  Main tab three content </div> 
 <div id="fout">  Main tab four content </div> 
</div> <!-- end tabs -->


<script>
$(document).ready(function(){
   /* main tabs stuff */
   var $tabs = $("#tabs").tabs().addClass('ui-tabs-vertical ui-helper-clearfix');
   $("#tabs li").removeClass('ui-corner-top').addClass('ui-corner-left');

   /* nested tabs */
   var $nested = $("#nested").tabs().addClass('ui-tabs-hz');
   $("#nested ul").removeClass('ui-tabs-nav');

   /* show the hash tab whenever the address is changed */
   $.address.change(function(event){               
      $("#tabs").tabs( "select" , window.location.hash ) ;  
   })

   /* when the tab is selected update the url with the hash */
   $("#tabs").bind("tabsselect", function(event, ui) {          
      window.location.hash = ui.tab.hash;                           
   })
});
</script>

Everything works fine for the main (external tabs):

  • The href link in the tab is placed in the url as it is correct.
  • external tabs obey browser buttons back and forth
  • external tabs are available for bookmarks

However, I can't seem to have the same type of functionality for inner tabs.

, "" , , $(this) ( ). JavaScript , , () .

, JavaScript , , , () . , , , .

   $("#tabs").bind("tabsselect", function(event, ui) {          
      if ($(ui.tab).closest('div').attr('id') !== "nested") {
         window.location.hash = ui.tab.hash; 
      }                     
   })

, - . ?

!

+3
1

, , - , . .address, - :

<div id="tabs">
 <ul class="links">
  <li><a href="#one">main tab one</a></li>     
  <li><a href="#two">main tab two</a></li>
  <li><a href="#three">main tab three</a></li>
  <li><a href="#four">main tab four</a></li>
 </ul>
 <div id="one">  Main tab one content </div> 
 <div id="two">
  Main tab two content 
  <div id="nested">
   <ul>
    <li><a href="#two-nestedone">nested tab one</a></li>
    <li><a href="#two-nestedtwo">nested tab two</a></li>
    <li><a href="#two-nestedtwo">nested tab three</a></li>
   </ul>
   <div id="two-nestedone"> nested tab one </div>
   <div id="two-nestedtwo"> nested tab two </div>
   <div id="two-nestedthree"> nested tab three </div>
  </div> <!-- end nested -->
 </div> 
 <div id="three">  Main tab three content </div> 
 <div id="four">  Main tab four content </div> 
</div> <!-- end tabs -->

javascript:

$(document).ready(function(){
   /* main tabs stuff */
   var $tabs = $("#tabs").tabs().addClass('ui-tabs-vertical ui-helper-clearfix');
   $("#tabs li").removeClass('ui-corner-top').addClass('ui-corner-left');

   /* nested tabs */
   var $nested = $("#nested").tabs().addClass('ui-tabs-hz');
   $("#nested ul").removeClass('ui-tabs-nav');

   /* show the hash tab whenever the address is changed */
   $.address.change(function(event){               
      var arrParts = window.location.hash.substring(1).split("-");      
      $("#tabs").tabs( "select" , '#' + arrParts[0] ) ;
      if (arrParts.length > 1) {  
        $("#nested").tabs( "select" , '#' + arrParts[1] ) ;  
      }
   })

   /* when the tab is selected update the url with the hash */
   $("#tabs, #nested").bind("tabsselect", function(event, ui) {          
      window.location.hash = ui.tab.hash;                           
      event.stopPropagation();
   })
});
0

Source: https://habr.com/ru/post/1761815/


All Articles