Skip to content

Commit

Permalink
Fixes #2
Browse files Browse the repository at this point in the history
  • Loading branch information
istvan-ujjmeszaros committed Jun 27, 2015
1 parent 5fa4809 commit dbd1452
Show file tree
Hide file tree
Showing 8 changed files with 36 additions and 27 deletions.
2 changes: 1 addition & 1 deletion bootstrap-dropdown-hover.jquery.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
"hover",
"ui"
],
"version": "1.0.3",
"version": "1.0.4",
"author": {
"name": "István Ujj-Mészáros",
"url": "https://github.com/istvan-ujjmeszaros"
Expand Down
2 changes: 1 addition & 1 deletion bower.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "bootstrap-dropdown-hover",
"version": "1.0.3",
"version": "1.0.4",
"homepage": "http://www.virtuosoft.eu/code/bootstrap-dropdown-hover/",
"authors": [
"István Ujj-Mészáros <[email protected]>"
Expand Down
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"keywords": ["bootstrap", "dropdown", "hover", "ui"],
"description": "Open dropdown menus on mouse hover, the proper way.",
"homepage": "http://www.virtuosoft.eu/code/bootstrap-dropdown-hover/",
"version": "1.0.3",
"version": "1.0.4",
"authors": [
{
"name": "István Ujj-Mészáros",
Expand Down
26 changes: 15 additions & 11 deletions dist/jquery.bootstrap-dropdown-hover.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Bootstrap Dropdown Hover - v1.0.3
* Bootstrap Dropdown Hover - v1.0.4
* Open dropdown menus on mouse hover, the proper way.
* http://www.virtuosoft.eu/code/bootstrap-dropdown-hover/
*
Expand All @@ -18,8 +18,8 @@
},
_hideTimeoutHandler,
_hardOpened = false,
_mouseDetected = false,
_mouseEnterDetected = false;
_touchstartDetected = false,
_mouseDetected = false;

// The actual plugin constructor
function BootstrapDropdownHover(element, options) {
Expand All @@ -31,19 +31,22 @@
}

function bindEvents(dropdown) {
// we do not want to modify behavior if mouse is not present (touch screens),
// so we rely on mousemove to detect the mouse
$('body').one('mousemove.dropdownhover', function () {
// some touch devices are firing the mousemove event on the body,
// but only after the mouseenter event happens on the dropdown toggle
if (!_mouseEnterDetected) {
$('body').one('touchstart.dropdownhover', function() {
_touchstartDetected = true;
});

$('body').one('mouseenter.dropdownhover', function() {
// touchstart fires before mouseenter on touch devices
if (!_touchstartDetected) {
_mouseDetected = true;
}
});

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

if (!_mouseDetected) {
return;
Expand Down Expand Up @@ -104,6 +107,7 @@
// seems that bootstrap binds the click handler twice after we reinitializing the plugin after a destroy...
$('.dropdown-toggle, .dropdown-menu', dropdown.element.parent()).off('.dropdown');
dropdown.element.off('.dropdownhover');
$('body').off('.dropdownhover');
}

BootstrapDropdownHover.prototype = {
Expand Down
4 changes: 2 additions & 2 deletions dist/jquery.bootstrap-dropdown-hover.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,7 @@ <h1>Bootstrap Dropdown Hover</h1>
</div>

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

<div class="alert alert-danger">The plugin instance is destroyed, please reinitialize!</div>
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
"url": "http://github.com/istvan-ujjmeszaros/bootstrap-dropdown-hover.git"
},
"homepage": "http://www.virtuosoft.eu/code/bootstrap-dropdown-hover/",
"version": "1.0.3",
"version": "1.0.4",
"devDependencies": {
"grunt": "~0.4.1",
"grunt-cli": "~0.1.13",
Expand Down
24 changes: 14 additions & 10 deletions src/jquery.bootstrap-dropdown-hover.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@
},
_hideTimeoutHandler,
_hardOpened = false,
_mouseDetected = false,
_mouseEnterDetected = false;
_touchstartDetected = false,
_mouseDetected = false;

// The actual plugin constructor
function BootstrapDropdownHover(element, options) {
Expand All @@ -23,19 +23,22 @@
}

function bindEvents(dropdown) {
// we do not want to modify behavior if mouse is not present (touch screens),
// so we rely on mousemove to detect the mouse
$('body').one('mousemove.dropdownhover', function () {
// some touch devices are firing the mousemove event on the body,
// but only after the mouseenter event happens on the dropdown toggle
if (!_mouseEnterDetected) {
$('body').one('touchstart.dropdownhover', function() {
_touchstartDetected = true;
});

$('body').one('mouseenter.dropdownhover', function() {
// touchstart fires before mouseenter on touch devices
if (!_touchstartDetected) {
_mouseDetected = true;
}
});

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

if (!_mouseDetected) {
return;
Expand Down Expand Up @@ -96,6 +99,7 @@
// seems that bootstrap binds the click handler twice after we reinitializing the plugin after a destroy...
$('.dropdown-toggle, .dropdown-menu', dropdown.element.parent()).off('.dropdown');
dropdown.element.off('.dropdownhover');
$('body').off('.dropdownhover');
}

BootstrapDropdownHover.prototype = {
Expand Down

0 comments on commit dbd1452

Please sign in to comment.