Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/twbs/bootstrap.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
path: root/js
diff options
context:
space:
mode:
authorJacob Thornton <jacobthornton@gmail.com>2012-02-19 11:29:58 +0400
committerJacob Thornton <jacobthornton@gmail.com>2012-02-19 11:29:58 +0400
commit3d58b4622671bc51c22c857641db3b988e73632a (patch)
treec2449b661858c5ab4846ad40f94648a1833033b6 /js
parent7ec09d0db9b1117d708682a08efaa55045e6926e (diff)
fix bootstrap-button toggle regression + tests
Diffstat (limited to 'js')
-rw-r--r--js/bootstrap-button.js4
-rw-r--r--js/tests/unit/bootstrap-button.js25
2 files changed, 27 insertions, 2 deletions
diff --git a/js/bootstrap-button.js b/js/bootstrap-button.js
index a0e0535475..0238ca3cb9 100644
--- a/js/bootstrap-button.js
+++ b/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')
})
})
diff --git a/js/tests/unit/bootstrap-button.js b/js/tests/unit/bootstrap-button.js
index 8aed857e11..03c4a8e9d5 100644
--- a/js/tests/unit/bootstrap-button.js
+++ b/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')
+ })
+
}) \ No newline at end of file