Skip to content

Commit

Permalink
Merge branch 'redavis-master'
Browse files Browse the repository at this point in the history
Conflicts:
	bootstrap-hover-dropdown.js
  • Loading branch information
CWSpear committed Feb 7, 2015
2 parents 7d869e7 + 0be226b commit a5f547e
Showing 1 changed file with 22 additions and 9 deletions.
31 changes: 22 additions & 9 deletions bootstrap-hover-dropdown.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,18 +30,20 @@
$parent = $this.parent(),
defaults = {
delay: 500,
hoverDelay: 0,
instantlyCloseOthers: true
},
data = {
delay: $(this).data('delay'),
hoverDelay: $(this).data('hover-delay'),
instantlyCloseOthers: $(this).data('close-others')
},
showEvent = 'show.bs.dropdown',
hideEvent = 'hide.bs.dropdown',
// shownEvent = 'shown.bs.dropdown',
// hiddenEvent = 'hidden.bs.dropdown',
settings = $.extend(true, {}, defaults, options, data),
timeout;
timeout, timeoutHover;

$parent.hover(function (event) {
// so a neighbor can't open the dropdown
Expand All @@ -53,6 +55,8 @@

openDropdown(event);
}, function () {
// clear timer for hover event
window.clearTimeout(timeoutHover)
timeout = window.setTimeout(function () {
$this.attr('aria-expanded', 'false');
$parent.removeClass('open');
Expand Down Expand Up @@ -91,15 +95,24 @@
});

function openDropdown(event) {
$allDropdowns.find(':focus').blur();

if(settings.instantlyCloseOthers === true)
$allDropdowns.removeClass('open');

// clear dropdown timeout here so it doesnt close before it should
window.clearTimeout(timeout);
$this.attr('aria-expanded', 'true');
$parent.addClass('open');
$this.trigger(showEvent);
// restart hover timer
window.clearTimeout(timeoutHover);

// delay for hover event.
timeoutHover = window.setTimeout(function () {
$allDropdowns.find(':focus').blur();

if(settings.instantlyCloseOthers === true)
$allDropdowns.removeClass('open');

// clear timer for hover event
window.clearTimeout(timeoutHover);
$this.attr('aria-expanded', 'true');
$parent.addClass('open');
$this.trigger(showEvent);
}, settings.hoverDelay);
}
});
};
Expand Down

0 comments on commit a5f547e

Please sign in to comment.