diff --git a/docs/assets/js/bootstrap-dropdown.js b/docs/assets/js/bootstrap-dropdown.js index 0ef9b0f9d2..503fb7b3ac 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 d1672330ca..b539cd499d 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 0ef9b0f9d2..503fb7b3ac 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 = $("
") + 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 = + '' + + '
' + + ' ' + + ' ' + + ' ' + + '
' + , 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