Template:Team:Valencia Biocampus/Templates/Header

From 2014.igem.org

(Difference between revisions)
Line 12: Line 12:
</script>
</script>
 +
<script type="text/javascript">
 +
$(document).ready(function() {
 +
  // cache the id
 +
  var navbox = $('#myTab');
 +
  // activate tab on click
 +
  navbox.on('click', 'a', function (e) {
 +
      // add a hash to the URL when the user clicks on a tab
 +
      history.pushState(null, null, $(this).attr('href'));
 +
      var $this = $(this);
 +
      // prevent the Default behavior
 +
      e.preventDefault();
 +
      // set the hash to the address bar
 +
      window.location.hash = $this.attr('href');
 +
      // activate the clicked tab
 +
      $this.tab('show');
 +
      //return false;
 +
  })
 +
  // if we have a hash in the address bar
 +
  if(window.location.hash){
 +
    // show right tab on load (read hash from address bar)
 +
    $('a[href="'+window.location.hash+'"]').tab('show');
 +
  }
 +
 +
  // navigate to a tab when the history changes
 +
  window.addEventListener("popstate", function(e) {
 +
    var activeTab = $('[href=' + location.hash + ']');
 +
    if (activeTab.length) {
 +
        activeTab.tab('show');
 +
    } else {
 +
        $('.nav-tabs a:first').tab('show');
 +
    }
 +
  });
 +
});
 +
</script>
<link rel="stylesheet" type="text/css" href="https://2014.igem.org/wiki/index.php?title=Template:Team:Valencia_Biocampus/Templates/css/bootstrap&amp;action=raw&amp;ctype=text/css" />
<link rel="stylesheet" type="text/css" href="https://2014.igem.org/wiki/index.php?title=Template:Team:Valencia_Biocampus/Templates/css/bootstrap&amp;action=raw&amp;ctype=text/css" />

Revision as of 16:35, 29 September 2014