From 41c782567775d3bbcfc62d163ae22a531277b5e2 Mon Sep 17 00:00:00 2001 From: Ivan Khalopik Date: Fri, 29 Mar 2013 17:55:14 +0300 Subject: [PATCH] Fixes #7213 Collapse plugin does not correctly set the "collapsed" class on accordion heading links --- js/bootstrap-collapse.js | 6 +++++ js/tests/unit/bootstrap-collapse.js | 35 +++++++++++++++++++++++++++++ 2 files changed, 41 insertions(+) diff --git a/js/bootstrap-collapse.js b/js/bootstrap-collapse.js index 2730a48d45..813462a24e 100644 --- a/js/bootstrap-collapse.js +++ b/js/bootstrap-collapse.js @@ -160,6 +160,12 @@ || e.preventDefault() || (href = $this.attr('href')) && href.replace(/.*(?=#[^\s]+$)/, '') //strip for ie7 , option = $(target).data('collapse') ? 'toggle' : $this.data() + , parent = $this.attr('data-parent') + , $parent = parent && $(parent) + + if ($parent) { + $parent.find('[data-toggle=collapse][data-parent=' + parent + ']').not($this).addClass('collapsed') + } $this[$(target).hasClass('in') ? 'addClass' : 'removeClass']('collapsed') $(target).collapse(option) }) diff --git a/js/tests/unit/bootstrap-collapse.js b/js/tests/unit/bootstrap-collapse.js index 4c5916ecd9..dbbf5dcf1f 100644 --- a/js/tests/unit/bootstrap-collapse.js +++ b/js/tests/unit/bootstrap-collapse.js @@ -91,4 +91,39 @@ $(function () { target.click() }) + test("should remove active class from inactive accordion targets", function () { + $.support.transition = false + stop() + + var accordion = $('
') + .appendTo($('#qunit-fixture')) + + var target1 = $('') + .appendTo(accordion.find('.accordion-group').eq(0)) + + var collapsible1 = $('
') + .appendTo(accordion.find('.accordion-group').eq(0)) + + var target2 = $('') + .appendTo(accordion.find('.accordion-group').eq(1)) + + var collapsible2 = $('
') + .appendTo(accordion.find('.accordion-group').eq(1)) + + var target3 = $('') + .appendTo(accordion.find('.accordion-group').eq(2)) + + var collapsible3 = $('
') + .appendTo(accordion.find('.accordion-group').eq(2)) + .on('show', function () { + ok(target1.hasClass('collapsed')) + ok(target2.hasClass('collapsed')) + ok(!target3.hasClass('collapsed')) + + start() + }) + + target3.click() + }) + }) \ No newline at end of file