Skip to content

Commit dbd1452

Browse files
Fixes #2
1 parent 5fa4809 commit dbd1452

8 files changed

+36
-27
lines changed

bootstrap-dropdown-hover.jquery.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
"hover",
99
"ui"
1010
],
11-
"version": "1.0.3",
11+
"version": "1.0.4",
1212
"author": {
1313
"name": "István Ujj-Mészáros",
1414
"url": "https://github.com/istvan-ujjmeszaros"

bower.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "bootstrap-dropdown-hover",
3-
"version": "1.0.3",
3+
"version": "1.0.4",
44
"homepage": "http://www.virtuosoft.eu/code/bootstrap-dropdown-hover/",
55
"authors": [
66
"István Ujj-Mészáros <[email protected]>"

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
"keywords": ["bootstrap", "dropdown", "hover", "ui"],
55
"description": "Open dropdown menus on mouse hover, the proper way.",
66
"homepage": "http://www.virtuosoft.eu/code/bootstrap-dropdown-hover/",
7-
"version": "1.0.3",
7+
"version": "1.0.4",
88
"authors": [
99
{
1010
"name": "István Ujj-Mészáros",

dist/jquery.bootstrap-dropdown-hover.js

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Bootstrap Dropdown Hover - v1.0.3
2+
* Bootstrap Dropdown Hover - v1.0.4
33
* Open dropdown menus on mouse hover, the proper way.
44
* http://www.virtuosoft.eu/code/bootstrap-dropdown-hover/
55
*
@@ -18,8 +18,8 @@
1818
},
1919
_hideTimeoutHandler,
2020
_hardOpened = false,
21-
_mouseDetected = false,
22-
_mouseEnterDetected = false;
21+
_touchstartDetected = false,
22+
_mouseDetected = false;
2323

2424
// The actual plugin constructor
2525
function BootstrapDropdownHover(element, options) {
@@ -31,19 +31,22 @@
3131
}
3232

3333
function bindEvents(dropdown) {
34-
// we do not want to modify behavior if mouse is not present (touch screens),
35-
// so we rely on mousemove to detect the mouse
36-
$('body').one('mousemove.dropdownhover', function () {
37-
// some touch devices are firing the mousemove event on the body,
38-
// but only after the mouseenter event happens on the dropdown toggle
39-
if (!_mouseEnterDetected) {
34+
$('body').one('touchstart.dropdownhover', function() {
35+
_touchstartDetected = true;
36+
});
37+
38+
$('body').one('mouseenter.dropdownhover', function() {
39+
// touchstart fires before mouseenter on touch devices
40+
if (!_touchstartDetected) {
4041
_mouseDetected = true;
4142
}
4243
});
4344

4445
$('.dropdown-toggle, .dropdown-menu', dropdown.element.parent()).on('mouseenter.dropdownhover', function () {
45-
// we need that for proper mouse detection
46-
_mouseEnterDetected = true;
46+
// seems to be a touch device
47+
if(_mouseDetected && !$(this).is(':hover')) {
48+
_mouseDetected = false;
49+
}
4750

4851
if (!_mouseDetected) {
4952
return;
@@ -104,6 +107,7 @@
104107
// seems that bootstrap binds the click handler twice after we reinitializing the plugin after a destroy...
105108
$('.dropdown-toggle, .dropdown-menu', dropdown.element.parent()).off('.dropdown');
106109
dropdown.element.off('.dropdownhover');
110+
$('body').off('.dropdownhover');
107111
}
108112

109113
BootstrapDropdownHover.prototype = {

dist/jquery.bootstrap-dropdown-hover.min.js

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

index.html

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,7 @@ <h1>Bootstrap Dropdown Hover</h1>
104104
</div>
105105

106106
<div class="col-xs-12 bs-example">
107+
<!--textarea id="log" style="display:block;height:200px;width:100%;"></textarea-->
107108
<p>Modify the behavior of the above two dropdowns</p>
108109

109110
<div class="alert alert-danger">The plugin instance is destroyed, please reinitialize!</div>

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
"url": "http://github.com/istvan-ujjmeszaros/bootstrap-dropdown-hover.git"
1010
},
1111
"homepage": "http://www.virtuosoft.eu/code/bootstrap-dropdown-hover/",
12-
"version": "1.0.3",
12+
"version": "1.0.4",
1313
"devDependencies": {
1414
"grunt": "~0.4.1",
1515
"grunt-cli": "~0.1.13",

src/jquery.bootstrap-dropdown-hover.js

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@
1010
},
1111
_hideTimeoutHandler,
1212
_hardOpened = false,
13-
_mouseDetected = false,
14-
_mouseEnterDetected = false;
13+
_touchstartDetected = false,
14+
_mouseDetected = false;
1515

1616
// The actual plugin constructor
1717
function BootstrapDropdownHover(element, options) {
@@ -23,19 +23,22 @@
2323
}
2424

2525
function bindEvents(dropdown) {
26-
// we do not want to modify behavior if mouse is not present (touch screens),
27-
// so we rely on mousemove to detect the mouse
28-
$('body').one('mousemove.dropdownhover', function () {
29-
// some touch devices are firing the mousemove event on the body,
30-
// but only after the mouseenter event happens on the dropdown toggle
31-
if (!_mouseEnterDetected) {
26+
$('body').one('touchstart.dropdownhover', function() {
27+
_touchstartDetected = true;
28+
});
29+
30+
$('body').one('mouseenter.dropdownhover', function() {
31+
// touchstart fires before mouseenter on touch devices
32+
if (!_touchstartDetected) {
3233
_mouseDetected = true;
3334
}
3435
});
3536

3637
$('.dropdown-toggle, .dropdown-menu', dropdown.element.parent()).on('mouseenter.dropdownhover', function () {
37-
// we need that for proper mouse detection
38-
_mouseEnterDetected = true;
38+
// seems to be a touch device
39+
if(_mouseDetected && !$(this).is(':hover')) {
40+
_mouseDetected = false;
41+
}
3942

4043
if (!_mouseDetected) {
4144
return;
@@ -96,6 +99,7 @@
9699
// seems that bootstrap binds the click handler twice after we reinitializing the plugin after a destroy...
97100
$('.dropdown-toggle, .dropdown-menu', dropdown.element.parent()).off('.dropdown');
98101
dropdown.element.off('.dropdownhover');
102+
$('body').off('.dropdownhover');
99103
}
100104

101105
BootstrapDropdownHover.prototype = {

0 commit comments

Comments
 (0)