1
0
mirror of https://github.com/twbs/bootstrap.git synced 2025-02-24 21:40:17 +00:00
bootstrap/docs/assets/js/bootstrap-tabs.js

38 lines
804 B
JavaScript
Raw Normal View History

2011-09-08 19:13:08 -07:00
(function( $ ){
function activate ( element, container ) {
container.find('.active').removeClass('active')
element.addClass('active')
2011-09-08 19:13:08 -07:00
}
function tab( e ) {
var $this = $(this)
, href = $this.attr('href')
, $ul = $(e.liveFired)
, $controlled
2011-09-08 19:13:08 -07:00
if (/^#/.test(href)) {
e.preventDefault()
2011-09-08 19:13:08 -07:00
if ($this.hasClass('active')) {
return
}
$controlled = $('#' + $ul.attr('aria-controls'))
activate($this.parent('li'), $ul)
activate($(href, $controlled), $controlled)
}
2011-09-08 19:13:08 -07:00
}
/* TABS/PILLS PLUGIN DEFINITION
* ============================ */
2011-09-08 19:13:08 -07:00
$.fn.tabs = $.fn.pills = function () {
2011-09-08 19:13:08 -07:00
return this.each(function () {
$(this).delegate('.tabs > li > a, .pills > li > a', 'click', tab)
2011-09-08 19:13:08 -07:00
})
}
})( jQuery || ender )