aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorErlend Halvorsen <[email protected]>2012-09-27 10:31:40 +0200
committerErlend Halvorsen <[email protected]>2012-09-27 10:31:40 +0200
commite9a648cd39dc6b5e0f126b7272adeac816ece758 (patch)
treedd1ef7ebb5cfc60619e30641d49c8f649827beff
parent0540b63ab0a2f9359fbd34967fbb74402534573f (diff)
downloadbootstrap-e9a648cd39dc6b5e0f126b7272adeac816ece758.tar.xz
bootstrap-e9a648cd39dc6b5e0f126b7272adeac816ece758.zip
Fixed bug in dropdown toggle where menu would only clear on the first drop down
-rw-r--r--docs/assets/js/bootstrap-dropdown.js7
-rw-r--r--docs/assets/js/bootstrap.js7
-rw-r--r--js/bootstrap-dropdown.js7
-rw-r--r--js/tests/unit/bootstrap-dropdown.js42
4 files changed, 53 insertions, 10 deletions
diff --git a/docs/assets/js/bootstrap-dropdown.js b/docs/assets/js/bootstrap-dropdown.js
index 0ef9b0f9d..503fb7b3a 100644
--- a/docs/assets/js/bootstrap-dropdown.js
+++ b/docs/assets/js/bootstrap-dropdown.js
@@ -99,9 +99,10 @@
}
- function clearMenus() {
- getParent($(toggle))
- .removeClass('open')
+ function clearMenus() {
+ $(toggle).each(function () {
+ getParent($(this)).removeClass("open")
+ })
}
function getParent($this) {
diff --git a/docs/assets/js/bootstrap.js b/docs/assets/js/bootstrap.js
index d1672330c..b539cd499 100644
--- a/docs/assets/js/bootstrap.js
+++ b/docs/assets/js/bootstrap.js
@@ -674,9 +674,10 @@
}
- function clearMenus() {
- getParent($(toggle))
- .removeClass('open')
+ function clearMenus() {
+ $(toggle).each(function () {
+ getParent($(this)).removeClass("open")
+ })
}
function getParent($this) {
diff --git a/js/bootstrap-dropdown.js b/js/bootstrap-dropdown.js
index 0ef9b0f9d..503fb7b3a 100644
--- a/js/bootstrap-dropdown.js
+++ b/js/bootstrap-dropdown.js
@@ -99,9 +99,10 @@
}
- function clearMenus() {
- getParent($(toggle))
- .removeClass('open')
+ function clearMenus() {
+ $(toggle).each(function () {
+ getParent($(this)).removeClass("open")
+ })
}
function getParent($this) {
diff --git a/js/tests/unit/bootstrap-dropdown.js b/js/tests/unit/bootstrap-dropdown.js
index 3a617692b..3788209ec 100644
--- a/js/tests/unit/bootstrap-dropdown.js
+++ b/js/tests/unit/bootstrap-dropdown.js
@@ -7,7 +7,8 @@ $(function () {
})
test("should return element", function () {
- ok($(document.body).dropdown()[0] == document.body, 'document.body returned')
+ var el = $("<div />")
+ ok(el.dropdown()[0] === el[0], 'same element returned')
})
test("should not open dropdown if target is disabled", function () {
@@ -102,4 +103,43 @@ $(function () {
dropdown.remove()
})
+ test("should remove open class if body clicked, with multiple drop downs", function () {
+ var dropdownHTML =
+ '<ul class="nav">'
+ + ' <li><a href="#menu1">Menu 1</a></li>'
+ + ' <li class="dropdown" id="testmenu">'
+ + ' <a class="dropdown-toggle" data-toggle="dropdown" href="#testmenu">Test menu <b class="caret"></b></a>'
+ + ' <ul class="dropdown-menu" role="menu">'
+ + ' <li><a href="#sub1">Submenu 1</a></li>'
+ + ' </ul>'
+ + ' </li>'
+ + '</ul>'
+ + '<div class="btn-group">'
+ + ' <button class="btn">Actions</button>'
+ + ' <button class="btn dropdown-toggle" data-toggle="dropdown"><span class="caret"></span></button>'
+ + ' <ul class="dropdown-menu">'
+ + ' <li><a href="#">Action 1</a></li>'
+ + ' </ul>'
+ + '</div>'
+ , dropdowns = $(dropdownHTML).appendTo('#qunit-fixture').find('[data-toggle="dropdown"]')
+ , first = dropdowns.first()
+ , last = dropdowns.last()
+
+ ok(dropdowns.length == 2, "Should be two dropdowns")
+
+ first.click()
+ ok(first.parents('.open').length == 1, 'open class added on click')
+ ok($('#qunit-fixture .open').length == 1, 'only one object is open')
+ $('body').click()
+ ok($("#qunit-fixture .open").length === 0, 'open class removed')
+
+ last.click()
+ ok(last.parent('.open').length == 1, 'open class added on click')
+ ok($('#qunit-fixture .open').length == 1, 'only one object is open')
+ $('body').click()
+ ok($("#qunit-fixture .open").length === 0, 'open class removed')
+
+ $("#qunit-fixture").html("")
+ })
+
}) \ No newline at end of file