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

Commit

Permalink
Navigation: Add active class to submit button if form will be handled…
Browse files Browse the repository at this point in the history
… via AJAX. Addresses parts of #5009.
  • Loading branch information
Gabriel Schulhof committed Nov 27, 2012
1 parent 53e1acd commit b5ccb80
Showing 1 changed file with 23 additions and 13 deletions.
36 changes: 23 additions & 13 deletions js/jquery.mobile.navigation.js
Expand Up @@ -1330,28 +1330,38 @@ define( [

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

var link = findClosestLink( event.target ), $btn;
if ( $target.data( "mobile-button" ) ) {
if ( !getAjaxFormData( $target.closest( "form" ), true ) ) {
return;
}
} else {
link = findClosestLink( event.target );
if ( !( link && path.parseUrl( link.getAttribute( "href" ) || "#" ).hash !== "#" ) ) {
return;
}

// split from the previous return logic to avoid find closest where possible
// TODO teach $.mobile.hijackable to operate on raw dom elements so the link wrapping
// can be avoided
if ( !$( link ).jqmHijackable().length ) {
return;
$link = $( link );
// TODO teach $.mobile.hijackable to operate on raw dom elements so the link wrapping
// can be avoided
if ( !$link.jqmHijackable().length ) {
return;
}

$target = $link;
}

if ( link ) {
$btn = $( link ).closest( ".ui-btn" ).not( ".ui-disabled" );
if ( path.parseUrl( link.getAttribute( "href" ) || "#" ).hash !== "#" && !$btn.hasClass( $.mobile.activeBtnClass ) ) {
removeActiveLinkClass( true );
$activeClickedLink = $btn;
$activeClickedLink.addClass( $.mobile.activeBtnClass );
}
$btn = $target.closest( ".ui-btn" ).not( ".ui-disabled" );
if ( !$btn.hasClass( $.mobile.activeBtnClass ) ) {
removeActiveLinkClass( true );
$activeClickedLink = $btn;
$activeClickedLink.addClass( $.mobile.activeBtnClass );
}
});

Expand Down

0 comments on commit b5ccb80

Please sign in to comment.