Skip to content

Commit 6179803

Browse files
Merge branch 'rbu-click-link'
2 parents d0d6df4 + b050f2f commit 6179803

File tree

3 files changed

+8
-4
lines changed

3 files changed

+8
-4
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ $('.navbar [data-toggle="dropdown"]').bootstrapDropdownHover({
6868

6969
When calling `bootstrapDropdownHover()` you can pass a parameters object with zero or more of the following:
7070

71-
- `clickBehavior`, `'sticky'`|`'default'`|`'disable'`, defaults to `sticky`, which means that if we click on an opened dropdown then it will not hide on mouseleave but on a second click only. Can be `default`, which means that means that the dropdown toggles on hover and on click too, or `disable`, which disables dropdown toggling with clicking when mouse is detected (so it will open on hover only)
71+
- `clickBehavior`, `'sticky'`|`'default'`|`'disable'`|`'link'`, defaults to `sticky`, which means that if we click on an opened dropdown then it will not hide on mouseleave but on a second click only. Can be `default`, which means that means that the dropdown toggles on hover and on click too, `disable`, which disables dropdown toggling with clicking when mouse is detected (so it will open on hover only) or `link` which is like `disable`, but does not prevent the default browser action (i.e. link clicks).
7272
- `hideTimeout`, integer, defaults to `200`, how much time the hovered dropdown hides after mouseleave (in milliseconds).
7373

7474
These settings can also be set via HTML5 data attributes on the element itself, e.g. this will

demo/index-bs3.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -498,7 +498,7 @@ <h2>Other dropdown type examples</h2>
498498

499499
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js"></script>
500500
<script src="//maxcdn.bootstrapcdn.com/bootstrap/3.3.5/js/bootstrap.min.js"></script>
501-
<script src="../src/jquery.bootstrap-dropdown-hover.js"></script>
501+
<script src="src/jquery.bootstrap-dropdown-hover.js"></script>
502502

503503
<script>
504504
//$('[data-toggle="dropdown"]').bootstrapDropdownHover();

src/jquery.bootstrap-dropdown-hover.js

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
clickBehavior: 'sticky', // Click behavior setting:
2424
// 'default' means that the dropdown toggles on hover and on click too
2525
// 'disable' disables dropdown toggling with clicking when mouse is detected
26+
// 'link' disabled dropdown toggling, but allows link clicks to go through
2627
// 'sticky' means if we click on an opened dropdown then it will not hide on
2728
// mouseleave but on a second click only
2829
hideTimeout: 200
@@ -88,7 +89,7 @@
8889
});
8990

9091
dropdown.element.on('click.dropdownhover', function (e) {
91-
if (!_mouseDetected) {
92+
if (dropdown.settings.clickBehavior !== 'link' && !_mouseDetected) {
9293
return;
9394
}
9495

@@ -98,7 +99,10 @@
9899
case 'disable':
99100
e.preventDefault();
100101
e.stopImmediatePropagation();
101-
break;
102+
return;
103+
case 'link':
104+
e.stopImmediatePropagation();
105+
return;
102106
case 'sticky':
103107
if (_hardOpened) {
104108
_hardOpened = false;

0 commit comments

Comments
 (0)