bootstrap-tabs.js 2.11 KB
Newer Older
Jacob Thornton's avatar
Jacob Thornton committed
1
/* ========================================================
2
 * bootstrap-tabs.js v2.0.0
Jacob Thornton's avatar
Jacob Thornton committed
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
 * http://twitter.github.com/bootstrap/javascript.html#tabs
 * ========================================================
 * Copyright 2011 Twitter, Inc.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * ======================================================== */


21
!function( $ ){
Jacob Thornton's avatar
tabssss  
Jacob Thornton committed
22

23
24
  "use strict"

Jacob Thornton's avatar
tabssss  
Jacob Thornton committed
25
  function activate ( element, container ) {
26
27
28
29
30
31
    container
      .find('> .active')
      .removeClass('active')
      .find('> .dropdown-menu > .active')
      .removeClass('active')

32
    element.addClass('active')
33
34
35
36

    if ( element.parent('.dropdown-menu') ) {
      element.closest('li.dropdown').addClass('active')
    }
Jacob Thornton's avatar
tabssss  
Jacob Thornton committed
37
38
39
  }

  function tab( e ) {
40
    var $this = $(this)
41
      , $ul = $this.closest('ul:not(.dropdown-menu)')
42
      , href = $this.attr('href')
43
      , previous
44
      , $href
Jacob Thornton's avatar
tabssss  
Jacob Thornton committed
45

46
    if ( /^#\w+/.test(href) ) {
47
      e.preventDefault()
Jacob Thornton's avatar
tabssss  
Jacob Thornton committed
48

49
      if ( $this.parent('li').hasClass('active') ) {
Jacob Thornton's avatar
tabssss  
Jacob Thornton committed
50
51
52
        return
      }

53
      previous = $ul.find('.active a').last()[0]
Jacob Thornton's avatar
Jacob Thornton committed
54
      $href = $(href)
55
56

      activate($this.parent('li'), $ul)
Jacob Thornton's avatar
Jacob Thornton committed
57
      activate($href, $href.parent())
58
59
60
61
62

      $this.trigger({
        type: 'change'
      , relatedTarget: previous
      })
63
    }
Jacob Thornton's avatar
tabssss  
Jacob Thornton committed
64
65
66
  }


67
68
 /* TABS/PILLS PLUGIN DEFINITION
  * ============================ */
Jacob Thornton's avatar
tabssss  
Jacob Thornton committed
69

70
71
72
73
74
75
76
77
  $.fn.tabs = $.fn.pills = function ( selector ) {
    return this.each(function () {
      $(this).delegate(selector || '.tabs li > a, .pills > li > a', 'click', tab)
    })
  }

  $(document).ready(function () {
    $('body').tabs('ul[data-tabs] li > a, ul[data-pills] > li > a')
78
79
  })

80
}( window.jQuery || window.ender );