Skip to content

Commit

Permalink
Always instantly close submenu siblings when opening a new one. Issue m…
Browse files Browse the repository at this point in the history
  • Loading branch information
CWSpear committed Jun 10, 2013
1 parent 0173edc commit 22357b6
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 13 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ This plugin purposedly lets you choose a selector (as opposed to apply this to e

I'm a slacker and only started keeping track of changes/bug fixes starting in March of 2013.

* **2013-06-10** Always instantly close submenu siblings when opening a new one. Issue #19.
* **2013-06-10** A fix for my last fix that would sometimes cause the correct item to not trigger when it should. Issue #18.
* **2013-05-08** Fix issue where a sibling could open a drop down that wasn't theirs. Issue #18.
* **2013-04-29** Added support for submenus: Submenus should now honor the delay option and way before closing. They do not abide by the `instantlyCloseOthers` option, as it's not really relevant.
Expand Down
16 changes: 15 additions & 1 deletion demo.html
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,21 @@

</ul>
</li>
<li><a tabindex="-1" href="#">Got Hover Dropdowns?</a></li>
<li class="dropdown-submenu">
<a tabindex="-1" href="#">Got Hover Dropdowns?</a>
<ul class="dropdown-menu">
<li><a tabindex="-1" href="#">Why Would</a></li>
<li><a tabindex="-1" href="#">A Home Tab</a></li>
<li><a tabindex="-1" href="#">Have Dropdowns?</a></li>
<li class="dropdown-submenu">
<a href="#">One More Time! <b class="caret"></b></a>
<ul class="dropdown-menu">
<li><a tabindex="-1" href="#">Menu Item 1</a></li>
<li><a tabindex="-1" href="#">Menu Item Blue</a></li>
</ul>
</li>
</ul>
</li>
</ul>
</li>
<li class="dropdown">
Expand Down
26 changes: 15 additions & 11 deletions twitter-bootstrap-hover-dropdown.js
Original file line number Diff line number Diff line change
Expand Up @@ -70,23 +70,27 @@
}
});

// handle submenus
$parent.find('.dropdown-submenu').each(function(){
var $this = $(this);
var subTimeout;
$(this).hover(function() {
$this.hover(function() {
if(shouldHover()) {
window.clearTimeout(subTimeout);
}
$(this).children('.dropdown-menu').show();
}, function() {
var $submenu = $(this).children('.dropdown-menu');
if(shouldHover()) {
subTimeout = window.setTimeout(function() {
$submenu.hide();
}, settings.delay);
} else {
// emulate Twitter Bootstrap's default behavior
$this.children('.dropdown-menu').show();
// always close submenu siblings instantly
$this.siblings().children('.dropdown-menu').hide();
}, function() {
var $submenu = $this.children('.dropdown-menu');
if(shouldHover()) {
subTimeout = window.setTimeout(function() {
$submenu.hide();
}
}, settings.delay);
} else {
// emulate Twitter Bootstrap's default behavior
$submenu.hide();
}
});
});
});
Expand Down
2 changes: 1 addition & 1 deletion twitter-bootstrap-hover-dropdown.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 22357b6

Please sign in to comment.