mirror of
https://github.com/twbs/bootstrap.git
synced 2022-11-09 12:25:43 -05:00
127 lines
3.5 KiB
JavaScript
127 lines
3.5 KiB
JavaScript
|
/* =============================================================
|
||
|
* bootstrap-collapsible.js v2.0.0
|
||
|
* http://twitter.github.com/bootstrap/javascript.html#collapsible
|
||
|
* =============================================================
|
||
|
* Copyright 2011 Twitter, Inc.
|
||
|
*
|
||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||
|
* you may not use this file except in compliance with the License.
|
||
|
* You may obtain a copy of the License at
|
||
|
*
|
||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||
|
*
|
||
|
* Unless required by applicable law or agreed to in writing, software
|
||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||
|
* See the License for the specific language governing permissions and
|
||
|
* limitations under the License.
|
||
|
* ============================================================ */
|
||
|
|
||
|
(function( $ ){
|
||
|
|
||
|
"use strict"
|
||
|
|
||
|
var Collapse = function ( element, options ) {
|
||
|
this.$element = $(element)
|
||
|
this.settings = $.extend({}, $.fn.collapse.defaults, options)
|
||
|
|
||
|
if (this.settings["parent"]) {
|
||
|
this.$parent = $(this.settings["parent"])
|
||
|
}
|
||
|
|
||
|
this.settings.toggle && this.toggle()
|
||
|
}
|
||
|
|
||
|
Collapse.prototype = {
|
||
|
|
||
|
dimension: function () {
|
||
|
var hasWidth = this.$element.hasClass('width')
|
||
|
return hasWidth ? 'width' : 'height'
|
||
|
}
|
||
|
|
||
|
, show: function () {
|
||
|
var dimension = this.dimension()
|
||
|
, scroll = $.camelCase(['scroll', dimension].join('-'))
|
||
|
|
||
|
this.$parent && this.$parent.find('.in').collapse('hide')
|
||
|
|
||
|
this.$element[dimension](0)
|
||
|
this.transition('addClass', 'show', 'shown')
|
||
|
this.$element[dimension](this.$element[0][scroll])
|
||
|
|
||
|
}
|
||
|
|
||
|
, hide: function () {
|
||
|
var dimension = this.dimension()
|
||
|
this.reset(this.$element[dimension]())
|
||
|
this.transition('removeClass', 'hide', 'hidden')
|
||
|
this.$element[dimension](0)
|
||
|
}
|
||
|
|
||
|
, reset: function ( size ) {
|
||
|
var dimension = this.dimension()
|
||
|
|
||
|
this.$element
|
||
|
.removeClass('collapse')
|
||
|
[dimension](size || '')
|
||
|
[0].offsetWidth
|
||
|
|
||
|
this.$element.addClass('collapse')
|
||
|
}
|
||
|
|
||
|
, transition: function ( method, startEvent, completeEvent ) {
|
||
|
var that = this
|
||
|
, complete = function () {
|
||
|
if (startEvent == 'show') that.reset()
|
||
|
that.$element.trigger(completeEvent)
|
||
|
}
|
||
|
|
||
|
this.$element
|
||
|
.trigger(startEvent)
|
||
|
[method]('in')
|
||
|
|
||
|
$.support.transition && this.$element.hasClass('collapse') ?
|
||
|
this.$element.one($.support.transition.end, complete) :
|
||
|
complete()
|
||
|
}
|
||
|
|
||
|
, toggle: function () {
|
||
|
this[this.$element.hasClass('in') ? 'hide' : 'show']()
|
||
|
}
|
||
|
|
||
|
}
|
||
|
|
||
|
/* COLLAPSIBLE PLUGIN DEFINITION
|
||
|
* ============================== */
|
||
|
|
||
|
$.fn.collapse = function ( option ) {
|
||
|
return this.each(function () {
|
||
|
var $this = $(this)
|
||
|
, data = $this.data('collapse')
|
||
|
, options = typeof option == 'object' && option
|
||
|
if (!data) $this.data('collapse', (data = new Collapse(this, options)))
|
||
|
if (typeof option == 'string') data[option]()
|
||
|
})
|
||
|
}
|
||
|
|
||
|
$.fn.collapse.defaults = {
|
||
|
toggle: true
|
||
|
}
|
||
|
|
||
|
$.fn.collapse.Collapse = Collapse
|
||
|
|
||
|
|
||
|
/* COLLAPSIBLE DATA-API
|
||
|
* ==================== */
|
||
|
|
||
|
$(function () {
|
||
|
$('body').delegate('[data-toggle=collapse]', 'click.collapse.data-api', function ( e ) {
|
||
|
var $this = $(this)
|
||
|
, target = $this.attr('data-target')
|
||
|
, option = $(target).data('collapse') ? 'toggle' : $this.data()
|
||
|
e.preventDefault()
|
||
|
$(target).collapse(option)
|
||
|
})
|
||
|
})
|
||
|
|
||
|
})( window.jQuery || window.ender )
|