1 /* =============================================================
2 * bootstrap-collapse.js v2.3.2
3 * http://twbs.github.com/bootstrap/javascript.html#collapse
4 * =============================================================
5 * Copyright 2013 Twitter, Inc.
7 * Licensed under the Apache License, Version 2.0 (the "License");
8 * you may not use this file except in compliance with the License.
9 * You may obtain a copy of the License at
11 * http://www.apache.org/licenses/LICENSE-2.0
13 * Unless required by applicable law or agreed to in writing, software
14 * distributed under the License is distributed on an "AS IS" BASIS,
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 * See the License for the specific language governing permissions and
17 * limitations under the License.
18 * ============================================================ */
23 "use strict"; // jshint ;_;
26 /* COLLAPSE PUBLIC CLASS DEFINITION
27 * ================================ */
29 var Collapse = function (element, options) {
30 this.$element = $(element)
31 this.options = $.extend({}, $.fn.collapse.defaults, options)
33 if (this.options.parent) {
34 this.$parent = $(this.options.parent)
37 this.options.toggle && this.toggle()
40 Collapse.prototype = {
44 , dimension: function () {
45 var hasWidth = this.$element.hasClass('width')
46 return hasWidth ? 'width' : 'height'
55 if (this.transitioning || this.$element.hasClass('in')) return
57 dimension = this.dimension()
58 scroll = $.camelCase(['scroll', dimension].join('-'))
59 actives = this.$parent && this.$parent.find('> .accordion-group > .in')
61 if (actives && actives.length) {
62 hasData = actives.data('collapse')
63 if (hasData && hasData.transitioning) return
64 actives.collapse('hide')
65 hasData || actives.data('collapse', null)
68 this.$element[dimension](0)
69 this.transition('addClass', $.Event('show'), 'shown')
70 $.support.transition && this.$element[dimension](this.$element[0][scroll])
75 if (this.transitioning || !this.$element.hasClass('in')) return
76 dimension = this.dimension()
77 this.reset(this.$element[dimension]())
78 this.transition('removeClass', $.Event('hide'), 'hidden')
79 this.$element[dimension](0)
82 , reset: function (size) {
83 var dimension = this.dimension()
86 .removeClass('collapse')
87 [dimension](size || 'auto')
90 this.$element[size !== null ? 'addClass' : 'removeClass']('collapse')
95 , transition: function (method, startEvent, completeEvent) {
97 , complete = function () {
98 if (startEvent.type == 'show') that.reset()
99 that.transitioning = 0
100 that.$element.trigger(completeEvent)
103 this.$element.trigger(startEvent)
105 if (startEvent.isDefaultPrevented()) return
107 this.transitioning = 1
109 this.$element[method]('in')
111 $.support.transition && this.$element.hasClass('collapse') ?
112 this.$element.one($.support.transition.end, complete) :
116 , toggle: function () {
117 this[this.$element.hasClass('in') ? 'hide' : 'show']()
123 /* COLLAPSE PLUGIN DEFINITION
124 * ========================== */
126 var old = $.fn.collapse
128 $.fn.collapse = function (option) {
129 return this.each(function () {
131 , data = $this.data('collapse')
132 , options = $.extend({}, $.fn.collapse.defaults, $this.data(), typeof option == 'object' && option)
133 if (!data) $this.data('collapse', (data = new Collapse(this, options)))
134 if (typeof option == 'string') data[option]()
138 $.fn.collapse.defaults = {
142 $.fn.collapse.Constructor = Collapse
145 /* COLLAPSE NO CONFLICT
146 * ==================== */
148 $.fn.collapse.noConflict = function () {
155 * ================= */
157 $(document).on('click.collapse.data-api', '[data-toggle=collapse]', function (e) {
158 var $this = $(this), href
159 , target = $this.attr('data-target')
160 || e.preventDefault()
161 || (href = $this.attr('href')) && href.replace(/.*(?=#[^\s]+$)/, '') //strip for ie7
162 , option = $(target).data('collapse') ? 'toggle' : $this.data()
163 $this[$(target).hasClass('in') ? 'addClass' : 'removeClass']('collapsed')
164 $(target).collapse(option)