aboutsummaryrefslogtreecommitdiff
path: root/js/bootstrap-collapse.js
diff options
context:
space:
mode:
authorMark Otto <[email protected]>2011-11-29 22:35:58 -0800
committerMark Otto <[email protected]>2011-11-29 22:35:58 -0800
commitcbb291b8ab316c3c0103da3c7b7a2c73596cfef2 (patch)
treee632dc37d1f3dda4e91a06d4f671313a7e476187 /js/bootstrap-collapse.js
parentb36df463108e2e4df8c389a06f577823564788d9 (diff)
parent08d0aff19f8ad8fa2a9cfa389b8753c4525ea99c (diff)
downloadbootstrap-cbb291b8ab316c3c0103da3c7b7a2c73596cfef2.tar.xz
bootstrap-cbb291b8ab316c3c0103da3c7b7a2c73596cfef2.zip
Merge branch '2.0-wip' of github.com:twitter/bootstrap into 2.0-wip
Conflicts: bootstrap.css bootstrap.min.css
Diffstat (limited to 'js/bootstrap-collapse.js')
-rw-r--r--js/bootstrap-collapse.js133
1 files changed, 133 insertions, 0 deletions
diff --git a/js/bootstrap-collapse.js b/js/bootstrap-collapse.js
new file mode 100644
index 000000000..93f91513e
--- /dev/null
+++ b/js/bootstrap-collapse.js
@@ -0,0 +1,133 @@
+/* =============================================================
+ * 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('-'))
+ , actives = this.$parent && this.$parent.find('.in')
+ , hasData
+
+ if (actives && actives.length) {
+ hasData = actives.data('collapse')
+ actives.collapse('hide')
+ hasData || actives.data('collapse', null)
+ }
+
+ 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') || $this.attr('href')
+ , option = $(target).data('collapse') ? 'toggle' : $this.data()
+ e.preventDefault()
+ $(target).collapse(option)
+ })
+ })
+
+})( window.jQuery || window.ender ) \ No newline at end of file