bootstrap-tabs.js 1.86 KB
Newer Older
Jacob Thornton's avatar
Jacob Thornton committed
1
/* ========================================================
2
 * bootstrap-tabs.js v1.3.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

  function activate ( element, container ) {
24
    container.find('> .active').removeClass('active')
25
    element.addClass('active')
Jacob Thornton's avatar
tabssss  
Jacob Thornton committed
26
27
28
  }

  function tab( e ) {
29
    var $this = $(this)
30
      , $ul = $this.closest('ul')
31
      , href = $this.attr('href')
32
      , previous
Jacob Thornton's avatar
tabssss  
Jacob Thornton committed
33

Jacob Thornton's avatar
Jacob Thornton committed
34
    if (/^#\w+/.test(href)) {
35
      e.preventDefault()
Jacob Thornton's avatar
tabssss  
Jacob Thornton committed
36

37
      if ($this.parent('li').hasClass('active')) {
Jacob Thornton's avatar
tabssss  
Jacob Thornton committed
38
39
40
        return
      }

41
      previous = $ul.find('.active a')[0]
Jacob Thornton's avatar
Jacob Thornton committed
42
      $href = $(href)
43
44

      activate($this.parent('li'), $ul)
Jacob Thornton's avatar
Jacob Thornton committed
45
      activate($href, $href.parent())
46
47
48
49
50

      $this.trigger({
        type: 'change'
      , relatedTarget: previous
      })
51
    }
Jacob Thornton's avatar
tabssss  
Jacob Thornton committed
52
53
54
  }


55
56
 /* TABS/PILLS PLUGIN DEFINITION
  * ============================ */
Jacob Thornton's avatar
tabssss  
Jacob Thornton committed
57

58
  $.fn.tabs = $.fn.pills = function ( selector ) {
Jacob Thornton's avatar
tabssss  
Jacob Thornton committed
59
    return this.each(function () {
60
      $(this).delegate(selector || '.tabs li > a, .pills > li > a', 'click', tab)
Jacob Thornton's avatar
tabssss  
Jacob Thornton committed
61
62
63
    })
  }

64
  $(document).ready(function () {
65
66
67
    $('body').tabs('ul[data-tabs] li > a, ul[data-pills] > li > a')
  })

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