@@ -1330,44 +1330,48 @@ define( [
13301330
13311331 //add active state on vclick
13321332 $ ( document ) . bind ( "vclick" , function ( event ) {
1333- var link , $link , $ btn, btnEls , $ target = $ ( event . target ) ;
1333+ var $ btn, btnEls , target = event . target , needClosest = false ;
13341334 // if this isn't a left click we don't care. Its important to note
13351335 // that when the virtual event is generated it will create the which attr
13361336 if ( event . which > 1 || ! $ . mobile . linkBindingEnabled ) {
13371337 return ;
13381338 }
13391339
1340- if ( $target . data ( "mobile-button" ) ) {
1341- if ( ! getAjaxFormData ( $target . closest ( "form" ) , true ) ) {
1340+ // Try to find a target element to which the active class will be applied
1341+ if ( $ . data ( target , "mobile-button" ) ) {
1342+ if ( ! getAjaxFormData ( $ ( target ) . closest ( "form" ) , true ) ) {
13421343 return ;
1343- } else {
1344- $target = $target . parent ( ) ;
13451344 }
1345+ // We will apply the active state to this button widget - the parent
1346+ // of the input that was clicked will have the associated data
1347+ target = target . parentNode ;
13461348 } else {
1347- link = findClosestLink ( event . target ) ;
1348- if ( ! ( link && path . parseUrl ( link . getAttribute ( "href" ) || "#" ) . hash !== "#" ) ) {
1349+ target = findClosestLink ( target ) ;
1350+ if ( ! ( target && path . parseUrl ( target . getAttribute ( "href" ) || "#" ) . hash !== "#" ) ) {
13491351 return ;
13501352 }
13511353
1352- $link = $ ( link ) ;
1353- // TODO teach $.mobile.hijackable to operate on raw dom elements so the link wrapping
1354- // can be avoided
1355- if ( ! $link . jqmHijackable ( ) . length ) {
1354+ // TODO teach $.mobile.hijackable to operate on raw dom elements so the
1355+ // link wrapping can be avoided
1356+ if ( ! $ ( target ) . jqmHijackable ( ) . length ) {
13561357 return ;
13571358 }
1358-
1359- $target = $link ;
13601359 }
13611360
1362- btnEls = $ . data ( $target [ 0 ] , "buttonElements" ) ;
1361+ // Avoid calling .closest by using the data set during .buttonMarkup()
1362+ btnEls = $ . data ( target , "buttonElements" ) ;
13631363 if ( btnEls ) {
1364- $ target = $ ( btnEls . outer ) ;
1364+ target = btnEls . outer ;
13651365 } else {
1366- $target = $target . closest ( ".ui-btn" ) ;
1366+ needClosest = true ;
13671367 }
13681368
1369- $btn = $target . not ( ".ui-disabled" ) ;
1370- if ( ! $btn . hasClass ( $ . mobile . activeBtnClass ) ) {
1369+ $btn = $ ( target ) ;
1370+ if ( needClosest ) {
1371+ $btn = $btn . closest ( ".ui-btn" ) ;
1372+ }
1373+ $btn = $btn . not ( ".ui-disabled" ) ;
1374+ if ( $btn . length > 0 && ! $btn . hasClass ( $ . mobile . activeBtnClass ) ) {
13711375 removeActiveLinkClass ( true ) ;
13721376 $activeClickedLink = $btn ;
13731377 $activeClickedLink . addClass ( $ . mobile . activeBtnClass ) ;
0 commit comments