Skip to content
This repository
Browse code

Added slight delay before application of hover/down classes on touch …

…devices, to prevent unintentional hover-ish behavior when the user intent is to scroll.
  • Loading branch information...
commit 171be28a220d8204e4e244d7ba5fa9f4ce42d16b 1 parent bb2a578
Mat Marquis authored

Showing 1 changed file with 11 additions and 3 deletions. Show diff stats Hide diff stats

  1. 14  js/jquery.mobile.buttonMarkup.js
14  js/jquery.mobile.buttonMarkup.js
@@ -128,6 +128,8 @@ function closestEnabledButton( element ) {
128 128
 }
129 129
 
130 130
 var attachEvents = function() {
  131
+	var hoverDelay = 200,
  132
+		hov, foc;
131 133
 	$( document ).bind( {
132 134
 		"vmousedown": function( event ) {
133 135
 			var btn = closestEnabledButton( event.target ),
@@ -136,7 +138,9 @@ var attachEvents = function() {
136 138
 			if ( btn ) {
137 139
 				$btn = $( btn );
138 140
 				theme = $btn.attr( "data-" + $.mobile.ns + "theme" );
139  
-				$btn.removeClass( "ui-btn-up-" + theme ).addClass( "ui-btn-down-" + theme );
  141
+				hov = setTimeout(function() {
  142
+					$btn.removeClass( "ui-btn-up-" + theme ).addClass( "ui-btn-down-" + theme );
  143
+				}, hoverDelay );
140 144
 			}
141 145
 		},
142 146
 		"vmousecancel vmouseup": function( event ) {
@@ -156,17 +160,21 @@ var attachEvents = function() {
156 160
 			if ( btn ) {
157 161
 				$btn = $( btn );
158 162
 				theme = $btn.attr( "data-" + $.mobile.ns + "theme" );
159  
-				$btn.removeClass( "ui-btn-up-" + theme ).addClass( "ui-btn-hover-" + theme );
  163
+				foc = setTimeout(function() {
  164
+					$btn.removeClass( "ui-btn-up-" + theme ).addClass( "ui-btn-hover-" + theme );
  165
+				}, hoverDelay );
160 166
 			}
161 167
 		},
162 168
 		"vmouseout blur scrollstart": function( event ) {
163 169
 			var btn = closestEnabledButton( event.target ),
164 170
 				$btn, theme;
165  
-
166 171
 			if ( btn ) {
167 172
 				$btn = $( btn );
168 173
 				theme = $btn.attr( "data-" + $.mobile.ns + "theme" );
169 174
 				$btn.removeClass( "ui-btn-hover-" + theme  + " ui-btn-down-" + theme ).addClass( "ui-btn-up-" + theme );
  175
+				
  176
+				hov && clearTimeout( hov );
  177
+				foc && clearTimeout( foc );
170 178
 			}
171 179
 		}
172 180
 	});

0 notes on commit 171be28

Please sign in to comment.
Something went wrong with that request. Please try again.