1
0
mirror of https://github.com/twbs/bootstrap.git synced 2025-08-27 15:19:52 +02:00

add dropdown tab selection support

This commit is contained in:
Jacob Thornton
2011-10-04 22:11:44 -07:00
parent 100954eeda
commit a2c263493a
2 changed files with 27 additions and 5 deletions

19
js/bootstrap-tabs.js vendored
View File

@@ -21,24 +21,33 @@
!function( $ ){
function activate ( element, container ) {
container.find('> .active').removeClass('active')
container
.find('> .active')
.removeClass('active')
.find('> .dropdown-menu > .active')
.removeClass('active')
element.addClass('active')
if ( element.parent('.dropdown-menu') ) {
element.closest('li.dropdown').addClass('active')
}
}
function tab( e ) {
var $this = $(this)
, $ul = $this.closest('ul')
, $ul = $this.closest('ul:not(.dropdown-menu)')
, href = $this.attr('href')
, previous
if (/^#\w+/.test(href)) {
if ( /^#\w+/.test(href) ) {
e.preventDefault()
if ($this.parent('li').hasClass('active')) {
if ( $this.parent('li').hasClass('active') ) {
return
}
previous = $ul.find('.active a')[0]
previous = $ul.find('.active a').last()[0]
$href = $(href)
activate($this.parent('li'), $ul)