Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

fix bootstrap-button toggle regression + tests

  • Loading branch information...
commit 3d58b4622671bc51c22c857641db3b988e73632a 1 parent 7ec09d0
@fat fat authored
View
BIN  docs/assets/bootstrap.zip
Binary file not shown
View
4 docs/assets/js/bootstrap-button.js
@@ -91,7 +91,9 @@
$(function () {
$('body').on('click.button.data-api', '[data-toggle^=button]', function ( e ) {
- $(e.currentTarget).button('toggle')
+ var $btn = $(e.target)
+ if (!$btn.hasClass('btn')) $btn = $btn.closest('.btn')
+ $btn.button('toggle')
})
})
View
4 js/bootstrap-button.js
@@ -91,7 +91,9 @@
$(function () {
$('body').on('click.button.data-api', '[data-toggle^=button]', function ( e ) {
- $(e.currentTarget).button('toggle')
+ var $btn = $(e.target)
+ if (!$btn.hasClass('btn')) $btn = $btn.closest('.btn')
+ $btn.button('toggle')
})
})
View
25 js/tests/unit/bootstrap-button.js
@@ -45,10 +45,33 @@ $(function () {
})
test("should toggle active", function () {
- var btn = $('<button class="btn" data-loading-text="fat">mdo</button>')
+ var btn = $('<button class="btn">mdo</button>')
ok(!btn.hasClass('active'), 'btn does not have active class')
btn.button('toggle')
ok(btn.hasClass('active'), 'btn has class active')
})
+ test("should toggle active when btn children are clicked", function () {
+ var btn = $('<button class="btn" data-toggle="button">mdo</button>')
+ , inner = $('<i></i>')
+ btn
+ .append(inner)
+ .appendTo($('#qunit-fixture'))
+ ok(!btn.hasClass('active'), 'btn does not have active class')
+ inner.click()
+ ok(btn.hasClass('active'), 'btn has class active')
+ })
+
+ test("should toggle active when btn children are clicked within btn-group", function () {
+ var btngroup = $('<div class="btn-group" data-toggle="buttons-checkbox"></div>')
+ , btn = $('<button class="btn">fat</button>')
+ , inner = $('<i></i>')
+ btngroup
+ .append(btn.append(inner))
+ .appendTo($('#qunit-fixture'))
+ ok(!btn.hasClass('active'), 'btn does not have active class')
+ inner.click()
+ ok(btn.hasClass('active'), 'btn has class active')
+ })
+
})
Please sign in to comment.
Something went wrong with that request. Please try again.