2015-01-03 21:58:44 +00:00
|
|
|
/** =======================================================================
|
|
|
|
* Bootstrap: tab.js v4.0.0
|
2013-10-29 17:10:47 +00:00
|
|
|
* http://getbootstrap.com/javascript/#tabs
|
2013-05-22 02:30:33 +00:00
|
|
|
* ========================================================================
|
2015-01-01 00:23:48 +00:00
|
|
|
* Copyright 2011-2015 Twitter, Inc.
|
2013-12-18 23:28:08 +00:00
|
|
|
* Licensed under MIT (https://github.com/twbs/bootstrap/blob/master/LICENSE)
|
2015-01-03 21:58:44 +00:00
|
|
|
* ========================================================================
|
|
|
|
* @fileoverview - Bootstrap's tab plugin. Tab O_O
|
|
|
|
*
|
|
|
|
* Public Methods & Properties:
|
|
|
|
*
|
|
|
|
* + $.tab
|
|
|
|
* + $.tab.noConflict
|
|
|
|
* + $.tab.Constructor
|
|
|
|
* + $.tab.Constructor.VERSION
|
|
|
|
* + $.tab.Constructor.prototype.show
|
|
|
|
*
|
|
|
|
* ========================================================================
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
|
|
'use strict';
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Our Tab class.
|
|
|
|
* @param {Element!} element
|
|
|
|
* @constructor
|
|
|
|
*/
|
|
|
|
var Tab = function (element) {
|
|
|
|
|
|
|
|
/** @type {Element} */
|
|
|
|
this._element = element
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @const
|
|
|
|
* @type {string}
|
|
|
|
*/
|
|
|
|
Tab['VERSION'] = '4.0.0'
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @const
|
|
|
|
* @type {string}
|
|
|
|
* @private
|
|
|
|
*/
|
|
|
|
Tab._NAME = 'tab'
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @const
|
|
|
|
* @type {string}
|
|
|
|
* @private
|
|
|
|
*/
|
|
|
|
Tab._DATA_KEY = 'bs.tab'
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @const
|
|
|
|
* @type {number}
|
|
|
|
* @private
|
|
|
|
*/
|
|
|
|
Tab._TRANSITION_DURATION = 150
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @const
|
|
|
|
* @enum {string}
|
|
|
|
* @private
|
|
|
|
*/
|
|
|
|
Tab._Event = {
|
|
|
|
HIDE : 'hide.bs.tab',
|
|
|
|
HIDDEN : 'hidden.bs.tab',
|
|
|
|
SHOW : 'show.bs.tab',
|
|
|
|
SHOWN : 'shown.bs.tab'
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @const
|
|
|
|
* @enum {string}
|
|
|
|
* @private
|
|
|
|
*/
|
|
|
|
Tab._ClassName = {
|
|
|
|
DROPDOWN_MENU : 'dropdown-menu',
|
|
|
|
ACTIVE : 'active',
|
|
|
|
FADE : 'fade',
|
|
|
|
IN : 'in'
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @const
|
|
|
|
* @enum {string}
|
|
|
|
* @private
|
|
|
|
*/
|
|
|
|
Tab._Selector = {
|
|
|
|
A : 'a',
|
|
|
|
LI : 'li',
|
|
|
|
LI_DROPDOWN : 'li.dropdown',
|
|
|
|
UL : 'ul:not(.dropdown-menu)',
|
|
|
|
FADE_CHILD : ':scope > .fade',
|
|
|
|
ACTIVE : '.active',
|
|
|
|
ACTIVE_CHILD : ':scope > .active',
|
|
|
|
DATA_TOGGLE : '[data-toggle="tab"], [data-toggle="pill"]',
|
|
|
|
DROPDOWN_ACTIVE_CHILD : ':scope > .dropdown-menu > .active'
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @param {Object|string=} opt_config
|
|
|
|
* @this {jQuery}
|
|
|
|
* @return {jQuery}
|
|
|
|
* @private
|
|
|
|
*/
|
|
|
|
Tab._jQueryInterface = function (opt_config) {
|
|
|
|
return this.each(function () {
|
|
|
|
var $this = $(this)
|
|
|
|
var data = $this.data(Tab._DATA_KEY)
|
|
|
|
|
|
|
|
if (!data) {
|
|
|
|
data = data = new Tab(this)
|
|
|
|
$this.data(Tab._DATA_KEY, data)
|
|
|
|
}
|
2011-11-28 01:04:55 +00:00
|
|
|
|
2015-01-03 21:58:44 +00:00
|
|
|
if (typeof opt_config === 'string') {
|
|
|
|
data[opt_config]()
|
|
|
|
}
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Show the tab
|
|
|
|
*/
|
|
|
|
Tab.prototype['show'] = function () {
|
|
|
|
if ( this._element.parentNode
|
|
|
|
&& this._element.parentNode.nodeType == Node.ELEMENT_NODE
|
|
|
|
&& $(this._element).parent().hasClass(Tab._ClassName.ACTIVE)) {
|
|
|
|
return
|
|
|
|
}
|
2011-11-28 01:04:55 +00:00
|
|
|
|
2015-01-03 21:58:44 +00:00
|
|
|
var ulElement = $(this._element).closest(Tab._Selector.UL)[0]
|
|
|
|
var selector = Bootstrap.getSelectorFromElement(this._element)
|
2014-06-10 05:18:05 +00:00
|
|
|
|
2015-01-03 21:58:44 +00:00
|
|
|
if (ulElement) {
|
|
|
|
var previous = /** @type {Array.<Element>} */ ($.makeArray($(ulElement).find(Tab._Selector.ACTIVE)))
|
|
|
|
previous = previous[previous.length - 1]
|
2012-04-14 23:29:53 +00:00
|
|
|
|
2015-01-03 21:58:44 +00:00
|
|
|
if (previous) {
|
|
|
|
previous = $(previous).find('a')[0]
|
|
|
|
}
|
2014-06-23 18:07:18 +00:00
|
|
|
}
|
2011-11-28 01:04:55 +00:00
|
|
|
|
2015-01-03 21:58:44 +00:00
|
|
|
var hideEvent = $.Event(Tab._Event.HIDE, {
|
|
|
|
relatedTarget: this._element
|
|
|
|
})
|
|
|
|
|
|
|
|
var showEvent = $.Event(Tab._Event.SHOW, {
|
|
|
|
relatedTarget: previous
|
|
|
|
})
|
2011-11-28 01:04:55 +00:00
|
|
|
|
2015-01-03 21:58:44 +00:00
|
|
|
if (previous) {
|
|
|
|
$(previous).trigger(hideEvent)
|
|
|
|
}
|
2014-07-07 11:03:56 +00:00
|
|
|
|
2015-01-03 21:58:44 +00:00
|
|
|
$(this._element).trigger(showEvent)
|
2012-03-25 01:20:09 +00:00
|
|
|
|
2015-01-03 21:58:44 +00:00
|
|
|
if (showEvent.isDefaultPrevented() || hideEvent.isDefaultPrevented()) return
|
2014-06-12 18:11:04 +00:00
|
|
|
|
2015-01-03 21:58:44 +00:00
|
|
|
if (selector) {
|
|
|
|
var target = $(selector)[0]
|
|
|
|
}
|
2011-12-21 03:37:41 +00:00
|
|
|
|
2015-01-03 21:58:44 +00:00
|
|
|
this._activate($(this._element).closest(Tab._Selector.LI)[0], ulElement)
|
|
|
|
|
|
|
|
var complete = function () {
|
|
|
|
var hiddenEvent = $.Event(Tab._Event.HIDDEN, {
|
|
|
|
relatedTarget: this._element
|
2014-06-23 18:07:18 +00:00
|
|
|
})
|
2014-06-12 18:11:04 +00:00
|
|
|
|
2015-01-03 21:58:44 +00:00
|
|
|
var shownEvent = $.Event(Tab._Event.SHOWN, {
|
|
|
|
relatedTarget: previous
|
|
|
|
})
|
2014-06-12 18:11:04 +00:00
|
|
|
|
2015-01-03 21:58:44 +00:00
|
|
|
$(previous).trigger(hiddenEvent)
|
|
|
|
$(this._element).trigger(shownEvent)
|
|
|
|
}.bind(this)
|
2014-06-12 18:11:04 +00:00
|
|
|
|
2015-01-03 21:58:44 +00:00
|
|
|
if (target) {
|
|
|
|
this._activate(target, /** @type {Element} */ (target.parentNode), complete)
|
|
|
|
} else {
|
|
|
|
complete()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @param {Element} element
|
|
|
|
* @param {Element} container
|
|
|
|
* @param {Function=} opt_callback
|
|
|
|
* @private
|
|
|
|
*/
|
|
|
|
Tab.prototype._activate = function (element, container, opt_callback) {
|
|
|
|
var active = $(container).find(Tab._Selector.ACTIVE_CHILD)[0]
|
|
|
|
var isTransitioning = opt_callback
|
|
|
|
&& Bootstrap.transition
|
|
|
|
&& ((active && $(active).hasClass(Tab._ClassName.FADE))
|
|
|
|
|| !!$(container).find(Tab._Selector.FADE_CHILD)[0])
|
|
|
|
|
|
|
|
var complete = this._transitionComplete.bind(this, element, active, isTransitioning, opt_callback)
|
|
|
|
|
|
|
|
if (active && isTransitioning) {
|
|
|
|
$(active)
|
|
|
|
.one(Bootstrap.TRANSITION_END, complete)
|
|
|
|
.emulateTransitionEnd(Tab._TRANSITION_DURATION)
|
|
|
|
|
|
|
|
} else {
|
|
|
|
complete()
|
|
|
|
}
|
2014-06-12 18:11:04 +00:00
|
|
|
|
2015-01-03 21:58:44 +00:00
|
|
|
if (active) {
|
|
|
|
$(active).removeClass(Tab._ClassName.IN)
|
2014-06-23 18:07:18 +00:00
|
|
|
}
|
2015-01-03 21:58:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @param {Element} element
|
|
|
|
* @param {Element} active
|
|
|
|
* @param {boolean} isTransitioning
|
|
|
|
* @param {Function=} opt_callback
|
|
|
|
* @private
|
|
|
|
*/
|
|
|
|
Tab.prototype._transitionComplete = function (element, active, isTransitioning, opt_callback) {
|
|
|
|
if (active) {
|
|
|
|
$(active).removeClass(Tab._ClassName.ACTIVE)
|
|
|
|
|
|
|
|
var dropdownChild = $(active).find(Tab._Selector.DROPDOWN_ACTIVE_CHILD)[0]
|
|
|
|
if (dropdownChild) {
|
|
|
|
$(dropdownChild).removeClass(Tab._ClassName.ACTIVE)
|
|
|
|
}
|
2014-06-23 18:07:18 +00:00
|
|
|
|
2015-01-03 21:58:44 +00:00
|
|
|
var activeToggle = $(active).find(Tab._Selector.DATA_TOGGLE)[0]
|
|
|
|
if (activeToggle) {
|
|
|
|
activeToggle.setAttribute('aria-expanded', false)
|
2014-06-12 18:11:04 +00:00
|
|
|
}
|
2015-01-03 21:58:44 +00:00
|
|
|
}
|
2013-05-17 00:18:15 +00:00
|
|
|
|
2015-01-03 21:58:44 +00:00
|
|
|
$(element).addClass(Tab._ClassName.ACTIVE)
|
2011-11-28 01:04:55 +00:00
|
|
|
|
2015-01-03 21:58:44 +00:00
|
|
|
var elementToggle = $(element).find(Tab._Selector.DATA_TOGGLE)[0]
|
|
|
|
if (elementToggle) {
|
|
|
|
elementToggle.setAttribute('aria-expanded', true)
|
2014-06-23 18:07:18 +00:00
|
|
|
}
|
2011-11-28 01:04:55 +00:00
|
|
|
|
2015-01-03 21:58:44 +00:00
|
|
|
if (isTransitioning) {
|
|
|
|
Bootstrap.reflow(element)
|
|
|
|
$(element).addClass(Tab._ClassName.IN)
|
|
|
|
} else {
|
|
|
|
$(element).removeClass(Tab._ClassName.FADE)
|
|
|
|
}
|
2011-11-28 01:04:55 +00:00
|
|
|
|
2015-01-03 21:58:44 +00:00
|
|
|
if (element.parentNode && $(element.parentNode).hasClass(Tab._ClassName.DROPDOWN_MENU)) {
|
|
|
|
var dropdownElement = $(element).closest(Tab._Selector.LI_DROPDOWN)[0]
|
|
|
|
if (dropdownElement) {
|
|
|
|
$(dropdownElement).addClass(Tab._ClassName.ACTIVE)
|
|
|
|
}
|
2013-05-17 00:18:15 +00:00
|
|
|
|
2015-01-03 21:58:44 +00:00
|
|
|
elementToggle = $(element).find(Tab._Selector.DATA_TOGGLE)[0]
|
|
|
|
if (elementToggle) {
|
|
|
|
elementToggle.setAttribute('aria-expanded', true)
|
|
|
|
}
|
|
|
|
}
|
2011-11-28 01:04:55 +00:00
|
|
|
|
2015-01-03 21:58:44 +00:00
|
|
|
if (opt_callback) {
|
|
|
|
opt_callback()
|
2014-06-23 18:07:18 +00:00
|
|
|
}
|
2015-01-03 21:58:44 +00:00
|
|
|
}
|
2014-04-22 05:03:33 +00:00
|
|
|
|
2011-11-28 01:04:55 +00:00
|
|
|
|
2015-01-03 21:58:44 +00:00
|
|
|
/**
|
|
|
|
* ------------------------------------------------------------------------
|
|
|
|
* jQuery Interface + noConflict implementaiton
|
|
|
|
* ------------------------------------------------------------------------
|
|
|
|
*/
|
2011-11-28 01:04:55 +00:00
|
|
|
|
2015-01-03 21:58:44 +00:00
|
|
|
/**
|
|
|
|
* @const
|
|
|
|
* @type {Function}
|
|
|
|
*/
|
|
|
|
$.fn[Tab._NAME] = Tab._jQueryInterface
|
2012-12-07 22:06:01 +00:00
|
|
|
|
|
|
|
|
2015-01-03 21:58:44 +00:00
|
|
|
/**
|
|
|
|
* @const
|
|
|
|
* @type {Function}
|
|
|
|
*/
|
|
|
|
$.fn[Tab._NAME]['Constructor'] = Tab
|
2012-12-07 22:06:01 +00:00
|
|
|
|
2011-11-28 01:04:55 +00:00
|
|
|
|
2015-01-03 21:58:44 +00:00
|
|
|
/**
|
|
|
|
* @const
|
|
|
|
* @type {Function}
|
|
|
|
*/
|
|
|
|
$.fn[Tab._NAME]['noConflict'] = function () {
|
|
|
|
$.fn[Tab._NAME] = Tab._JQUERY_NO_CONFLICT
|
|
|
|
return this
|
|
|
|
}
|
2014-06-23 18:07:18 +00:00
|
|
|
|
2014-08-26 21:34:21 +00:00
|
|
|
|
2011-11-28 01:04:55 +00:00
|
|
|
|
2015-01-03 21:58:44 +00:00
|
|
|
// TAB DATA-API
|
|
|
|
// ============
|
|
|
|
|
|
|
|
var clickHandler = function (e) {
|
|
|
|
e.preventDefault()
|
|
|
|
Tab._jQueryInterface.call($(this), 'show')
|
|
|
|
}
|
|
|
|
|
|
|
|
$(document)
|
|
|
|
.on('click.bs.tab.data-api', Tab._Selector.DATA_TOGGLE, clickHandler)
|