File indexing completed on 2024-12-22 05:33:16

0001 /* =============================================================
0002  * bootstrap-collapse.js v2.0.4
0003  * http://twitter.github.com/bootstrap/javascript.html#collapse
0004  * =============================================================
0005  * Copyright 2012 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 ($) {
0022 
0023   "use strict"; // jshint ;_;
0024 
0025 
0026  /* COLLAPSE PUBLIC CLASS DEFINITION
0027   * ================================ */
0028 
0029   var Collapse = function (element, options) {
0030     this.$element = $(element)
0031     this.options = $.extend({}, $.fn.collapse.defaults, options)
0032 
0033     if (this.options.parent) {
0034       this.$parent = $(this.options.parent)
0035     }
0036 
0037     this.options.toggle && this.toggle()
0038   }
0039 
0040   Collapse.prototype = {
0041 
0042     constructor: Collapse
0043 
0044   , dimension: function () {
0045       var hasWidth = this.$element.hasClass('width')
0046       return hasWidth ? 'width' : 'height'
0047     }
0048 
0049   , show: function () {
0050       var dimension
0051         , scroll
0052         , actives
0053         , hasData
0054 
0055       if (this.transitioning) return
0056 
0057       dimension = this.dimension()
0058       scroll = $.camelCase(['scroll', dimension].join('-'))
0059       actives = this.$parent && this.$parent.find('> .accordion-group > .in')
0060 
0061       if (actives && actives.length) {
0062         hasData = actives.data('collapse')
0063         if (hasData && hasData.transitioning) return
0064         actives.collapse('hide')
0065         hasData || actives.data('collapse', null)
0066       }
0067 
0068       this.$element[dimension](0)
0069       this.transition('addClass', $.Event('show'), 'shown')
0070       this.$element[dimension](this.$element[0][scroll])
0071     }
0072 
0073   , hide: function () {
0074       var dimension
0075       if (this.transitioning) return
0076       dimension = this.dimension()
0077       this.reset(this.$element[dimension]())
0078       this.transition('removeClass', $.Event('hide'), 'hidden')
0079       this.$element[dimension](0)
0080     }
0081 
0082   , reset: function (size) {
0083       var dimension = this.dimension()
0084 
0085       this.$element
0086         .removeClass('collapse')
0087         [dimension](size || 'auto')
0088         [0].offsetWidth
0089 
0090       this.$element[size !== null ? 'addClass' : 'removeClass']('collapse')
0091 
0092       return this
0093     }
0094 
0095   , transition: function (method, startEvent, completeEvent) {
0096       var that = this
0097         , complete = function () {
0098             if (startEvent.type == 'show') that.reset()
0099             that.transitioning = 0
0100             that.$element.trigger(completeEvent)
0101           }
0102 
0103       this.$element.trigger(startEvent)
0104 
0105       if (startEvent.isDefaultPrevented()) return
0106 
0107       this.transitioning = 1
0108 
0109       this.$element[method]('in')
0110 
0111       $.support.transition && this.$element.hasClass('collapse') ?
0112         this.$element.one($.support.transition.end, complete) :
0113         complete()
0114     }
0115 
0116   , toggle: function () {
0117       this[this.$element.hasClass('in') ? 'hide' : 'show']()
0118     }
0119 
0120   }
0121 
0122 
0123  /* COLLAPSIBLE PLUGIN DEFINITION
0124   * ============================== */
0125 
0126   $.fn.collapse = function (option) {
0127     return this.each(function () {
0128       var $this = $(this)
0129         , data = $this.data('collapse')
0130         , options = typeof option == 'object' && option
0131       if (!data) $this.data('collapse', (data = new Collapse(this, options)))
0132       if (typeof option == 'string') data[option]()
0133     })
0134   }
0135 
0136   $.fn.collapse.defaults = {
0137     toggle: true
0138   }
0139 
0140   $.fn.collapse.Constructor = Collapse
0141 
0142 
0143  /* COLLAPSIBLE DATA-API
0144   * ==================== */
0145 
0146   $(function () {
0147     $('body').on('click.collapse.data-api', '[data-toggle=collapse]', function ( e ) {
0148       var $this = $(this), href
0149         , target = $this.attr('data-target')
0150           || e.preventDefault()
0151           || (href = $this.attr('href')) && href.replace(/.*(?=#[^\s]+$)/, '') //strip for ie7
0152         , option = $(target).data('collapse') ? 'toggle' : $this.data()
0153       $(target).collapse(option)
0154     })
0155   })
0156 
0157 }(window.jQuery);