Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 20 additions & 8 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 () {
$parent.removeClass('open');
$this.trigger(hideEvent);
Expand Down Expand Up @@ -90,14 +94,22 @@
});

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);
$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);
$parent.addClass('open');
$this.trigger(showEvent);
}, settings.hoverDelay);
}
});
};
Expand Down