Bones/javascripts/tabs.js
Guillermo Rauch 110765dbc1 Misc refactoring.
- Switched to `hashchange` listening instead of delegation
  We still check that the given hash exists as a `href` within a valid
  Skeleton tabs markup, but you can now send links around that focus
  on tabs.

  As an example, if I tweet out mypage.com/#activetab, it will check that
  `#activetab` is a valid href in an anchor within an `<ul class="tabs">`
  element, and if so, make that tab active.

- In addition, you can have multiple anchors in the page that
  trigger tabs by simply setting the appropriate `href`.

- Leverage `closest` and `find` instead of `parent`, `siblings` and
  `children` (code simplification).
2012-03-01 19:38:50 -03:00

29 lines
673 B
JavaScript

/**
* Skeleton V1.1
* Copyright 2011, Dave Gamache
* www.getskeleton.com
* Free to use under the MIT license.
* http://www.opensource.org/licenses/mit-license.php
* 8/17/2011
*/
jQuery(function ($) {
// hash change handler
function hashchange () {
var hash = window.location.hash
, el = $('ul.tabs [href*="' + hash + '"]')
if (el.length) {
$(el).closest('.tabs').find('.active').removeClass('active');
$(el).addClass('active');
$(hash).show().addClass('active').siblings().hide().removeClass('active');
}
}
// listen on event and fire right away
$(window).on('hashchange.skeleton', hashchange);
hashchange();
});