Skip to content

Commit db3dbc0

Browse files
author
scottjehl
committed
Merge remote branch 'origin/master'
2 parents 7be8311 + 557da74 commit db3dbc0

File tree

4 files changed

+71
-27
lines changed

4 files changed

+71
-27
lines changed

docs/api/globalconfig.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ <h2>Configurable options</h2>
9292
<dd>The class assigned to page currently in view, and during transitions</dd>
9393

9494

95-
<dt><code>activeBtnClass</code> <em>string</em>, default: "ui-page-active"</dt>
95+
<dt><code>activeBtnClass</code> <em>string</em>, default: "ui-btn-active"</dt>
9696
<dd>The class used for "active" button state, from CSS framework.</dd>
9797

9898
<dt><code>ajaxEnabled</code> <em>boolean</em>, default: true</dt>

docs/forms/forms-sample-response.php

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,12 +27,15 @@
2727

2828
<h2>You Chose:</h2>
2929

30-
30+
<div class="ui-body ui-body-d ui-corner-all">
3131

3232
<?php
3333
echo "<p> " . $_REQUEST['shipping'] . "</p>";
3434
?>
35-
35+
36+
</div>
37+
38+
<a href="forms-sample.html" data-role="button" data-theme="b" data-icon="arrow-l">Change shipping method</a>
3639

3740
</form>
3841

docs/forms/forms-sample.html

Lines changed: 26 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -27,25 +27,42 @@ <h2>Ajax form submission</h2>
2727

2828
<p>In jQuery Mobile, form submissions are automatically handled using Ajax whenever possible, creating a smooth transition between the form and the result page. To ensure your form submits as intended, be sure to specify <code>action</code> and <code>method</code> properties on your form element. When unspecified, the method will default to <code>get</code>, and the <code>action</code> will default to the current page's relative path (found via <code>$.mobile.path.get()</code></p>
2929
<p>Forms also accept attributes for transitions just like anchors, such as <code>data-transition="pop"</code> and <code>data-direction="reverse"</code>. To submit a form without Ajax, you can either disable Ajax form handling globally, or per form via the <code>data-ajax="false"</code> attribute. The <code>target</code> attribute (as in <code>target="_blank"</code>) is respected on forms as well, and will default to the browser's handling of that target when the form submits. Note that unlike anchors, the <code>rel</code> attribute is not allowed on forms.</p>
30-
31-
<h2>Non-Ajax handling</h2>
32-
33-
<p>To prevent form submissions from being automatically handled with Ajax, add the <code>data-ajax="false"</code> attribute to the form element. You can also turn of Ajax form handling completely via the <code>ajaxEnabled</code> <a href="../api/globalconfig.html">global config option</a>.</p>
30+
3431

35-
<h2>Simple Ajax form example</h2>
36-
<p>This page demonstrates automated ajax handling of form submissions. The form below is configured to send regular a <code>get</code> request to <code>forms-sample-response.php</code>. On submit, jQuery Mobile will make sure that the Url specified is able to be retrieved via Ajax, and handle it appropriately. Keep in mind that just like ordinary HTTP form submissions, jQuery Mobile allows <code>get</code> result pages to be bookmarked by updating the Url hash when the response returns successfully. Also like ordinary form submissions, <code>post</code> requests do not contain query parameters in the hash, so they are not bookmarkable.</p>
37-
<form action="forms-sample-response.php" method="get">
32+
<h2>Default Ajax form example</h2>
33+
<p>This demonstrates automated ajax handling of form submissions. The form below is configured to send regular a <code>get</code> request to <code>forms-sample-response.php</code>. On submit, jQuery Mobile will make sure that the Url specified is able to be retrieved via Ajax, and handle it appropriately. Keep in mind that just like ordinary HTTP form submissions, jQuery Mobile allows <code>get</code> result pages to be bookmarked by updating the Url hash when the response returns successfully. Also like ordinary form submissions, <code>post</code> requests do not contain query parameters in the hash, so they are not bookmarkable.</p>
34+
<form action="forms-sample-response.php" method="get" class="ui-body ui-body-a ui-corner-all">
35+
<fieldset>
36+
<div data-role="fieldcontain">
37+
<label for="shipping" class="select">Shipping method:</label>
38+
<select name="shipping" id="shipping">
39+
<option value="Standard shipping">Standard: 7 day</option>
40+
<option value="Rush shipping">Rush: 3 days</option>
41+
<option value="Express shipping">Express: next day</option>
42+
<option value="Overnight shipping">Overnight</option>
43+
</select>
44+
</div>
45+
<button type="submit" data-theme="b" name="submit" value="submit-value">Submit</button>
46+
</fieldset>
47+
</form>
48+
49+
<h2>Non-Ajax form example</h2>
50+
51+
<p>To prevent form submissions from being automatically handled with Ajax, add the <code>data-ajax="false"</code> attribute to the form element. You can also turn of Ajax form handling completely via the <code>ajaxEnabled</code> <a href="../api/globalconfig.html">global config option</a>.</p>
52+
53+
<p>The form below is identical to the one above except for the addition of the <code>data-ajax="false"</code> attribute attribute. When the submit button is pressed, it will result in a full page refresh.</p>
54+
<form action="forms-sample-response.php" method="get" data-ajax="false" class="ui-body ui-body-a ui-corner-all">
3855
<fieldset>
3956
<div data-role="fieldcontain">
40-
<label for="shipping" class="select">Choose shipping method:</label>
57+
<label for="shipping" class="select">Shipping method:</label>
4158
<select name="shipping" id="shipping">
4259
<option value="Standard shipping">Standard: 7 day</option>
4360
<option value="Rush shipping">Rush: 3 days</option>
4461
<option value="Express shipping">Express: next day</option>
4562
<option value="Overnight shipping">Overnight</option>
4663
</select>
4764
</div>
48-
<button type="submit" data-theme="a" name="submit" value="submit-value">Submit</button>
65+
<button type="submit" data-theme="b" name="submit" value="submit-value">Submit</button>
4966
</fieldset>
5067
</form>
5168

js/jquery.mobile.navigation.js

100644100755
Lines changed: 39 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -832,17 +832,39 @@
832832
return;
833833
}
834834

835+
var settings = $.extend( {}, $.mobile.changePage.defaults, options );
836+
837+
// Make sure we have a pageContainer to work with.
838+
settings.pageContainer = settings.pageContainer || $.mobile.pageContainer;
839+
840+
// Make sure we have a fromPage.
841+
settings.fromPage = settings.fromPage || $.mobile.activePage;
842+
843+
var mpc = settings.pageContainer,
844+
pbcEvent = new $.Event( "pagebeforechange" ),
845+
triggerData = { toPage: toPage, options: settings };
846+
847+
// Let listeners know we're about to change the current page.
848+
mpc.trigger( pbcEvent, triggerData );
849+
850+
mpc.trigger( "beforechangepage", triggerData ); // XXX: DEPRECATED for 1.0
851+
852+
// If the default behavior is prevented, stop here!
853+
if( pbcEvent.isDefaultPrevented() ){
854+
return;
855+
}
856+
857+
// We allow "pagebeforechange" observers to modify the toPage in the trigger
858+
// data to allow for redirects. Make sure our toPage is updated.
859+
860+
toPage = triggerData.toPage;
861+
835862
// Set the isPageTransitioning flag to prevent any requests from
836863
// entering this method while we are in the midst of loading a page
837864
// or transitioning.
838865

839866
isPageTransitioning = true;
840867

841-
var settings = $.extend( {}, $.mobile.changePage.defaults, options );
842-
843-
// Make sure we have a pageContainer to work with.
844-
settings.pageContainer = settings.pageContainer || $.mobile.pageContainer;
845-
846868
// If the caller passed us a url, call loadPage()
847869
// to make sure it is loaded into the DOM. We'll listen
848870
// to the promise object it returns so we know when
@@ -863,16 +885,16 @@
863885

864886
//release transition lock so navigation is free again
865887
releasePageTransitionLock();
866-
settings.pageContainer.trigger("changepagefailed");
888+
settings.pageContainer.trigger( "pagechangefailed", triggerData );
889+
settings.pageContainer.trigger( "changepagefailed", triggerData ); // XXX: DEPRECATED for 1.0
867890
});
868891
return;
869892
}
870893

871894
// The caller passed us a real page DOM element. Update our
872895
// internal state and then trigger a transition to the page.
873-
var mpc = settings.pageContainer,
874-
fromPage = $.mobile.activePage,
875-
url = toPage.jqmData( "url" ),
896+
var fromPage = settings.fromPage,
897+
url = ( settings.dataUrl && path.convertUrlToDataUrl( settings.dataUrl ) ) || toPage.jqmData( "url" ),
876898
// The pageUrl var is usually the same as url, except when url is obscured as a dialog url. pageUrl always contains the file path
877899
pageUrl = url,
878900
fileUrl = path.getFilePath( url ),
@@ -882,9 +904,6 @@
882904
pageTitle = document.title,
883905
isDialog = settings.role === "dialog" || toPage.jqmData( "role" ) === "dialog";
884906

885-
// Let listeners know we're about to change the current page.
886-
mpc.trigger( "beforechangepage" );
887-
888907
// If we are trying to transition to the same page that we are currently on ignore the request.
889908
// an illegal same page request is defined by the current page being the same as the url, as long as there's history
890909
// and toPage is not an array or object (those are allowed to be "same")
@@ -893,7 +912,8 @@
893912
// to the same page.
894913
if( fromPage && fromPage[0] === toPage[0] ) {
895914
isPageTransitioning = false;
896-
mpc.trigger( "changepage" );
915+
mpc.trigger( "pagechange", triggerData );
916+
mpc.trigger( "changepage", triggerData ); // XXX: DEPRECATED for 1.0
897917
return;
898918
}
899919

@@ -980,7 +1000,9 @@
9801000
releasePageTransitionLock();
9811001

9821002
// Let listeners know we're all done changing the current page.
983-
mpc.trigger( "changepage" );
1003+
mpc.trigger( "pagechange", triggerData );
1004+
1005+
mpc.trigger( "changepage", triggerData ); // XXX: DEPRECATED for 1.0
9841006
});
9851007
};
9861008

@@ -992,7 +1014,9 @@
9921014
role: undefined, // By default we rely on the role defined by the @data-role attribute.
9931015
duplicateCachedPage: undefined,
9941016
pageContainer: undefined,
995-
showLoadMsg: true //loading message shows by default when pages are being fetched during changePage
1017+
showLoadMsg: true, //loading message shows by default when pages are being fetched during changePage
1018+
dataUrl: undefined,
1019+
fromPage: undefined
9961020
};
9971021

9981022
/* Event Bindings - hashchange, submit, and click */

0 commit comments

Comments
 (0)