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

Commit e84cf61

Browse files
author
Gabriel Schulhof
committed
Navigation: Factor out calculation as to whether form submit will happen over AJAX
1 parent 9f7cbfc commit e84cf61

File tree

1 file changed

+17
-11
lines changed

1 file changed

+17
-11
lines changed

js/jquery.mobile.navigation.js

Lines changed: 17 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1264,17 +1264,14 @@ define( [
12641264
//the following deferred is resolved in the init file
12651265
$.mobile.navreadyDeferred = $.Deferred();
12661266
$.mobile._registerInternalEvents = function() {
1267-
//bind to form submit events, handle with Ajax
1268-
$( document ).delegate( "form", "submit", function( event ) {
1269-
var $this = $( this );
1270-
1267+
var getAjaxFormData = function( $this ) {
12711268
if ( !$.mobile.ajaxEnabled ||
12721269
// test that the form is, itself, ajax false
12731270
$this.is( ":jqmData(ajax='false')" ) ||
12741271
// test that $.mobile.ignoreContentEnabled is set and
12751272
// the form or one of it's parents is ajax=false
12761273
!$this.jqmHijackable().length ) {
1277-
return;
1274+
return false;
12781275
}
12791276

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

13031300
if ( ( path.isExternal( url ) && !path.isPermittedCrossDomainRequest( documentUrl, url ) ) || target ) {
1304-
return;
1301+
return false;
13051302
}
13061303

1307-
$.mobile.changePage(
1308-
url,
1309-
{
1304+
return {
1305+
url: url,
1306+
options: {
13101307
type: type && type.length && type.toLowerCase() || "get",
13111308
data: $this.serialize(),
13121309
transition: $this.jqmData( "transition" ),
13131310
reverse: $this.jqmData( "direction" ) === "reverse",
13141311
reloadPage: true
13151312
}
1316-
);
1317-
event.preventDefault();
1313+
};
1314+
};
1315+
1316+
//bind to form submit events, handle with Ajax
1317+
$( document ).delegate( "form", "submit", function( event ) {
1318+
var formData = getAjaxFormData( $( this ) );
1319+
1320+
if ( formData ) {
1321+
$.mobile.changePage( formData.url, formData.options );
1322+
event.preventDefault();
1323+
}
13181324
});
13191325

13201326
//add active state on vclick

0 commit comments

Comments
 (0)