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-08-28 07:58:51 +0400
committerJacob Thornton <jacobthornton@gmail.com>2012-08-28 07:58:51 +0400
commit601e252074eedf89de9cb080db9c463a4b67ba77 (patch)
treee3f72cb04af090b69bcc090c0d14b64e8ef2c0cc /js
parentd797a5fbd7dd883a09bf00e516e0bd509c898f53 (diff)
fix for #4761
Diffstat (limited to 'js')
-rw-r--r--js/bootstrap-button.js2
-rw-r--r--js/tests/unit/bootstrap-button.js21
2 files changed, 21 insertions, 2 deletions
diff --git a/js/bootstrap-button.js b/js/bootstrap-button.js
index 702198f6d0..a0ab0bfad5 100644
--- a/js/bootstrap-button.js
+++ b/js/bootstrap-button.js
@@ -51,7 +51,7 @@
}
Button.prototype.toggle = function () {
- var $parent = this.$element.parent('[data-toggle="buttons-radio"]')
+ var $parent = this.$element.closest('[data-toggle="buttons-radio"]')
$parent && $parent
.find('.active')
diff --git a/js/tests/unit/bootstrap-button.js b/js/tests/unit/bootstrap-button.js
index 03c4a8e9d5..b5d0834999 100644
--- a/js/tests/unit/bootstrap-button.js
+++ b/js/tests/unit/bootstrap-button.js
@@ -62,7 +62,7 @@ $(function () {
ok(btn.hasClass('active'), 'btn has class active')
})
- test("should toggle active when btn children are clicked within btn-group", function () {
+ 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>')
@@ -74,4 +74,23 @@ $(function () {
ok(btn.hasClass('active'), 'btn has class active')
})
+ test("should check for closest matching toggle", function () {
+ var group = $("<div data-toggle='buttons-radio'></div>")
+ , btn1 = $("<button class='btn active'></button>")
+ , btn2 = $("<button class='btn'></button>")
+ , wrap = $("<div></div>")
+
+ wrap.append(btn1, btn2)
+
+ group
+ .append(wrap)
+ .appendTo($('#qunit-fixture'))
+
+ ok(btn1.hasClass('active'), 'btn1 has active class')
+ ok(!btn2.hasClass('active'), 'btn2 does not have active class')
+ btn2.click()
+ ok(!btn1.hasClass('active'), 'btn1 does not have active class')
+ ok(btn2.hasClass('active'), 'btn2 has active class')
+ })
+
}) \ No newline at end of file