1 /* ========================================================
2 * bootstrap-tab.js v2.0.4
3 * http://twitter.github.com/bootstrap/javascript.html#tabs
4 * ========================================================
5 * Copyright 2012 Twitter, Inc.
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
11 * http://www.apache.org/licenses/LICENSE-2.0
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 * ======================================================== */
23 "use strict"; // jshint ;_;
26 /* TAB CLASS DEFINITION
27 * ==================== */
29 var Tab = function ( element ) {
30 this.element = $(element)
38 var $this = this.element
39 , $ul = $this.closest('ul:not(.dropdown-menu)')
40 , selector = $this.attr('data-target')
46 selector = $this.attr('href')
47 selector = selector && selector.replace(/.*(?=#[^\s]*$)/, '') //strip for ie7
50 if ( $this.parent('li').hasClass('active') ) return
52 previous = $ul.find('.active a').last()[0]
55 relatedTarget: previous
60 if (e.isDefaultPrevented()) return
64 this.activate($this.parent('li'), $ul)
65 this.activate($target, $target.parent(), function () {
68 , relatedTarget: previous
73 , activate: function ( element, container, callback) {
74 var $active = container.find('> .active')
75 , transition = callback
76 && $.support.transition
77 && $active.hasClass('fade')
81 .removeClass('active')
82 .find('> .dropdown-menu > .active')
83 .removeClass('active')
85 element.addClass('active')
88 element[0].offsetWidth // reflow for transition
89 element.addClass('in')
91 element.removeClass('fade')
94 if ( element.parent('.dropdown-menu') ) {
95 element.closest('li.dropdown').addClass('active')
98 callback && callback()
102 $active.one($.support.transition.end, next) :
105 $active.removeClass('in')
110 /* TAB PLUGIN DEFINITION
111 * ===================== */
113 $.fn.tab = function ( option ) {
114 return this.each(function () {
116 , data = $this.data('tab')
117 if (!data) $this.data('tab', (data = new Tab(this)))
118 if (typeof option == 'string') data[option]()
122 $.fn.tab.Constructor = Tab
129 $('body').on('click.tab.data-api', '[data-toggle="tab"], [data-toggle="pill"]', function (e) {