diff options
| author | Jacob Thornton <[email protected]> | 2011-11-25 17:23:14 -0800 |
|---|---|---|
| committer | Jacob Thornton <[email protected]> | 2011-11-25 17:23:14 -0800 |
| commit | 98fddaa3557b1c872f1e585d579ec7e5e989e95d (patch) | |
| tree | 50a1963f3cd4c7059a94ebedb41d70d32f0a300a /js | |
| parent | 96adf8f91811a71bf2fbd6737c8bd80fe400b8c2 (diff) | |
| download | bootstrap-98fddaa3557b1c872f1e585d579ec7e5e989e95d.tar.xz bootstrap-98fddaa3557b1c872f1e585d579ec7e5e989e95d.zip | |
new plugin "collapse" for collapsible lists and "accordion" like support
Diffstat (limited to 'js')
| -rw-r--r-- | js/bootstrap-collapse.js | 127 |
1 files changed, 127 insertions, 0 deletions
diff --git a/js/bootstrap-collapse.js b/js/bootstrap-collapse.js new file mode 100644 index 000000000..6de3d971a --- /dev/null +++ b/js/bootstrap-collapse.js @@ -0,0 +1,127 @@ +/* ============================================================= + * 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 )
\ No newline at end of file |
