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

213 lines
5.9 KiB
JavaScript
Raw Permalink Normal View History

2014-05-12 20:08:19 +02:00
/* ========================================================================
2019-03-29 22:00:08 +01:00
* Bootstrap: collapse.js v3.4.1
* https://getbootstrap.com/docs/3.4/javascript/#collapse
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)
* ======================================================================== */
2017-05-13 13:25:33 +02:00
/* jshint latedef: false */
2014-05-12 20:08:19 +02:00
+function ($) {
'use strict';
// COLLAPSE PUBLIC CLASS DEFINITION
// ================================
var Collapse = function (element, options) {
this.$element = $(element)
this.options = $.extend({}, Collapse.DEFAULTS, options)
2016-05-16 13:33:49 +02:00
this.$trigger = $('[data-toggle="collapse"][href="#' + element.id + '"],' +
'[data-toggle="collapse"][data-target="#' + element.id + '"]')
2014-05-12 20:08:19 +02:00
this.transitioning = null
2016-05-16 13:33:49 +02:00
if (this.options.parent) {
this.$parent = this.getParent()
} else {
this.addAriaAndCollapsedClass(this.$element, this.$trigger)
}
2014-05-12 20:08:19 +02:00
if (this.options.toggle) this.toggle()
}
2019-03-29 22:00:08 +01:00
Collapse.VERSION = '3.4.1'
2016-05-16 13:33:49 +02:00
Collapse.TRANSITION_DURATION = 350
2014-08-10 12:02:48 +02:00
2014-05-12 20:08:19 +02:00
Collapse.DEFAULTS = {
toggle: true
}
Collapse.prototype.dimension = function () {
var hasWidth = this.$element.hasClass('width')
return hasWidth ? 'width' : 'height'
}
Collapse.prototype.show = function () {
if (this.transitioning || this.$element.hasClass('in')) return
2016-05-16 13:33:49 +02:00
var activesData
var actives = this.$parent && this.$parent.children('.panel').children('.in, .collapsing')
if (actives && actives.length) {
activesData = actives.data('bs.collapse')
if (activesData && activesData.transitioning) return
}
2014-05-12 20:08:19 +02:00
var startEvent = $.Event('show.bs.collapse')
this.$element.trigger(startEvent)
if (startEvent.isDefaultPrevented()) return
if (actives && actives.length) {
2014-08-10 12:02:48 +02:00
Plugin.call(actives, 'hide')
2016-05-16 13:33:49 +02:00
activesData || actives.data('bs.collapse', null)
2014-05-12 20:08:19 +02:00
}
var dimension = this.dimension()
this.$element
.removeClass('collapse')
.addClass('collapsing')[dimension](0)
2016-05-16 13:33:49 +02:00
.attr('aria-expanded', true)
this.$trigger
.removeClass('collapsed')
.attr('aria-expanded', true)
2014-05-12 20:08:19 +02:00
this.transitioning = 1
2014-08-10 12:02:48 +02:00
var complete = function () {
2014-05-12 20:08:19 +02:00
this.$element
.removeClass('collapsing')
.addClass('collapse in')[dimension]('')
this.transitioning = 0
2014-08-10 12:02:48 +02:00
this.$element
.trigger('shown.bs.collapse')
2014-05-12 20:08:19 +02:00
}
if (!$.support.transition) return complete.call(this)
var scrollSize = $.camelCase(['scroll', dimension].join('-'))
this.$element
2014-08-10 12:02:48 +02:00
.one('bsTransitionEnd', $.proxy(complete, this))
2016-05-16 13:33:49 +02:00
.emulateTransitionEnd(Collapse.TRANSITION_DURATION)[dimension](this.$element[0][scrollSize])
2014-05-12 20:08:19 +02:00
}
Collapse.prototype.hide = function () {
if (this.transitioning || !this.$element.hasClass('in')) return
var startEvent = $.Event('hide.bs.collapse')
this.$element.trigger(startEvent)
if (startEvent.isDefaultPrevented()) return
var dimension = this.dimension()
this.$element[dimension](this.$element[dimension]())[0].offsetHeight
this.$element
.addClass('collapsing')
2016-05-16 13:33:49 +02:00
.removeClass('collapse in')
.attr('aria-expanded', false)
this.$trigger
.addClass('collapsed')
.attr('aria-expanded', false)
2014-05-12 20:08:19 +02:00
this.transitioning = 1
2014-08-10 12:02:48 +02:00
var complete = function () {
2014-05-12 20:08:19 +02:00
this.transitioning = 0
this.$element
.removeClass('collapsing')
.addClass('collapse')
2016-05-16 13:33:49 +02:00
.trigger('hidden.bs.collapse')
2014-05-12 20:08:19 +02:00
}
if (!$.support.transition) return complete.call(this)
this.$element
[dimension](0)
2014-08-10 12:02:48 +02:00
.one('bsTransitionEnd', $.proxy(complete, this))
2016-05-16 13:33:49 +02:00
.emulateTransitionEnd(Collapse.TRANSITION_DURATION)
2014-05-12 20:08:19 +02:00
}
Collapse.prototype.toggle = function () {
this[this.$element.hasClass('in') ? 'hide' : 'show']()
}
2016-05-16 13:33:49 +02:00
Collapse.prototype.getParent = function () {
2019-03-29 22:00:08 +01:00
return $(document).find(this.options.parent)
2016-05-16 13:33:49 +02:00
.find('[data-toggle="collapse"][data-parent="' + this.options.parent + '"]')
.each($.proxy(function (i, element) {
var $element = $(element)
this.addAriaAndCollapsedClass(getTargetFromTrigger($element), $element)
}, this))
.end()
}
Collapse.prototype.addAriaAndCollapsedClass = function ($element, $trigger) {
var isOpen = $element.hasClass('in')
$element.attr('aria-expanded', isOpen)
$trigger
.toggleClass('collapsed', !isOpen)
.attr('aria-expanded', isOpen)
}
function getTargetFromTrigger($trigger) {
var href
var target = $trigger.attr('data-target')
|| (href = $trigger.attr('href')) && href.replace(/.*(?=#[^\s]+$)/, '') // strip for ie7
2019-03-29 22:00:08 +01:00
return $(document).find(target)
2016-05-16 13:33:49 +02:00
}
2014-05-12 20:08:19 +02:00
// COLLAPSE 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.collapse')
var options = $.extend({}, Collapse.DEFAULTS, $this.data(), typeof option == 'object' && option)
2016-05-16 13:33:49 +02:00
if (!data && options.toggle && /show|hide/.test(option)) options.toggle = false
2014-05-12 20:08:19 +02:00
if (!data) $this.data('bs.collapse', (data = new Collapse(this, options)))
if (typeof option == 'string') data[option]()
})
}
2014-08-10 12:02:48 +02:00
var old = $.fn.collapse
$.fn.collapse = Plugin
2014-05-12 20:08:19 +02:00
$.fn.collapse.Constructor = Collapse
// COLLAPSE NO CONFLICT
// ====================
$.fn.collapse.noConflict = function () {
$.fn.collapse = old
return this
}
// COLLAPSE DATA-API
// =================
$(document).on('click.bs.collapse.data-api', '[data-toggle="collapse"]', function (e) {
2014-08-10 12:02:48 +02:00
var $this = $(this)
2016-05-16 13:33:49 +02:00
if (!$this.attr('data-target')) e.preventDefault()
var $target = getTargetFromTrigger($this)
2014-05-12 20:08:19 +02:00
var data = $target.data('bs.collapse')
var option = data ? 'toggle' : $this.data()
2014-08-10 12:02:48 +02:00
Plugin.call($target, option)
2014-05-12 20:08:19 +02:00
})
}(jQuery);