bootstrap-tabs.js 787 Bytes
Newer Older
Jacob Thornton's avatar
tabssss  
Jacob Thornton committed
1
2
3
4
(function( $ ){

  function activate ( element, container ) {
    container.find('.active').removeClass('active')
5
    element.addClass('active')
Jacob Thornton's avatar
tabssss  
Jacob Thornton committed
6
7
8
  }

  function tab( e ) {
9
10
11
12
    var $this = $(this)
      , href = $this.attr('href')
      , $ul = $(e.liveFired)
      , $controlled
Jacob Thornton's avatar
tabssss  
Jacob Thornton committed
13

Jacob Thornton's avatar
Jacob Thornton committed
14
    if (/^#\w+/.test(href)) {
15
      e.preventDefault()
Jacob Thornton's avatar
tabssss  
Jacob Thornton committed
16
17
18
19
20

      if ($this.hasClass('active')) {
        return
      }

Jacob Thornton's avatar
Jacob Thornton committed
21
      $href = $(href)
22
23

      activate($this.parent('li'), $ul)
Jacob Thornton's avatar
Jacob Thornton committed
24
      activate($href, $href.parent())
25
    }
Jacob Thornton's avatar
tabssss  
Jacob Thornton committed
26
27
28
  }


29
30
 /* TABS/PILLS PLUGIN DEFINITION
  * ============================ */
Jacob Thornton's avatar
tabssss  
Jacob Thornton committed
31

32
  $.fn.tabs = $.fn.pills = function () {
Jacob Thornton's avatar
tabssss  
Jacob Thornton committed
33
    return this.each(function () {
Jacob Thornton's avatar
Jacob Thornton committed
34
      $(this).delegate('.tabs > li > a, .pills > li > a, .dropdown-menu > li > a', 'click', tab)
Jacob Thornton's avatar
tabssss  
Jacob Thornton committed
35
36
37
38
    })
  }

})( jQuery || ender )