Skip to content
This repository has been archived by the owner on Oct 8, 2021. It is now read-only.

Commit

Permalink
Added slight delay before application of hover/down classes on touch …
Browse files Browse the repository at this point in the history
…devices, to prevent unintentional hover-ish behavior when the user intent is to scroll.
  • Loading branch information
Wilto committed Dec 30, 2011
1 parent bb2a578 commit 171be28
Showing 1 changed file with 11 additions and 3 deletions.
14 changes: 11 additions & 3 deletions js/jquery.mobile.buttonMarkup.js
Expand Up @@ -128,6 +128,8 @@ function closestEnabledButton( element ) {
}

var attachEvents = function() {
var hoverDelay = 200,
hov, foc;
$( document ).bind( {
"vmousedown": function( event ) {
var btn = closestEnabledButton( event.target ),
Expand All @@ -136,7 +138,9 @@ var attachEvents = function() {
if ( btn ) {
$btn = $( btn );
theme = $btn.attr( "data-" + $.mobile.ns + "theme" );
$btn.removeClass( "ui-btn-up-" + theme ).addClass( "ui-btn-down-" + theme );
hov = setTimeout(function() {
$btn.removeClass( "ui-btn-up-" + theme ).addClass( "ui-btn-down-" + theme );
}, hoverDelay );
}
},
"vmousecancel vmouseup": function( event ) {
Expand All @@ -156,17 +160,21 @@ var attachEvents = function() {
if ( btn ) {
$btn = $( btn );
theme = $btn.attr( "data-" + $.mobile.ns + "theme" );
$btn.removeClass( "ui-btn-up-" + theme ).addClass( "ui-btn-hover-" + theme );
foc = setTimeout(function() {
$btn.removeClass( "ui-btn-up-" + theme ).addClass( "ui-btn-hover-" + theme );
}, hoverDelay );
}
},
"vmouseout blur scrollstart": function( event ) {
var btn = closestEnabledButton( event.target ),
$btn, theme;

if ( btn ) {
$btn = $( btn );
theme = $btn.attr( "data-" + $.mobile.ns + "theme" );
$btn.removeClass( "ui-btn-hover-" + theme + " ui-btn-down-" + theme ).addClass( "ui-btn-up-" + theme );

hov && clearTimeout( hov );
foc && clearTimeout( foc );
}
}
});
Expand Down

0 comments on commit 171be28

Please sign in to comment.