UNPKG

2.25 kBJavaScriptView Raw
1/* ========================================================
2 * bootstrap-tabs.js v1.4.0
3 * http://twitter.github.com/bootstrap/javascript.html#tabs
4 * ========================================================
5 * Copyright 2011 Twitter, Inc.
6 *
7 * Licensed under the Apache License, Version 2.0 (the "License");
8 * you may not use this file except in compliance with the License.
9 * You may obtain a copy of the License at
10 *
11 * http://www.apache.org/licenses/LICENSE-2.0
12 *
13 * Unless required by applicable law or agreed to in writing, software
14 * distributed under the License is distributed on an "AS IS" BASIS,
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 * See the License for the specific language governing permissions and
17 * limitations under the License.
18 * ======================================================== */
19
20
21!function( $ ){
22
23 "use strict"
24
25 function activate ( element, container ) {
26 container
27 .find('> .active')
28 .removeClass('active')
29 .find('> .dropdown-menu > .active')
30 .removeClass('active')
31
32 element.addClass('active')
33
34 if ( element.parent('.dropdown-menu') ) {
35 element.closest('li.dropdown').addClass('active')
36 }
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
45
46 if ( /^#\w+/.test(href) ) {
47 e.preventDefault()
48
49 if ( $this.parent('li').hasClass('active') ) {
50 return
51 }
52
53 previous = $ul.find('.active a').last()[0]
54 $href = $(href)
55
56 activate($this.parent('li'), $ul)
57 activate($href, $href.parent())
58
59 $this.trigger({
60 type: 'change'
61 , relatedTarget: previous
62 })
63 }
64 }
65
66
67 /* TABS/PILLS PLUGIN DEFINITION
68 * ============================ */
69
70 $.fn.tabs = $.fn.pills = function ( selector ) {
71 return this.each(function () {
72 $(this).delegate(selector || '.tabs li > a, .pills > li > a', 'click', tab)
73 })
74 }
75
76 $(document).ready(function () {
77 $('body').tabs('ul[data-tabs] li > a, ul[data-pills] > li > a')
78 })
79
80}( window.jQuery || window.ender );