-
Notifications
You must be signed in to change notification settings - Fork 3
/
bootstrap4-dropdown-ml-hack-hover.js
48 lines (46 loc) · 1.73 KB
/
bootstrap4-dropdown-ml-hack-hover.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
$.fn.dropdown = (function() {
var $bsDropdown = $.fn.dropdown;
return function(config) {
if (typeof config === 'string' && config === 'toggle') { // dropdown toggle trigged
$('.has-child-dropdown-show').removeClass('has-child-dropdown-show');
$(this).closest('.dropdown').parents('.dropdown').addClass('has-child-dropdown-show');
}
var ret = $bsDropdown.call($(this), config);
$(this).off('click.bs.dropdown'); // Turn off dropdown.js click event, it will call 'this.toggle()' internal
return ret;
}
})();
$(function() {
$('.dropdown [data-toggle="dropdown"]').on('click', function(e) {
$(this).dropdown('toggle');
e.stopPropagation(); // do not fire dropdown.js click event, it will call 'this.toggle()' internal
});
$('.dropdown').on('hide.bs.dropdown', function(e) {
if ($(this).is('.has-child-dropdown-show')) {
$(this).removeClass('has-child-dropdown-show');
e.preventDefault();
}
e.stopPropagation(); // do not need pop in multi level mode
});
});
// for hover
$('.dropdown-hover').on('mouseenter',function() {
if(!$(this).hasClass('show')){
$('>[data-toggle="dropdown"]', this).dropdown('toggle');
}
});
$('.dropdown-hover').on('mouseleave',function() {
if($(this).hasClass('show')){
$('>[data-toggle="dropdown"]', this).dropdown('toggle');
}
});
$('.dropdown-hover-all').on('mouseenter', '.dropdown', function() {
if(!$(this).hasClass('show')){
$('>[data-toggle="dropdown"]', this).dropdown('toggle');
}
});
$('.dropdown-hover-all').on('mouseleave', '.dropdown', function() {
if($(this).hasClass('show')){
$('>[data-toggle="dropdown"]', this).dropdown('toggle');
}
});