File indexing completed on 2024-05-19 06:00:17

0001 /* ========================================================================
0002  * Bootstrap: collapse.js v3.0.3
0003  * http://getbootstrap.com/javascript/#collapse
0004  * ========================================================================
0005  * Copyright 2013 Twitter, Inc.
0006  *
0007  * Licensed under the Apache License, Version 2.0 (the "License");
0008  * you may not use this file except in compliance with the License.
0009  * You may obtain a copy of the License at
0010  *
0011  * http://www.apache.org/licenses/LICENSE-2.0
0012  *
0013  * Unless required by applicable law or agreed to in writing, software
0014  * distributed under the License is distributed on an "AS IS" BASIS,
0015  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
0016  * See the License for the specific language governing permissions and
0017  * limitations under the License.
0018  * ======================================================================== */
0019 
0020 
0021 +function ($) { "use strict";
0022 
0023   // COLLAPSE PUBLIC CLASS DEFINITION
0024   // ================================
0025 
0026   var Collapse = function (element, options) {
0027     this.$element      = $(element)
0028     this.options       = $.extend({}, Collapse.DEFAULTS, options)
0029     this.transitioning = null
0030 
0031     if (this.options.parent) this.$parent = $(this.options.parent)
0032     if (this.options.toggle) this.toggle()
0033   }
0034 
0035   Collapse.DEFAULTS = {
0036     toggle: true
0037   }
0038 
0039   Collapse.prototype.dimension = function () {
0040     var hasWidth = this.$element.hasClass('width')
0041     return hasWidth ? 'width' : 'height'
0042   }
0043 
0044   Collapse.prototype.show = function () {
0045     if (this.transitioning || this.$element.hasClass('in')) return
0046 
0047     var startEvent = $.Event('show.bs.collapse')
0048     this.$element.trigger(startEvent)
0049     if (startEvent.isDefaultPrevented()) return
0050 
0051     var actives = this.$parent && this.$parent.find('> .panel > .in')
0052 
0053     if (actives && actives.length) {
0054       var hasData = actives.data('bs.collapse')
0055       if (hasData && hasData.transitioning) return
0056       actives.collapse('hide')
0057       hasData || actives.data('bs.collapse', null)
0058     }
0059 
0060     var dimension = this.dimension()
0061 
0062     this.$element
0063       .removeClass('collapse')
0064       .addClass('collapsing')
0065       [dimension](0)
0066 
0067     this.transitioning = 1
0068 
0069     var complete = function () {
0070       this.$element
0071         .removeClass('collapsing')
0072         .addClass('in')
0073         [dimension]('auto')
0074       this.transitioning = 0
0075       this.$element.trigger('shown.bs.collapse')
0076     }
0077 
0078     if (!$.support.transition) return complete.call(this)
0079 
0080     var scrollSize = $.camelCase(['scroll', dimension].join('-'))
0081 
0082     this.$element
0083       .one($.support.transition.end, $.proxy(complete, this))
0084       .emulateTransitionEnd(350)
0085       [dimension](this.$element[0][scrollSize])
0086   }
0087 
0088   Collapse.prototype.hide = function () {
0089     if (this.transitioning || !this.$element.hasClass('in')) return
0090 
0091     var startEvent = $.Event('hide.bs.collapse')
0092     this.$element.trigger(startEvent)
0093     if (startEvent.isDefaultPrevented()) return
0094 
0095     var dimension = this.dimension()
0096 
0097     this.$element
0098       [dimension](this.$element[dimension]())
0099       [0].offsetHeight
0100 
0101     this.$element
0102       .addClass('collapsing')
0103       .removeClass('collapse')
0104       .removeClass('in')
0105 
0106     this.transitioning = 1
0107 
0108     var complete = function () {
0109       this.transitioning = 0
0110       this.$element
0111         .trigger('hidden.bs.collapse')
0112         .removeClass('collapsing')
0113         .addClass('collapse')
0114     }
0115 
0116     if (!$.support.transition) return complete.call(this)
0117 
0118     this.$element
0119       [dimension](0)
0120       .one($.support.transition.end, $.proxy(complete, this))
0121       .emulateTransitionEnd(350)
0122   }
0123 
0124   Collapse.prototype.toggle = function () {
0125     this[this.$element.hasClass('in') ? 'hide' : 'show']()
0126   }
0127 
0128 
0129   // COLLAPSE PLUGIN DEFINITION
0130   // ==========================
0131 
0132   var old = $.fn.collapse
0133 
0134   $.fn.collapse = function (option) {
0135     return this.each(function () {
0136       var $this   = $(this)
0137       var data    = $this.data('bs.collapse')
0138       var options = $.extend({}, Collapse.DEFAULTS, $this.data(), typeof option == 'object' && option)
0139 
0140       if (!data) $this.data('bs.collapse', (data = new Collapse(this, options)))
0141       if (typeof option == 'string') data[option]()
0142     })
0143   }
0144 
0145   $.fn.collapse.Constructor = Collapse
0146 
0147 
0148   // COLLAPSE NO CONFLICT
0149   // ====================
0150 
0151   $.fn.collapse.noConflict = function () {
0152     $.fn.collapse = old
0153     return this
0154   }
0155 
0156 
0157   // COLLAPSE DATA-API
0158   // =================
0159 
0160   $(document).on('click.bs.collapse.data-api', '[data-toggle=collapse]', function (e) {
0161     var $this   = $(this), href
0162     var target  = $this.attr('data-target')
0163         || e.preventDefault()
0164         || (href = $this.attr('href')) && href.replace(/.*(?=#[^\s]+$)/, '') //strip for ie7
0165     var $target = $(target)
0166     var data    = $target.data('bs.collapse')
0167     var option  = data ? 'toggle' : $this.data()
0168     var parent  = $this.attr('data-parent')
0169     var $parent = parent && $(parent)
0170 
0171     if (!data || !data.transitioning) {
0172       if ($parent) $parent.find('[data-toggle=collapse][data-parent="' + parent + '"]').not($this).addClass('collapsed')
0173       $this[$target.hasClass('in') ? 'addClass' : 'removeClass']('collapsed')
0174     }
0175 
0176     $target.collapse(option)
0177   })
0178 
0179 }(jQuery);