mirror of
https://github.com/twbs/bootstrap.git
synced 2025-02-19 16:54:24 +01:00
add collapsed class to collapse invoker when it's target is collapsed #3525
This commit is contained in:
parent
5e5965ca6f
commit
5b401a8c16
1
docs/assets/js/bootstrap-collapse.js
vendored
1
docs/assets/js/bootstrap-collapse.js
vendored
@ -150,6 +150,7 @@
|
||||
|| e.preventDefault()
|
||||
|| (href = $this.attr('href')) && href.replace(/.*(?=#[^\s]+$)/, '') //strip for ie7
|
||||
, option = $(target).data('collapse') ? 'toggle' : $this.data()
|
||||
$this[$(target).hasClass('in') ? 'removeClass' : 'addClass']('show')
|
||||
$(target).collapse(option)
|
||||
})
|
||||
})
|
||||
|
1
docs/assets/js/bootstrap.js
vendored
1
docs/assets/js/bootstrap.js
vendored
@ -562,6 +562,7 @@
|
||||
|| e.preventDefault()
|
||||
|| (href = $this.attr('href')) && href.replace(/.*(?=#[^\s]+$)/, '') //strip for ie7
|
||||
, option = $(target).data('collapse') ? 'toggle' : $this.data()
|
||||
$this[$(target).hasClass('in') ? 'removeClass' : 'addClass']('show')
|
||||
$(target).collapse(option)
|
||||
})
|
||||
})
|
||||
|
2
docs/assets/js/bootstrap.min.js
vendored
2
docs/assets/js/bootstrap.min.js
vendored
File diff suppressed because one or more lines are too long
3
js/bootstrap-collapse.js
vendored
3
js/bootstrap-collapse.js
vendored
@ -144,12 +144,13 @@
|
||||
* ==================== */
|
||||
|
||||
$(function () {
|
||||
$('body').on('click.collapse.data-api', '[data-toggle=collapse]', function ( e ) {
|
||||
$('body').on('click.collapse.data-api', '[data-toggle=collapse]', function (e) {
|
||||
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()
|
||||
$this[$(target).hasClass('in') ? 'addClass' : 'removeClass']('collapsed')
|
||||
$(target).collapse(option)
|
||||
})
|
||||
})
|
||||
|
38
js/tests/unit/bootstrap-collapse.js
vendored
38
js/tests/unit/bootstrap-collapse.js
vendored
@ -24,7 +24,7 @@ $(function () {
|
||||
|
||||
test("should not fire shown when show is prevented", function () {
|
||||
$.support.transition = false
|
||||
stop();
|
||||
stop()
|
||||
$('<div class="collapse"/>')
|
||||
.bind('show', function (e) {
|
||||
e.preventDefault();
|
||||
@ -39,7 +39,7 @@ $(function () {
|
||||
|
||||
test("should reset style to auto after finishing opening collapse", function () {
|
||||
$.support.transition = false
|
||||
stop();
|
||||
stop()
|
||||
$('<div class="collapse" style="height: 0px"/>')
|
||||
.bind('show', function () {
|
||||
ok(this.style.height == '0px')
|
||||
@ -51,4 +51,38 @@ $(function () {
|
||||
.collapse('show')
|
||||
})
|
||||
|
||||
test("should add active class to target when collapse shown", function () {
|
||||
$.support.transition = false
|
||||
stop()
|
||||
|
||||
var target = $('<a data-toggle="collapse" href="#test1"></a>')
|
||||
.appendTo($('#qunit-fixture'))
|
||||
|
||||
var collapsible = $('<div id="test1"></div>')
|
||||
.appendTo($('#qunit-fixture'))
|
||||
.on('show', function () {
|
||||
ok(!target.hasClass('collapsed'))
|
||||
start()
|
||||
})
|
||||
|
||||
target.click()
|
||||
})
|
||||
|
||||
test("should remove active class to target when collapse hidden", function () {
|
||||
$.support.transition = false
|
||||
stop()
|
||||
|
||||
var target = $('<a data-toggle="collapse" href="#test1"></a>')
|
||||
.appendTo($('#qunit-fixture'))
|
||||
|
||||
var collapsible = $('<div id="test1" class="in"></div>')
|
||||
.appendTo($('#qunit-fixture'))
|
||||
.on('hide', function () {
|
||||
ok(target.hasClass('collapsed'))
|
||||
start()
|
||||
})
|
||||
|
||||
target.click()
|
||||
})
|
||||
|
||||
})
|
Loading…
x
Reference in New Issue
Block a user