From 98fddaa3557b1c872f1e585d579ec7e5e989e95d Mon Sep 17 00:00:00 2001 From: Jacob Thornton Date: Fri, 25 Nov 2011 17:23:14 -0800 Subject: new plugin "collapse" for collapsible lists and "accordion" like support --- js/bootstrap-collapse.js | 127 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 127 insertions(+) create mode 100644 js/bootstrap-collapse.js (limited to 'js/bootstrap-collapse.js') 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 -- cgit v1.2.3 From 46fe38386afce7149810b1feb534726735ce28b2 Mon Sep 17 00:00:00 2001 From: Jacob Thornton Date: Sun, 27 Nov 2011 17:04:55 -0800 Subject: rename tabs to tab - clean up lots of api stuff make href acceptable target val --- js/bootstrap-collapse.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'js/bootstrap-collapse.js') diff --git a/js/bootstrap-collapse.js b/js/bootstrap-collapse.js index 6de3d971a..629d9b589 100644 --- a/js/bootstrap-collapse.js +++ b/js/bootstrap-collapse.js @@ -117,9 +117,9 @@ $(function () { $('body').delegate('[data-toggle=collapse]', 'click.collapse.data-api', function ( e ) { var $this = $(this) - , target = $this.attr('data-target') + , target = $this.attr('data-target') || $this.attr('href') , option = $(target).data('collapse') ? 'toggle' : $this.data() - e.preventDefault() + e.preventDefault() $(target).collapse(option) }) }) -- cgit v1.2.3 From 7eb340ec589acd56ad960a020969822636c2bc54 Mon Sep 17 00:00:00 2001 From: Jacob Thornton Date: Sun, 27 Nov 2011 17:31:12 -0800 Subject: add code to reset data for collapsed element so that item can be intitialized with correct options --- js/bootstrap-collapse.js | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) (limited to 'js/bootstrap-collapse.js') diff --git a/js/bootstrap-collapse.js b/js/bootstrap-collapse.js index 629d9b589..93f91513e 100644 --- a/js/bootstrap-collapse.js +++ b/js/bootstrap-collapse.js @@ -42,8 +42,14 @@ , show: function () { var dimension = this.dimension() , scroll = $.camelCase(['scroll', dimension].join('-')) - - this.$parent && this.$parent.find('.in').collapse('hide') + , 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') -- cgit v1.2.3 From cee2f61898f4807311402fed747a93ee68a31f8f Mon Sep 17 00:00:00 2001 From: Jacob Thornton Date: Wed, 30 Nov 2011 22:42:22 -0800 Subject: define constructor on prototypes --- js/bootstrap-collapse.js | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'js/bootstrap-collapse.js') diff --git a/js/bootstrap-collapse.js b/js/bootstrap-collapse.js index 93f91513e..f56f6c705 100644 --- a/js/bootstrap-collapse.js +++ b/js/bootstrap-collapse.js @@ -34,7 +34,9 @@ Collapse.prototype = { - dimension: function () { + constructor: Collapse + + , dimension: function () { var hasWidth = this.$element.hasClass('width') return hasWidth ? 'width' : 'height' } -- cgit v1.2.3 From 1ef5fa7d6b4e50230c0c12919b0a06a9a2ac07f1 Mon Sep 17 00:00:00 2001 From: Jacob Thornton Date: Tue, 20 Dec 2011 18:02:47 -0800 Subject: giant refactor - all spec passing again... --- js/bootstrap-collapse.js | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) (limited to 'js/bootstrap-collapse.js') diff --git a/js/bootstrap-collapse.js b/js/bootstrap-collapse.js index f56f6c705..8eefd8863 100644 --- a/js/bootstrap-collapse.js +++ b/js/bootstrap-collapse.js @@ -23,13 +23,13 @@ var Collapse = function ( element, options ) { this.$element = $(element) - this.settings = $.extend({}, $.fn.collapse.defaults, options) + this.options = $.extend({}, $.fn.collapse.defaults, options) - if (this.settings["parent"]) { - this.$parent = $(this.settings["parent"]) + if (this.options["parent"]) { + this.$parent = $(this.options["parent"]) } - this.settings.toggle && this.toggle() + this.options.toggle && this.toggle() } Collapse.prototype = { @@ -123,13 +123,13 @@ * ==================== */ $(function () { - $('body').delegate('[data-toggle=collapse]', 'click.collapse.data-api', function ( e ) { + $('body').on('click.collapse.data-api', '[data-toggle=collapse]', function ( e ) { var $this = $(this) , target = $this.attr('data-target') || $this.attr('href') , option = $(target).data('collapse') ? 'toggle' : $this.data() - e.preventDefault() + e.preventDefault() $(target).collapse(option) }) }) -})( window.jQuery || window.ender ) \ No newline at end of file +})( window.jQuery ) \ No newline at end of file -- cgit v1.2.3 From f72a94ae2879ebfc5206dd40d5db175e13113850 Mon Sep 17 00:00:00 2001 From: Jacob Thornton Date: Tue, 20 Dec 2011 23:28:48 -0800 Subject: update more readme changes - introduce target specificty convention to more plugins --- js/bootstrap-collapse.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'js/bootstrap-collapse.js') diff --git a/js/bootstrap-collapse.js b/js/bootstrap-collapse.js index 8eefd8863..313c0abca 100644 --- a/js/bootstrap-collapse.js +++ b/js/bootstrap-collapse.js @@ -116,7 +116,7 @@ toggle: true } - $.fn.collapse.Collapse = Collapse + $.fn.collapse.Constructor = Collapse /* COLLAPSIBLE DATA-API -- cgit v1.2.3 From 6d5b5065176a9e46ce71ec5fc16ae4a079e9e636 Mon Sep 17 00:00:00 2001 From: Jacob Thornton Date: Wed, 21 Dec 2011 17:38:05 -0800 Subject: minor cleanups --- js/bootstrap-collapse.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'js/bootstrap-collapse.js') diff --git a/js/bootstrap-collapse.js b/js/bootstrap-collapse.js index 313c0abca..9301c7309 100644 --- a/js/bootstrap-collapse.js +++ b/js/bootstrap-collapse.js @@ -17,7 +17,7 @@ * limitations under the License. * ============================================================ */ -(function( $ ){ +!function( $ ){ "use strict" @@ -132,4 +132,4 @@ }) }) -})( window.jQuery ) \ No newline at end of file +}( window.jQuery ) \ No newline at end of file -- cgit v1.2.3 From 16eccc43d9fa6317818b5d1621d0477150214488 Mon Sep 17 00:00:00 2001 From: Mark Otto Date: Sat, 14 Jan 2012 23:28:48 -0800 Subject: dates updated to 2012 --- js/bootstrap-collapse.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'js/bootstrap-collapse.js') diff --git a/js/bootstrap-collapse.js b/js/bootstrap-collapse.js index 9301c7309..2521b7c7a 100644 --- a/js/bootstrap-collapse.js +++ b/js/bootstrap-collapse.js @@ -2,7 +2,7 @@ * bootstrap-collapsible.js v2.0.0 * http://twitter.github.com/bootstrap/javascript.html#collapsible * ============================================================= - * Copyright 2011 Twitter, Inc. + * Copyright 2012 Twitter, Inc. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. -- cgit v1.2.3 From 93c81522164421a03a9093502dae8125aa8b5584 Mon Sep 17 00:00:00 2001 From: Jacob Thornton Date: Fri, 20 Jan 2012 13:42:10 -0800 Subject: only prevent default if getting data-href --- js/bootstrap-collapse.js | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) (limited to 'js/bootstrap-collapse.js') diff --git a/js/bootstrap-collapse.js b/js/bootstrap-collapse.js index 2521b7c7a..9278f66d0 100644 --- a/js/bootstrap-collapse.js +++ b/js/bootstrap-collapse.js @@ -125,9 +125,8 @@ $(function () { $('body').on('click.collapse.data-api', '[data-toggle=collapse]', function ( e ) { var $this = $(this) - , target = $this.attr('data-target') || $this.attr('href') + , target = $this.attr('data-target') || e.preventDefault() || $this.attr('href') , option = $(target).data('collapse') ? 'toggle' : $this.data() - e.preventDefault() $(target).collapse(option) }) }) -- cgit v1.2.3 From 84a8aa1beac447cbbe77983730f7590fc955b312 Mon Sep 17 00:00:00 2001 From: Jon Stevens Date: Tue, 24 Jan 2012 11:08:03 -0800 Subject: 2.0-wip: fix js heads --- js/bootstrap-collapse.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'js/bootstrap-collapse.js') diff --git a/js/bootstrap-collapse.js b/js/bootstrap-collapse.js index 9278f66d0..ac434dcf3 100644 --- a/js/bootstrap-collapse.js +++ b/js/bootstrap-collapse.js @@ -1,6 +1,6 @@ /* ============================================================= - * bootstrap-collapsible.js v2.0.0 - * http://twitter.github.com/bootstrap/javascript.html#collapsible + * bootstrap-collapse.js v2.0.0 + * http://twitter.github.com/bootstrap/javascript.html#collapse * ============================================================= * Copyright 2012 Twitter, Inc. * -- cgit v1.2.3 From 5844aa550d5a2d22d527d80cfa42443914d28c1f Mon Sep 17 00:00:00 2001 From: Mark Otto Date: Thu, 26 Jan 2012 15:00:59 -0800 Subject: consistent new lines at ends of files --- js/bootstrap-collapse.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'js/bootstrap-collapse.js') diff --git a/js/bootstrap-collapse.js b/js/bootstrap-collapse.js index ac434dcf3..e33dadedf 100644 --- a/js/bootstrap-collapse.js +++ b/js/bootstrap-collapse.js @@ -131,4 +131,4 @@ }) }) -}( window.jQuery ) \ No newline at end of file +}( window.jQuery ) -- cgit v1.2.3 From e61164e67a048c20c512e99335e3adfcc3b63604 Mon Sep 17 00:00:00 2001 From: Jacob Thornton Date: Sat, 28 Jan 2012 01:35:13 -0800 Subject: all unit tests passing in ie7 --- js/bootstrap-collapse.js | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) (limited to 'js/bootstrap-collapse.js') diff --git a/js/bootstrap-collapse.js b/js/bootstrap-collapse.js index e33dadedf..ee36840d2 100644 --- a/js/bootstrap-collapse.js +++ b/js/bootstrap-collapse.js @@ -124,8 +124,10 @@ $(function () { $('body').on('click.collapse.data-api', '[data-toggle=collapse]', function ( e ) { - var $this = $(this) - , target = $this.attr('data-target') || e.preventDefault() || $this.attr('href') + var $this = $(this), href + , target = $this.attr('data-target') + || e.preventDefault() + || (href = $this.attr('href')) && href.replace(/.*(?=#[^\s]+$)/, '') //strip for ie7 , option = $(target).data('collapse') ? 'toggle' : $this.data() $(target).collapse(option) }) -- cgit v1.2.3 From f9b53d424e55bca4c7efe6220d36acafaee613cd Mon Sep 17 00:00:00 2001 From: Mark Reeder Date: Sun, 29 Jan 2012 21:14:07 -0800 Subject: Fixes issue with Opera flickering on the collapse plugin when reset is called without specifying the size https://github.com/twitter/bootstrap/issues/1208 --- js/bootstrap-collapse.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'js/bootstrap-collapse.js') diff --git a/js/bootstrap-collapse.js b/js/bootstrap-collapse.js index ee36840d2..8134cc42f 100644 --- a/js/bootstrap-collapse.js +++ b/js/bootstrap-collapse.js @@ -71,7 +71,7 @@ this.$element .removeClass('collapse') - [dimension](size || '') + [dimension](size || 'auto') [0].offsetWidth this.$element.addClass('collapse') -- cgit v1.2.3