Tip: Click lines to highlight, hold ctrl/cmd to multi-select

http://codedumper.com/otese (16-Jun @ 12:29)

remy

Syntax Highlighted Code

  1. $(function () {
  2.     var tabs = [];
  3.     var tabContainers = [];
  4.     $('ul.tabs a').each(function () {
  5.       // note that this only compares the pathname, not the entire url
  6.       // which actually may be required for a more terse solution.
  7.         if (this.pathname == window.location.pathname) {
  8.             tabs.push(this);
  9.             tabContainers.push($(this.hash).get(0));
  10.         }
  11.     });
  12.  
  13.     // sniff for hash in url, and create filter search
  14.     var selected = window.location.hash ? '[hash=' + window.location.hash + ']' : ':first';
  15.    
  16.     $(tabs).click(function () {
  17.         // hide all tabs
  18.         $(tabContainers).hide().filter(this.hash).show();
  19.        
  20.         // set up the selected class
  21.         $(tabs).removeClass('selected');
  22.         $(this).addClass('selected');
  23.        
  24.         return false;
  25.     }).filter(selected).click();
  26. });

Plain Code

$(function () {
    var tabs = [];
    var tabContainers = [];
    $('ul.tabs a').each(function () {
      // note that this only compares the pathname, not the entire url
      // which actually may be required for a more terse solution.
        if (this.pathname == window.location.pathname) {
            tabs.push(this);
            tabContainers.push($(this.hash).get(0));
        }
    });

    // sniff for hash in url, and create filter search 
    var selected = window.location.hash ? '[hash=' + window.location.hash + ']' : ':first'; 
    
    $(tabs).click(function () {
        // hide all tabs
        $(tabContainers).hide().filter(this.hash).show();
        
        // set up the selected class
        $(tabs).removeClass('selected');
        $(this).addClass('selected');
        
        return false;
    }).filter(selected).click();
});

Permalink: http://codedumper.com/otese