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

Commit b5ccb80

Browse files
author
Gabriel Schulhof
committed
Navigation: Add active class to submit button if form will be handled via AJAX. Addresses parts of #5009.
1 parent 53e1acd commit b5ccb80

File tree

1 file changed

+23
-13
lines changed

1 file changed

+23
-13
lines changed

js/jquery.mobile.navigation.js

Lines changed: 23 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1330,28 +1330,38 @@ define( [
13301330

13311331
//add active state on vclick
13321332
$( document ).bind( "vclick", function( event ) {
1333+
var link, $link, $btn, $target = $( event.target );
13331334
// if this isn't a left click we don't care. Its important to note
13341335
// that when the virtual event is generated it will create the which attr
13351336
if ( event.which > 1 || !$.mobile.linkBindingEnabled ) {
13361337
return;
13371338
}
13381339

1339-
var link = findClosestLink( event.target ), $btn;
1340+
if ( $target.data( "mobile-button" ) ) {
1341+
if ( !getAjaxFormData( $target.closest( "form" ), true ) ) {
1342+
return;
1343+
}
1344+
} else {
1345+
link = findClosestLink( event.target );
1346+
if ( !( link && path.parseUrl( link.getAttribute( "href" ) || "#" ).hash !== "#" ) ) {
1347+
return;
1348+
}
13401349

1341-
// split from the previous return logic to avoid find closest where possible
1342-
// TODO teach $.mobile.hijackable to operate on raw dom elements so the link wrapping
1343-
// can be avoided
1344-
if ( !$( link ).jqmHijackable().length ) {
1345-
return;
1350+
$link = $( link );
1351+
// TODO teach $.mobile.hijackable to operate on raw dom elements so the link wrapping
1352+
// can be avoided
1353+
if ( !$link.jqmHijackable().length ) {
1354+
return;
1355+
}
1356+
1357+
$target = $link;
13461358
}
13471359

1348-
if ( link ) {
1349-
$btn = $( link ).closest( ".ui-btn" ).not( ".ui-disabled" );
1350-
if ( path.parseUrl( link.getAttribute( "href" ) || "#" ).hash !== "#" && !$btn.hasClass( $.mobile.activeBtnClass ) ) {
1351-
removeActiveLinkClass( true );
1352-
$activeClickedLink = $btn;
1353-
$activeClickedLink.addClass( $.mobile.activeBtnClass );
1354-
}
1360+
$btn = $target.closest( ".ui-btn" ).not( ".ui-disabled" );
1361+
if ( !$btn.hasClass( $.mobile.activeBtnClass ) ) {
1362+
removeActiveLinkClass( true );
1363+
$activeClickedLink = $btn;
1364+
$activeClickedLink.addClass( $.mobile.activeBtnClass );
13551365
}
13561366
});
13571367

0 commit comments

Comments
 (0)