Skip to content

Commit 3d40968

Browse files
committed
DRY up buttonMarkup a bit and save a variable in the process
1 parent ff80fae commit 3d40968

File tree

1 file changed

+31
-51
lines changed

1 file changed

+31
-51
lines changed

js/jquery.mobile.buttonMarkup.js

Lines changed: 31 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -175,61 +175,41 @@ var attachEvents = function() {
175175
var hoverDelay = 200,
176176
hov, foc;
177177
$( document ).bind( {
178-
"vmousedown": function( event ) {
179-
var btn = closestEnabledButton( event.target ),
180-
$btn, theme;
181-
182-
if ( btn ) {
183-
$btn = $( btn );
178+
"vmousedown vmousecancel vmouseup vmouseover vmouseout focus blur scrollstart": function( event ) {
179+
var $btn = $( closestEnabledButton( event.target ) ),
180+
theme;
181+
182+
if ( $btn.length ) {
184183
theme = $btn.attr( "data-" + $.mobile.ns + "theme" );
185-
186-
if( $.support.touch ) {
187-
hov = setTimeout(function() {
184+
185+
if ( event.type === "vmousedown" ) {
186+
if ( $.support.touch ) {
187+
hov = setTimeout(function() {
188+
$btn.removeClass( "ui-btn-up-" + theme ).addClass( "ui-btn-down-" + theme );
189+
}, hoverDelay );
190+
}
191+
else {
188192
$btn.removeClass( "ui-btn-up-" + theme ).addClass( "ui-btn-down-" + theme );
189-
}, hoverDelay );
190-
} else {
191-
$btn.removeClass( "ui-btn-up-" + theme ).addClass( "ui-btn-down-" + theme );
193+
}
192194
}
193-
}
194-
},
195-
"vmousecancel vmouseup": function( event ) {
196-
var btn = closestEnabledButton( event.target ),
197-
$btn, theme;
198-
199-
if ( btn ) {
200-
$btn = $( btn );
201-
theme = $btn.attr( "data-" + $.mobile.ns + "theme" );
202-
$btn.removeClass( "ui-btn-down-" + theme ).addClass( "ui-btn-up-" + theme );
203-
}
204-
},
205-
"vmouseover focus": function( event ) {
206-
var btn = closestEnabledButton( event.target ),
207-
$btn, theme;
208-
209-
if ( btn ) {
210-
$btn = $( btn );
211-
theme = $btn.attr( "data-" + $.mobile.ns + "theme" );
212-
213-
if( $.support.touch ) {
214-
foc = setTimeout(function() {
195+
else if ( event.type === "vmousecancel" || event.type === "vmouseup" ) {
196+
$btn.removeClass( "ui-btn-down-" + theme ).addClass( "ui-btn-up-" + theme );
197+
}
198+
else if ( event.type === "vmouseover" || event.type === "focus" ) {
199+
if ( $.support.touch ) {
200+
foc = setTimeout(function() {
201+
$btn.removeClass( "ui-btn-up-" + theme ).addClass( "ui-btn-hover-" + theme );
202+
}, hoverDelay );
203+
}
204+
else {
215205
$btn.removeClass( "ui-btn-up-" + theme ).addClass( "ui-btn-hover-" + theme );
216-
}, hoverDelay );
217-
} else {
218-
$btn.removeClass( "ui-btn-up-" + theme ).addClass( "ui-btn-hover-" + theme );
206+
}
207+
}
208+
else if ( event.type === "vmouseout" || event.type === "blur" || event.type === "scrollstart" ) {
209+
$btn.removeClass( "ui-btn-hover-" + theme + " ui-btn-down-" + theme ).addClass( "ui-btn-up-" + theme );
210+
hov && clearTimeout( hov );
211+
foc && clearTimeout( foc );
219212
}
220-
}
221-
},
222-
"vmouseout blur scrollstart": function( event ) {
223-
var btn = closestEnabledButton( event.target ),
224-
$btn, theme;
225-
226-
if ( btn ) {
227-
$btn = $( btn );
228-
theme = $btn.attr( "data-" + $.mobile.ns + "theme" );
229-
$btn.removeClass( "ui-btn-hover-" + theme + " ui-btn-down-" + theme ).addClass( "ui-btn-up-" + theme );
230-
231-
hov && clearTimeout( hov );
232-
foc && clearTimeout( foc );
233213
}
234214
},
235215
"focusin focus": function( event ){
@@ -256,4 +236,4 @@ $( document ).bind( "pagecreate create", function( e ){
256236

257237
//>>excludeStart("jqmBuildExclude", pragmas.jqmBuildExclude);
258238
});
259-
//>>excludeEnd("jqmBuildExclude");
239+
//>>excludeEnd("jqmBuildExclude");

0 commit comments

Comments
 (0)