1 /* ========================================================
2 * bootstrap-tab.js v2.0.0
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 * ======================================================== */
25 /* TAB CLASS DEFINITION
26 * ==================== */
28 var Tab = function ( element ) {
29 this.element = $(element)
37 var $this = this.element
38 , $ul = $this.closest('ul:not(.dropdown-menu)')
39 , selector = $this.attr('data-target')
44 selector = $this.attr('href')
45 selector = selector && selector.replace(/.*(?=#[^\s]*$)/, '') //strip for ie7
48 if ( $this.parent('li').hasClass('active') ) return
50 previous = $ul.find('.active a').last()[0]
54 , relatedTarget: previous
59 this.activate($this.parent('li'), $ul)
60 this.activate($target, $target.parent(), function () {
63 , relatedTarget: previous
68 , activate: function ( element, container, callback) {
69 var $active = container.find('> .active')
70 , transition = callback
71 && $.support.transition
72 && $active.hasClass('fade')
76 .removeClass('active')
77 .find('> .dropdown-menu > .active')
78 .removeClass('active')
80 element.addClass('active')
83 element[0].offsetWidth // reflow for transition
84 element.addClass('in')
86 element.removeClass('fade')
89 if ( element.parent('.dropdown-menu') ) {
90 element.closest('li.dropdown').addClass('active')
93 callback && callback()
97 $active.one($.support.transition.end, next) :
100 $active.removeClass('in')
105 /* TAB PLUGIN DEFINITION
106 * ===================== */
108 $.fn.tab = function ( option ) {
109 return this.each(function () {
111 , data = $this.data('tab')
112 if (!data) $this.data('tab', (data = new Tab(this)))
113 if (typeof option == 'string') data[option]()
117 $.fn.tab.Constructor = Tab
124 $('body').on('click.tab.data-api', '[data-toggle="tab"], [data-toggle="pill"]', function (e) {