Skip to content

Commit 0b9d4e7

Browse files
committed
Merge branch '2.1.2-wip' of github.com:twitter/bootstrap into 2.1.2-wip
2 parents 7f3b94c + d6ac499 commit 0b9d4e7

File tree

4 files changed

+53
-10
lines changed

4 files changed

+53
-10
lines changed

docs/assets/js/bootstrap-dropdown.js

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -99,9 +99,10 @@
9999

100100
}
101101

102-
function clearMenus() {
103-
getParent($(toggle))
104-
.removeClass('open')
102+
function clearMenus() {
103+
$(toggle).each(function () {
104+
getParent($(this)).removeClass("open")
105+
})
105106
}
106107

107108
function getParent($this) {

docs/assets/js/bootstrap.js

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -668,9 +668,10 @@
668668

669669
}
670670

671-
function clearMenus() {
672-
getParent($(toggle))
673-
.removeClass('open')
671+
function clearMenus() {
672+
$(toggle).each(function () {
673+
getParent($(this)).removeClass("open")
674+
})
674675
}
675676

676677
function getParent($this) {

js/bootstrap-dropdown.js

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -99,9 +99,10 @@
9999

100100
}
101101

102-
function clearMenus() {
103-
getParent($(toggle))
104-
.removeClass('open')
102+
function clearMenus() {
103+
$(toggle).each(function () {
104+
getParent($(this)).removeClass("open")
105+
})
105106
}
106107

107108
function getParent($this) {

js/tests/unit/bootstrap-dropdown.js

Lines changed: 41 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,8 @@ $(function () {
77
})
88

99
test("should return element", function () {
10-
ok($(document.body).dropdown()[0] == document.body, 'document.body returned')
10+
var el = $("<div />")
11+
ok(el.dropdown()[0] === el[0], 'same element returned')
1112
})
1213

1314
test("should not open dropdown if target is disabled", function () {
@@ -102,4 +103,43 @@ $(function () {
102103
dropdown.remove()
103104
})
104105

106+
test("should remove open class if body clicked, with multiple drop downs", function () {
107+
var dropdownHTML =
108+
'<ul class="nav">'
109+
+ ' <li><a href="#menu1">Menu 1</a></li>'
110+
+ ' <li class="dropdown" id="testmenu">'
111+
+ ' <a class="dropdown-toggle" data-toggle="dropdown" href="#testmenu">Test menu <b class="caret"></b></a>'
112+
+ ' <ul class="dropdown-menu" role="menu">'
113+
+ ' <li><a href="#sub1">Submenu 1</a></li>'
114+
+ ' </ul>'
115+
+ ' </li>'
116+
+ '</ul>'
117+
+ '<div class="btn-group">'
118+
+ ' <button class="btn">Actions</button>'
119+
+ ' <button class="btn dropdown-toggle" data-toggle="dropdown"><span class="caret"></span></button>'
120+
+ ' <ul class="dropdown-menu">'
121+
+ ' <li><a href="#">Action 1</a></li>'
122+
+ ' </ul>'
123+
+ '</div>'
124+
, dropdowns = $(dropdownHTML).appendTo('#qunit-fixture').find('[data-toggle="dropdown"]')
125+
, first = dropdowns.first()
126+
, last = dropdowns.last()
127+
128+
ok(dropdowns.length == 2, "Should be two dropdowns")
129+
130+
first.click()
131+
ok(first.parents('.open').length == 1, 'open class added on click')
132+
ok($('#qunit-fixture .open').length == 1, 'only one object is open')
133+
$('body').click()
134+
ok($("#qunit-fixture .open").length === 0, 'open class removed')
135+
136+
last.click()
137+
ok(last.parent('.open').length == 1, 'open class added on click')
138+
ok($('#qunit-fixture .open').length == 1, 'only one object is open')
139+
$('body').click()
140+
ok($("#qunit-fixture .open").length === 0, 'open class removed')
141+
142+
$("#qunit-fixture").html("")
143+
})
144+
105145
})

0 commit comments

Comments
 (0)