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

Commit

Permalink
Navigation: Factor out calculation as to whether form submit will hap…
Browse files Browse the repository at this point in the history
…pen over AJAX
  • Loading branch information
Gabriel Schulhof committed Nov 27, 2012
1 parent 9f7cbfc commit e84cf61
Showing 1 changed file with 17 additions and 11 deletions.
28 changes: 17 additions & 11 deletions js/jquery.mobile.navigation.js
Expand Up @@ -1264,17 +1264,14 @@ define( [
//the following deferred is resolved in the init file
$.mobile.navreadyDeferred = $.Deferred();
$.mobile._registerInternalEvents = function() {
//bind to form submit events, handle with Ajax
$( document ).delegate( "form", "submit", function( event ) {
var $this = $( this );

var getAjaxFormData = function( $this ) {
if ( !$.mobile.ajaxEnabled ||
// test that the form is, itself, ajax false
$this.is( ":jqmData(ajax='false')" ) ||
// test that $.mobile.ignoreContentEnabled is set and
// the form or one of it's parents is ajax=false
!$this.jqmHijackable().length ) {
return;
return false;
}

var type = $this.attr( "method" ),
Expand All @@ -1301,20 +1298,29 @@ define( [
url = path.makeUrlAbsolute( url, getClosestBaseUrl( $this ) );

if ( ( path.isExternal( url ) && !path.isPermittedCrossDomainRequest( documentUrl, url ) ) || target ) {
return;
return false;
}

$.mobile.changePage(
url,
{
return {
url: url,
options: {
type: type && type.length && type.toLowerCase() || "get",
data: $this.serialize(),
transition: $this.jqmData( "transition" ),
reverse: $this.jqmData( "direction" ) === "reverse",
reloadPage: true
}
);
event.preventDefault();
};
};

//bind to form submit events, handle with Ajax
$( document ).delegate( "form", "submit", function( event ) {
var formData = getAjaxFormData( $( this ) );

if ( formData ) {
$.mobile.changePage( formData.url, formData.options );
event.preventDefault();
}
});

//add active state on vclick
Expand Down

0 comments on commit e84cf61

Please sign in to comment.