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-10-18 10:06:58 +0400
committerJacob Thornton <jacobthornton@gmail.com>2012-10-18 10:06:58 +0400
commit0b9d4e78ad5e5ad2f6f34735f0ac73463e1d1af9 (patch)
tree315c0473dccbc3db2df3b4d85f3b27af3e2ec050 /js
parent7f3b94c45315475a129ace3c22e122808c2dbcaa (diff)
parentd6ac499ca85606d8ce0294d2be3526700605c368 (diff)
Merge branch '2.1.2-wip' of github.com:twitter/bootstrap into 2.1.2-wip
Diffstat (limited to 'js')
-rw-r--r--js/bootstrap-dropdown.js7
-rw-r--r--js/tests/unit/bootstrap-dropdown.js42
2 files changed, 45 insertions, 4 deletions
diff --git a/js/bootstrap-dropdown.js b/js/bootstrap-dropdown.js
index f50aa64d62..4f99e04ffa 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 3a617692b3..3788209ecc 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