1 /* ========================================================================
2 * Bootstrap: tab.js v3.3.2
3 * http://getbootstrap.com/javascript/#tabs
4 * ========================================================================
5 * Copyright 2011-2015 Twitter, Inc.
6 * Licensed under MIT (https://github.com/twbs/bootstrap/blob/master/LICENSE)
7 * ======================================================================== */
13 // TAB CLASS DEFINITION
14 // ====================
16 var Tab = function (element) {
17 this.element = $(element)
22 Tab.TRANSITION_DURATION = 150
24 Tab.prototype.show = function () {
25 var $this = this.element
26 var $ul = $this.closest('ul:not(.dropdown-menu)')
27 var selector = $this.data('target')
30 selector = $this.attr('href')
31 selector = selector && selector.replace(/.*(?=#[^\s]*$)/, '') // strip for ie7
34 if ($this.parent('li').hasClass('active')) return
36 var $previous = $ul.find('.active:last a')
37 var hideEvent = $.Event('hide.bs.tab', {
38 relatedTarget: $this[0]
40 var showEvent = $.Event('show.bs.tab', {
41 relatedTarget: $previous[0]
44 $previous.trigger(hideEvent)
45 $this.trigger(showEvent)
47 if (showEvent.isDefaultPrevented() || hideEvent.isDefaultPrevented()) return
49 var $target = $(selector)
51 this.activate($this.closest('li'), $ul)
52 this.activate($target, $target.parent(), function () {
54 type: 'hidden.bs.tab',
55 relatedTarget: $this[0]
59 relatedTarget: $previous[0]
64 Tab.prototype.activate = function (element, container, callback) {
65 var $active = container.find('> .active')
66 var transition = callback
67 && $.support.transition
68 && (($active.length && $active.hasClass('fade')) || !!container.find('> .fade').length)
72 .removeClass('active')
73 .find('> .dropdown-menu > .active')
74 .removeClass('active')
76 .find('[data-toggle="tab"]')
77 .attr('aria-expanded', false)
81 .find('[data-toggle="tab"]')
82 .attr('aria-expanded', true)
85 element[0].offsetWidth // reflow for transition
86 element.addClass('in')
88 element.removeClass('fade')
91 if (element.parent('.dropdown-menu')) {
93 .closest('li.dropdown')
96 .find('[data-toggle="tab"]')
97 .attr('aria-expanded', true)
100 callback && callback()
103 $active.length && transition ?
105 .one('bsTransitionEnd', next)
106 .emulateTransitionEnd(Tab.TRANSITION_DURATION) :
109 $active.removeClass('in')
113 // TAB PLUGIN DEFINITION
114 // =====================
116 function Plugin(option) {
117 return this.each(function () {
119 var data = $this.data('bs.tab')
121 if (!data) $this.data('bs.tab', (data = new Tab(this)))
122 if (typeof option == 'string') data[option]()
129 $.fn.tab.Constructor = Tab
135 $.fn.tab.noConflict = function () {
144 var clickHandler = function (e) {
146 Plugin.call($(this), 'show')
150 .on('click.bs.tab.data-api', '[data-toggle="tab"]', clickHandler)
151 .on('click.bs.tab.data-api', '[data-toggle="pill"]', clickHandler)