Commit d65f7f20 authored by Jacob Thornton's avatar Jacob Thornton
Browse files

don't open dropdown if target is disabled

parent 82267d48
Showing with 39 additions and 1 deletion
+39 -1
...@@ -40,10 +40,14 @@ ...@@ -40,10 +40,14 @@
, toggle: function (e) { , toggle: function (e) {
var $this = $(this) var $this = $(this)
, selector = $this.attr('data-target') , selector
, $parent , $parent
, isActive , isActive
if ($this.is('.disabled, :disabled')) return
selector = $this.attr('data-target')
if (!selector) { if (!selector) {
selector = $this.attr('href') selector = $this.attr('href')
selector = selector && selector.replace(/.*(?=#[^\s]*$)/, '') //strip for ie7 selector = selector && selector.replace(/.*(?=#[^\s]*$)/, '') //strip for ie7
......
...@@ -10,6 +10,40 @@ $(function () { ...@@ -10,6 +10,40 @@ $(function () {
ok($(document.body).dropdown()[0] == document.body, 'document.body returned') ok($(document.body).dropdown()[0] == document.body, 'document.body returned')
}) })
test("should not open dropdown if target is disabled", function () {
var dropdownHTML = '<ul class="tabs">'
+ '<li class="dropdown">'
+ '<button disabled href="#" class="btn dropdown-toggle" data-toggle="dropdown">Dropdown</button>'
+ '<ul class="dropdown-menu">'
+ '<li><a href="#">Secondary link</a></li>'
+ '<li><a href="#">Something else here</a></li>'
+ '<li class="divider"></li>'
+ '<li><a href="#">Another link</a></li>'
+ '</ul>'
+ '</li>'
+ '</ul>'
, dropdown = $(dropdownHTML).find('[data-toggle="dropdown"]').dropdown().click()
ok(!dropdown.parent('.dropdown').hasClass('open'), 'open class added on click')
})
test("should not open dropdown if target is disabled", function () {
var dropdownHTML = '<ul class="tabs">'
+ '<li class="dropdown">'
+ '<button href="#" class="btn dropdown-toggle disabled" data-toggle="dropdown">Dropdown</button>'
+ '<ul class="dropdown-menu">'
+ '<li><a href="#">Secondary link</a></li>'
+ '<li><a href="#">Something else here</a></li>'
+ '<li class="divider"></li>'
+ '<li><a href="#">Another link</a></li>'
+ '</ul>'
+ '</li>'
+ '</ul>'
, dropdown = $(dropdownHTML).find('[data-toggle="dropdown"]').dropdown().click()
ok(!dropdown.parent('.dropdown').hasClass('open'), 'open class added on click')
})
test("should add class open to menu if clicked", function () { test("should add class open to menu if clicked", function () {
var dropdownHTML = '<ul class="tabs">' var dropdownHTML = '<ul class="tabs">'
+ '<li class="dropdown">' + '<li class="dropdown">'
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment