mirror of
				https://github.com/twbs/bootstrap.git
				synced 2025-11-04 00:03:15 -05:00 
			
		
		
		
	Merge pull request #5309 from erlendfh/dropdown-bugfix
Fixed bug in dropdown toggle where menu would only clear on the first dropdown
This commit is contained in:
		
						commit
						d6ac499ca8
					
				
							
								
								
									
										5
									
								
								docs/assets/js/bootstrap-dropdown.js
									
									
									
									
										vendored
									
									
								
							
							
						
						
									
										5
									
								
								docs/assets/js/bootstrap-dropdown.js
									
									
									
									
										vendored
									
									
								
							@ -100,8 +100,9 @@
 | 
				
			|||||||
  }
 | 
					  }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  function clearMenus() { 
 | 
					  function clearMenus() { 
 | 
				
			||||||
    getParent($(toggle))
 | 
					    $(toggle).each(function () { 
 | 
				
			||||||
      .removeClass('open')
 | 
					      getParent($(this)).removeClass("open")
 | 
				
			||||||
 | 
					    })
 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  function getParent($this) {
 | 
					  function getParent($this) {
 | 
				
			||||||
 | 
				
			|||||||
							
								
								
									
										5
									
								
								docs/assets/js/bootstrap.js
									
									
									
									
										vendored
									
									
								
							
							
						
						
									
										5
									
								
								docs/assets/js/bootstrap.js
									
									
									
									
										vendored
									
									
								
							@ -677,8 +677,9 @@
 | 
				
			|||||||
  }
 | 
					  }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  function clearMenus() { 
 | 
					  function clearMenus() { 
 | 
				
			||||||
    getParent($(toggle))
 | 
					    $(toggle).each(function () { 
 | 
				
			||||||
      .removeClass('open')
 | 
					      getParent($(this)).removeClass("open")
 | 
				
			||||||
 | 
					    })
 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  function getParent($this) {
 | 
					  function getParent($this) {
 | 
				
			||||||
 | 
				
			|||||||
							
								
								
									
										5
									
								
								js/bootstrap-dropdown.js
									
									
									
									
										vendored
									
									
								
							
							
						
						
									
										5
									
								
								js/bootstrap-dropdown.js
									
									
									
									
										vendored
									
									
								
							@ -100,8 +100,9 @@
 | 
				
			|||||||
  }
 | 
					  }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  function clearMenus() { 
 | 
					  function clearMenus() { 
 | 
				
			||||||
    getParent($(toggle))
 | 
					    $(toggle).each(function () { 
 | 
				
			||||||
      .removeClass('open')
 | 
					      getParent($(this)).removeClass("open")
 | 
				
			||||||
 | 
					    })
 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  function getParent($this) {
 | 
					  function getParent($this) {
 | 
				
			||||||
 | 
				
			|||||||
							
								
								
									
										42
									
								
								js/tests/unit/bootstrap-dropdown.js
									
									
									
									
										vendored
									
									
								
							
							
						
						
									
										42
									
								
								js/tests/unit/bootstrap-dropdown.js
									
									
									
									
										vendored
									
									
								
							@ -7,7 +7,8 @@ $(function () {
 | 
				
			|||||||
      })
 | 
					      })
 | 
				
			||||||
 | 
					
 | 
				
			||||||
      test("should return element", 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 () {
 | 
					      test("should not open dropdown if target is disabled", function () {
 | 
				
			||||||
@ -102,4 +103,43 @@ $(function () {
 | 
				
			|||||||
        dropdown.remove()
 | 
					        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("")
 | 
				
			||||||
 | 
					      })
 | 
				
			||||||
 | 
					
 | 
				
			||||||
})
 | 
					})
 | 
				
			||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user