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-tab.js | 102 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 102 insertions(+) create mode 100644 js/bootstrap-tab.js (limited to 'js/bootstrap-tab.js') diff --git a/js/bootstrap-tab.js b/js/bootstrap-tab.js new file mode 100644 index 000000000..ba956cbe8 --- /dev/null +++ b/js/bootstrap-tab.js @@ -0,0 +1,102 @@ +/* ======================================================== + * bootstrap-tabs.js v2.0.0 + * http://twitter.github.com/bootstrap/javascript.html#tabs + * ======================================================== + * 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" + + /* TAB CLASS DEFINITION + * ==================== */ + + var Tab = function ( element ) { + this.element = $(element) + } + + Tab.prototype = { + + show: function () { + var $this = this.element + , $ul = $this.closest('ul:not(.dropdown-menu)') + , href = $this.attr('data-target') || $this.attr('href') + , previous + , $href + + if ( $this.parent('li').hasClass('active') ) return + + previous = $ul.find('.active a').last()[0] + + $this.trigger({ + type: 'show' + , relatedTarget: previous + }) + + $href = $(href) + + this.activate($this.parent('li'), $ul) + this.activate($href, $href.parent()) + + $this.trigger({ + type: 'shown' + , relatedTarget: previous + }) + } + + , activate: function ( element, container ) { + container + .find('> .active') + .removeClass('active') + .find('> .dropdown-menu > .active') + .removeClass('active') + + element.addClass('active') + + if ( element.parent('.dropdown-menu') ) { + element.closest('li.dropdown').addClass('active') + } + } + } + + + /* TAB PLUGIN DEFINITION + * ===================== */ + + $.fn.tab = function (option) { + return this.each(function () { + var $this = $(this) + , data = $this.data('tab') + if (!data) $this.data('tab', (data = new Tab(this))) + if (typeof option == 'string') data[option]() + }) + } + + $.fn.tab.Tab = Tab + + + /* TAB DATA-API + * ============ */ + + $(document).ready(function () { + $('body').delegate('[data-toggle="tab"], [data-toggle="pill"]', 'click.tab.data-api', function (e) { + e.preventDefault() + $(this).tab('show') + }) + }) + +}( window.jQuery || window.ender ) \ No newline at end of file -- 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-tab.js | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'js/bootstrap-tab.js') diff --git a/js/bootstrap-tab.js b/js/bootstrap-tab.js index ba956cbe8..6aa8ae32c 100644 --- a/js/bootstrap-tab.js +++ b/js/bootstrap-tab.js @@ -31,7 +31,9 @@ Tab.prototype = { - show: function () { + constructor: Tab + + , show: function () { var $this = this.element , $ul = $this.closest('ul:not(.dropdown-menu)') , href = $this.attr('data-target') || $this.attr('href') -- 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-tab.js | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'js/bootstrap-tab.js') diff --git a/js/bootstrap-tab.js b/js/bootstrap-tab.js index 6aa8ae32c..e0a92816d 100644 --- a/js/bootstrap-tab.js +++ b/js/bootstrap-tab.js @@ -79,7 +79,7 @@ /* TAB PLUGIN DEFINITION * ===================== */ - $.fn.tab = function (option) { + $.fn.tab = function ( option ) { return this.each(function () { var $this = $(this) , data = $this.data('tab') @@ -94,11 +94,11 @@ /* TAB DATA-API * ============ */ - $(document).ready(function () { - $('body').delegate('[data-toggle="tab"], [data-toggle="pill"]', 'click.tab.data-api', function (e) { + $(function () { + $('body').on('click.tab.data-api', '[data-toggle="tab"], [data-toggle="pill"]', function (e) { e.preventDefault() $(this).tab('show') }) }) -}( window.jQuery || window.ender ) \ No newline at end of file +}( window.jQuery ) \ No newline at end of file -- cgit v1.2.3 From 0980a33b4703677e1aaf3cd949c0437512fa6f33 Mon Sep 17 00:00:00 2001 From: Jacob Thornton Date: Tue, 20 Dec 2011 19:37:41 -0800 Subject: update all to new on api + add animation support to tabs --- js/bootstrap-tab.js | 47 +++++++++++++++++++++++++++++++++-------------- 1 file changed, 33 insertions(+), 14 deletions(-) (limited to 'js/bootstrap-tab.js') diff --git a/js/bootstrap-tab.js b/js/bootstrap-tab.js index e0a92816d..2f147c59d 100644 --- a/js/bootstrap-tab.js +++ b/js/bootstrap-tab.js @@ -52,26 +52,45 @@ $href = $(href) this.activate($this.parent('li'), $ul) - this.activate($href, $href.parent()) - - $this.trigger({ - type: 'shown' - , relatedTarget: previous + this.activate($href, $href.parent(), function () { + $this.trigger({ + type: 'shown' + , relatedTarget: previous + }) }) } - , activate: function ( element, container ) { - container - .find('> .active') - .removeClass('active') - .find('> .dropdown-menu > .active') - .removeClass('active') + , activate: function ( element, container, callback) { + var $active = container.find('> .active') + , transition = callback + && $.support.transition + && $active.hasClass('fade') + + function next() { + $active + .removeClass('active') + .find('> .dropdown-menu > .active') + .removeClass('active') - element.addClass('active') + element.addClass('active') - if ( element.parent('.dropdown-menu') ) { - element.closest('li.dropdown').addClass('active') + if (transition) { + element[0].offsetWidth // reflow for transition + element.addClass('in') + } + + if ( element.parent('.dropdown-menu') ) { + element.closest('li.dropdown').addClass('active') + } + + callback && callback() } + + transition ? + $active.one($.support.transition.end, next) : + next() + + $active.removeClass('in') } } -- 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-tab.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'js/bootstrap-tab.js') diff --git a/js/bootstrap-tab.js b/js/bootstrap-tab.js index 2f147c59d..c7632ded2 100644 --- a/js/bootstrap-tab.js +++ b/js/bootstrap-tab.js @@ -107,7 +107,7 @@ }) } - $.fn.tab.Tab = Tab + $.fn.tab.Constructor = Tab /* TAB DATA-API -- cgit v1.2.3 From fbd686ad655e1a22450f517e9ec241eaafc167f7 Mon Sep 17 00:00:00 2001 From: Jacob Thornton Date: Sun, 8 Jan 2012 12:08:00 -0800 Subject: get tabs working in ie9 --- js/bootstrap-tab.js | 2 ++ 1 file changed, 2 insertions(+) (limited to 'js/bootstrap-tab.js') diff --git a/js/bootstrap-tab.js b/js/bootstrap-tab.js index c7632ded2..8492fe955 100644 --- a/js/bootstrap-tab.js +++ b/js/bootstrap-tab.js @@ -77,6 +77,8 @@ if (transition) { element[0].offsetWidth // reflow for transition element.addClass('in') + } else { + element.removeClass('fade') } if ( element.parent('.dropdown-menu') ) { -- 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-tab.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'js/bootstrap-tab.js') diff --git a/js/bootstrap-tab.js b/js/bootstrap-tab.js index 8492fe955..e5b85e232 100644 --- a/js/bootstrap-tab.js +++ b/js/bootstrap-tab.js @@ -2,7 +2,7 @@ * bootstrap-tabs.js v2.0.0 * http://twitter.github.com/bootstrap/javascript.html#tabs * ======================================================== - * 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 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-tab.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'js/bootstrap-tab.js') diff --git a/js/bootstrap-tab.js b/js/bootstrap-tab.js index e5b85e232..d52be872f 100644 --- a/js/bootstrap-tab.js +++ b/js/bootstrap-tab.js @@ -1,5 +1,5 @@ /* ======================================================== - * bootstrap-tabs.js v2.0.0 + * bootstrap-tab.js v2.0.0 * http://twitter.github.com/bootstrap/javascript.html#tabs * ======================================================== * 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-tab.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'js/bootstrap-tab.js') diff --git a/js/bootstrap-tab.js b/js/bootstrap-tab.js index d52be872f..95698d23e 100644 --- a/js/bootstrap-tab.js +++ b/js/bootstrap-tab.js @@ -122,4 +122,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-tab.js | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) (limited to 'js/bootstrap-tab.js') diff --git a/js/bootstrap-tab.js b/js/bootstrap-tab.js index 95698d23e..f19db5da1 100644 --- a/js/bootstrap-tab.js +++ b/js/bootstrap-tab.js @@ -36,9 +36,14 @@ , show: function () { var $this = this.element , $ul = $this.closest('ul:not(.dropdown-menu)') - , href = $this.attr('data-target') || $this.attr('href') + , selector = $this.attr('data-target') , previous - , $href + , $target + + if (!selector) { + selector = $this.attr('href') + selector = selector && selector.replace(/.*(?=#[^\s]*$)/, '') //strip for ie7 + } if ( $this.parent('li').hasClass('active') ) return @@ -49,10 +54,10 @@ , relatedTarget: previous }) - $href = $(href) + $target = $(selector) this.activate($this.parent('li'), $ul) - this.activate($href, $href.parent(), function () { + this.activate($target, $target.parent(), function () { $this.trigger({ type: 'shown' , relatedTarget: previous -- cgit v1.2.3