]> git.ipfire.org Git - thirdparty/bootstrap.git/commitdiff
don't open dropdown if target is disabled
authorJacob Thornton <jacobthornton@gmail.com>
Sun, 15 Apr 2012 04:44:57 +0000 (21:44 -0700)
committerJacob Thornton <jacobthornton@gmail.com>
Sun, 15 Apr 2012 04:44:57 +0000 (21:44 -0700)
js/bootstrap-dropdown.js
js/tests/unit/bootstrap-dropdown.js

index f27f4d2f437c4c24345cd2f93305a9d54f1fac26..411c2f7bfdb6753ef490268044780e601cfcf93c 100644 (file)
 
   , toggle: function (e) {
       var $this = $(this)
-        , selector = $this.attr('data-target')
+        , selector
         , $parent
         , isActive
 
+      if ($this.is('.disabled, :disabled')) return
+
+      selector = $this.attr('data-target')
+
       if (!selector) {
         selector = $this.attr('href')
         selector = selector && selector.replace(/.*(?=#[^\s]*$)/, '') //strip for ie7
index 368ced2a5ae70b0635437a6675d93b4fabda1987..4e52c8485e7156c8a722076e5208f74b1772149a 100644 (file)
@@ -10,6 +10,40 @@ $(function () {
         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 () {
         var dropdownHTML = '<ul class="tabs">'
           + '<li class="dropdown">'