ffffng/app/bower_components/bootstrap-sass-official/assets/javascripts/bootstrap/tab.js

156 lines
3.8 KiB
JavaScript
Raw Permalink Normal View History

2014-05-12 20:08:19 +02:00
/* ========================================================================
2019-03-29 22:00:08 +01:00
* Bootstrap: tab.js v3.4.1
* https://getbootstrap.com/docs/3.4/javascript/#tabs
2014-05-12 20:08:19 +02:00
* ========================================================================
2019-03-29 22:00:08 +01:00
* Copyright 2011-2019 Twitter, Inc.
2014-05-12 20:08:19 +02:00
* Licensed under MIT (https://github.com/twbs/bootstrap/blob/master/LICENSE)
* ======================================================================== */
+function ($) {
'use strict';
// TAB CLASS DEFINITION
// ====================
var Tab = function (element) {
2016-05-16 13:33:49 +02:00
// jscs:disable requireDollarBeforejQueryAssignment
2014-05-12 20:08:19 +02:00
this.element = $(element)
2016-05-16 13:33:49 +02:00
// jscs:enable requireDollarBeforejQueryAssignment
2014-05-12 20:08:19 +02:00
}
2019-03-29 22:00:08 +01:00
Tab.VERSION = '3.4.1'
2016-05-16 13:33:49 +02:00
Tab.TRANSITION_DURATION = 150
2014-08-10 12:02:48 +02:00
2014-05-12 20:08:19 +02:00
Tab.prototype.show = function () {
var $this = this.element
var $ul = $this.closest('ul:not(.dropdown-menu)')
var selector = $this.data('target')
if (!selector) {
selector = $this.attr('href')
2014-08-10 12:02:48 +02:00
selector = selector && selector.replace(/.*(?=#[^\s]*$)/, '') // strip for ie7
2014-05-12 20:08:19 +02:00
}
if ($this.parent('li').hasClass('active')) return
2016-05-16 13:33:49 +02:00
var $previous = $ul.find('.active:last a')
var hideEvent = $.Event('hide.bs.tab', {
relatedTarget: $this[0]
})
var showEvent = $.Event('show.bs.tab', {
relatedTarget: $previous[0]
2014-05-12 20:08:19 +02:00
})
2016-05-16 13:33:49 +02:00
$previous.trigger(hideEvent)
$this.trigger(showEvent)
2014-05-12 20:08:19 +02:00
2016-05-16 13:33:49 +02:00
if (showEvent.isDefaultPrevented() || hideEvent.isDefaultPrevented()) return
2014-05-12 20:08:19 +02:00
2019-03-29 22:00:08 +01:00
var $target = $(document).find(selector)
2014-05-12 20:08:19 +02:00
2014-08-10 12:02:48 +02:00
this.activate($this.closest('li'), $ul)
2014-05-12 20:08:19 +02:00
this.activate($target, $target.parent(), function () {
2016-05-16 13:33:49 +02:00
$previous.trigger({
type: 'hidden.bs.tab',
relatedTarget: $this[0]
})
2014-05-12 20:08:19 +02:00
$this.trigger({
type: 'shown.bs.tab',
2016-05-16 13:33:49 +02:00
relatedTarget: $previous[0]
2014-05-12 20:08:19 +02:00
})
})
}
Tab.prototype.activate = function (element, container, callback) {
var $active = container.find('> .active')
var transition = callback
&& $.support.transition
2016-05-16 13:33:49 +02:00
&& ($active.length && $active.hasClass('fade') || !!container.find('> .fade').length)
2014-05-12 20:08:19 +02:00
function next() {
$active
.removeClass('active')
.find('> .dropdown-menu > .active')
2019-03-29 22:00:08 +01:00
.removeClass('active')
2016-05-16 13:33:49 +02:00
.end()
.find('[data-toggle="tab"]')
2019-03-29 22:00:08 +01:00
.attr('aria-expanded', false)
2014-05-12 20:08:19 +02:00
2016-05-16 13:33:49 +02:00
element
.addClass('active')
.find('[data-toggle="tab"]')
2019-03-29 22:00:08 +01:00
.attr('aria-expanded', true)
2014-05-12 20:08:19 +02:00
if (transition) {
element[0].offsetWidth // reflow for transition
element.addClass('in')
} else {
element.removeClass('fade')
}
2016-05-16 13:33:49 +02:00
if (element.parent('.dropdown-menu').length) {
element
.closest('li.dropdown')
2019-03-29 22:00:08 +01:00
.addClass('active')
2016-05-16 13:33:49 +02:00
.end()
.find('[data-toggle="tab"]')
2019-03-29 22:00:08 +01:00
.attr('aria-expanded', true)
2014-05-12 20:08:19 +02:00
}
callback && callback()
}
2016-05-16 13:33:49 +02:00
$active.length && transition ?
2014-05-12 20:08:19 +02:00
$active
2014-08-10 12:02:48 +02:00
.one('bsTransitionEnd', next)
2016-05-16 13:33:49 +02:00
.emulateTransitionEnd(Tab.TRANSITION_DURATION) :
2014-05-12 20:08:19 +02:00
next()
$active.removeClass('in')
}
// TAB PLUGIN DEFINITION
// =====================
2014-08-10 12:02:48 +02:00
function Plugin(option) {
2014-05-12 20:08:19 +02:00
return this.each(function () {
var $this = $(this)
var data = $this.data('bs.tab')
if (!data) $this.data('bs.tab', (data = new Tab(this)))
if (typeof option == 'string') data[option]()
})
}
2014-08-10 12:02:48 +02:00
var old = $.fn.tab
$.fn.tab = Plugin
2014-05-12 20:08:19 +02:00
$.fn.tab.Constructor = Tab
// TAB NO CONFLICT
// ===============
$.fn.tab.noConflict = function () {
$.fn.tab = old
return this
}
// TAB DATA-API
// ============
2016-05-16 13:33:49 +02:00
var clickHandler = function (e) {
2014-05-12 20:08:19 +02:00
e.preventDefault()
2014-08-10 12:02:48 +02:00
Plugin.call($(this), 'show')
2016-05-16 13:33:49 +02:00
}
$(document)
.on('click.bs.tab.data-api', '[data-toggle="tab"]', clickHandler)
.on('click.bs.tab.data-api', '[data-toggle="pill"]', clickHandler)
2014-05-12 20:08:19 +02:00
}(jQuery);