From 2e6a396278f6dfdab4cabf0e495868b66af86dbb Mon Sep 17 00:00:00 2001 From: scottjehl Date: Sun, 23 Jan 2011 19:03:35 -0500 Subject: [PATCH] added ajaxEnabled option. ajaxLinksEnabled and ajaxFormsEnabled are deprecated and will be removed by 1.0. Fixes #851 --- docs/api/globalconfig.html | 7 +++++-- js/jquery.mobile.core.js | 13 +++++++++---- js/jquery.mobile.navigation.js | 17 ++++++++++++----- 3 files changed, 26 insertions(+), 11 deletions(-) diff --git a/docs/api/globalconfig.html b/docs/api/globalconfig.html index b06800a5..361f8feb 100755 --- a/docs/api/globalconfig.html +++ b/docs/api/globalconfig.html @@ -80,11 +80,14 @@ $(document).bind("mobileinit", function(){
activeBtnClass (string, default: "ui-page-active"):
The class used for "active" button state, from CSS framework.
+ +
ajaxEnabled (boolean, default: true):
+
jQuery Mobile will automatically handle link clicks and form submissions through Ajax, when possible. If false, url hash listening will be disabled as well, and urls will load as regular http requests.
-
ajaxLinksEnabled (boolean, default: true):
+
ajaxLinksEnabled (deprecated boolean, default: true):
jQuery Mobile will automatically handle link clicks through Ajax, when possible.
-
ajaxFormsEnabled (boolean, default: true):
+
ajaxFormsEnabled (deprecated boolean, default: true):
jQuery Mobile will automatically handle form submissions through Ajax, when possible.
defaultTransition (string, default: 'slide'):
diff --git a/js/jquery.mobile.core.js b/js/jquery.mobile.core.js index 012be648..1e4a20b1 100644 --- a/js/jquery.mobile.core.js +++ b/js/jquery.mobile.core.js @@ -27,11 +27,16 @@ //class used for "active" button state, from CSS framework activeBtnClass: 'ui-btn-active', - //automatically handle link clicks through Ajax, when possible - ajaxLinksEnabled: true, + //automatically handle clicks and form submissions through Ajax, when same-domain + ajaxEnabled: true, + + // TODO: deprecated - remove at 1.0 + //automatically handle link clicks through Ajax, when possible + ajaxLinksEnabled: true, - //automatically handle form submissions through Ajax, when possible - ajaxFormsEnabled: true, + // TODO: deprecated - remove at 1.0 + //automatically handle form submissions through Ajax, when possible + ajaxFormsEnabled: true, //set default transition - 'none' for no transitions defaultTransition: 'slide', diff --git a/js/jquery.mobile.navigation.js b/js/jquery.mobile.navigation.js index c272bab6..7aba0a42 100644 --- a/js/jquery.mobile.navigation.js +++ b/js/jquery.mobile.navigation.js @@ -219,7 +219,7 @@ /* exposed $.mobile methods */ //update location.hash, with or without triggering hashchange event - //TODO - deprecate this one + //TODO - deprecate this one at 1.0 $.mobile.updateHash = path.set; //expose path object on $.mobile @@ -229,7 +229,7 @@ $.mobile.base = base; //url stack, useful when plugins need to be aware of previous pages viewed - //TODO: deprecate this one + //TODO: deprecate this one at 1.0 $.mobile.urlstack = urlHistory.stack; //history stack @@ -509,7 +509,9 @@ //bind to form submit events, handle with Ajax $( "form[data-ajax!='false']" ).live('submit', function(event){ - if( !$.mobile.ajaxFormsEnabled ){ return; } + if( !$.mobile.ajaxEnabled || + //TODO: deprecated - remove at 1.0 + !$.mobile.ajaxFormsEnabled ){ return; } var type = $(this).attr("method"), url = path.clean( $(this).attr( "action" ) ); @@ -558,7 +560,9 @@ $activeClickedLink = $this.closest( ".ui-btn" ).addClass( $.mobile.activeBtnClass ); - if( isExternal || hasTarget || !$.mobile.ajaxLinksEnabled ){ + if( isExternal || hasTarget || !$.mobile.ajaxEnabled || + // TODO: deprecated - remove at 1.0 + !$.mobile.ajaxLinksEnabled ){ //remove active link class if external (then it won't be there if you come back) removeActiveLinkClass(true); @@ -596,7 +600,10 @@ //hashchange event handler $window.bind( "hashchange", function(e, triggered) { - if( !urlHistory.listeningEnabled ){ + if( !urlHistory.listeningEnabled || !$.mobile.ajaxEnabled || + // TODO: deprecated - remove at 1.0 + // only links need to be checked here, as forms don't trigger a hashchange event (they just silently update the hash) + ( !$.mobile.ajaxLinksEnabled ) ){ return; }