1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/bootstrap-source/bootstrap-3.0.3/js/collapse.js Fri Dec 20 22:49:16 2013 +0100
1.3 @@ -0,0 +1,179 @@
1.4 +/* ========================================================================
1.5 + * Bootstrap: collapse.js v3.0.3
1.6 + * http://getbootstrap.com/javascript/#collapse
1.7 + * ========================================================================
1.8 + * Copyright 2013 Twitter, Inc.
1.9 + *
1.10 + * Licensed under the Apache License, Version 2.0 (the "License");
1.11 + * you may not use this file except in compliance with the License.
1.12 + * You may obtain a copy of the License at
1.13 + *
1.14 + * http://www.apache.org/licenses/LICENSE-2.0
1.15 + *
1.16 + * Unless required by applicable law or agreed to in writing, software
1.17 + * distributed under the License is distributed on an "AS IS" BASIS,
1.18 + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1.19 + * See the License for the specific language governing permissions and
1.20 + * limitations under the License.
1.21 + * ======================================================================== */
1.22 +
1.23 +
1.24 ++function ($) { "use strict";
1.25 +
1.26 + // COLLAPSE PUBLIC CLASS DEFINITION
1.27 + // ================================
1.28 +
1.29 + var Collapse = function (element, options) {
1.30 + this.$element = $(element)
1.31 + this.options = $.extend({}, Collapse.DEFAULTS, options)
1.32 + this.transitioning = null
1.33 +
1.34 + if (this.options.parent) this.$parent = $(this.options.parent)
1.35 + if (this.options.toggle) this.toggle()
1.36 + }
1.37 +
1.38 + Collapse.DEFAULTS = {
1.39 + toggle: true
1.40 + }
1.41 +
1.42 + Collapse.prototype.dimension = function () {
1.43 + var hasWidth = this.$element.hasClass('width')
1.44 + return hasWidth ? 'width' : 'height'
1.45 + }
1.46 +
1.47 + Collapse.prototype.show = function () {
1.48 + if (this.transitioning || this.$element.hasClass('in')) return
1.49 +
1.50 + var startEvent = $.Event('show.bs.collapse')
1.51 + this.$element.trigger(startEvent)
1.52 + if (startEvent.isDefaultPrevented()) return
1.53 +
1.54 + var actives = this.$parent && this.$parent.find('> .panel > .in')
1.55 +
1.56 + if (actives && actives.length) {
1.57 + var hasData = actives.data('bs.collapse')
1.58 + if (hasData && hasData.transitioning) return
1.59 + actives.collapse('hide')
1.60 + hasData || actives.data('bs.collapse', null)
1.61 + }
1.62 +
1.63 + var dimension = this.dimension()
1.64 +
1.65 + this.$element
1.66 + .removeClass('collapse')
1.67 + .addClass('collapsing')
1.68 + [dimension](0)
1.69 +
1.70 + this.transitioning = 1
1.71 +
1.72 + var complete = function () {
1.73 + this.$element
1.74 + .removeClass('collapsing')
1.75 + .addClass('in')
1.76 + [dimension]('auto')
1.77 + this.transitioning = 0
1.78 + this.$element.trigger('shown.bs.collapse')
1.79 + }
1.80 +
1.81 + if (!$.support.transition) return complete.call(this)
1.82 +
1.83 + var scrollSize = $.camelCase(['scroll', dimension].join('-'))
1.84 +
1.85 + this.$element
1.86 + .one($.support.transition.end, $.proxy(complete, this))
1.87 + .emulateTransitionEnd(350)
1.88 + [dimension](this.$element[0][scrollSize])
1.89 + }
1.90 +
1.91 + Collapse.prototype.hide = function () {
1.92 + if (this.transitioning || !this.$element.hasClass('in')) return
1.93 +
1.94 + var startEvent = $.Event('hide.bs.collapse')
1.95 + this.$element.trigger(startEvent)
1.96 + if (startEvent.isDefaultPrevented()) return
1.97 +
1.98 + var dimension = this.dimension()
1.99 +
1.100 + this.$element
1.101 + [dimension](this.$element[dimension]())
1.102 + [0].offsetHeight
1.103 +
1.104 + this.$element
1.105 + .addClass('collapsing')
1.106 + .removeClass('collapse')
1.107 + .removeClass('in')
1.108 +
1.109 + this.transitioning = 1
1.110 +
1.111 + var complete = function () {
1.112 + this.transitioning = 0
1.113 + this.$element
1.114 + .trigger('hidden.bs.collapse')
1.115 + .removeClass('collapsing')
1.116 + .addClass('collapse')
1.117 + }
1.118 +
1.119 + if (!$.support.transition) return complete.call(this)
1.120 +
1.121 + this.$element
1.122 + [dimension](0)
1.123 + .one($.support.transition.end, $.proxy(complete, this))
1.124 + .emulateTransitionEnd(350)
1.125 + }
1.126 +
1.127 + Collapse.prototype.toggle = function () {
1.128 + this[this.$element.hasClass('in') ? 'hide' : 'show']()
1.129 + }
1.130 +
1.131 +
1.132 + // COLLAPSE PLUGIN DEFINITION
1.133 + // ==========================
1.134 +
1.135 + var old = $.fn.collapse
1.136 +
1.137 + $.fn.collapse = function (option) {
1.138 + return this.each(function () {
1.139 + var $this = $(this)
1.140 + var data = $this.data('bs.collapse')
1.141 + var options = $.extend({}, Collapse.DEFAULTS, $this.data(), typeof option == 'object' && option)
1.142 +
1.143 + if (!data) $this.data('bs.collapse', (data = new Collapse(this, options)))
1.144 + if (typeof option == 'string') data[option]()
1.145 + })
1.146 + }
1.147 +
1.148 + $.fn.collapse.Constructor = Collapse
1.149 +
1.150 +
1.151 + // COLLAPSE NO CONFLICT
1.152 + // ====================
1.153 +
1.154 + $.fn.collapse.noConflict = function () {
1.155 + $.fn.collapse = old
1.156 + return this
1.157 + }
1.158 +
1.159 +
1.160 + // COLLAPSE DATA-API
1.161 + // =================
1.162 +
1.163 + $(document).on('click.bs.collapse.data-api', '[data-toggle=collapse]', function (e) {
1.164 + var $this = $(this), href
1.165 + var target = $this.attr('data-target')
1.166 + || e.preventDefault()
1.167 + || (href = $this.attr('href')) && href.replace(/.*(?=#[^\s]+$)/, '') //strip for ie7
1.168 + var $target = $(target)
1.169 + var data = $target.data('bs.collapse')
1.170 + var option = data ? 'toggle' : $this.data()
1.171 + var parent = $this.attr('data-parent')
1.172 + var $parent = parent && $(parent)
1.173 +
1.174 + if (!data || !data.transitioning) {
1.175 + if ($parent) $parent.find('[data-toggle=collapse][data-parent="' + parent + '"]').not($this).addClass('collapsed')
1.176 + $this[$target.hasClass('in') ? 'addClass' : 'removeClass']('collapsed')
1.177 + }
1.178 +
1.179 + $target.collapse(option)
1.180 + })
1.181 +
1.182 +}(jQuery);