Skip to content

Commit 5f622de

Browse files
author
Gabriel Schulhof
committed
Pagecontainer: Honor both reload and reloadPage during load
Option reload takes precedence over option reloadPage Closes jquery-archivegh-7801 Fixes jquery-archivegh-7769
1 parent 87d2b9c commit 5f622de

File tree

2 files changed

+34
-6
lines changed

2 files changed

+34
-6
lines changed

js/widgets/pagecontainer.js

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -592,8 +592,16 @@ define( [
592592
// know when the content is done loading, or if an error has occurred.
593593
var deferred = ( options && options.deferred ) || $.Deferred(),
594594

595+
// Examining the option "reloadPage" passed by the user is deprecated as of 1.4.0
596+
// and will be removed in 1.5.0.
597+
// Copy option "reloadPage" to "reload", but only if option "reload" is not present
598+
reloadOptionExtension =
599+
( ( options && options.reload === undefined &&
600+
options.reloadPage !== undefined ) ?
601+
{ reload: options.reloadPage } : {} ),
602+
595603
// The default load options with overrides specified by the caller.
596-
settings = $.extend( {}, this._loadDefaults, options ),
604+
settings = $.extend( {}, this._loadDefaults, options, reloadOptionExtension ),
597605

598606
// The DOM element for the content after it has been loaded.
599607
content = null,
@@ -603,9 +611,6 @@ define( [
603611
absUrl = $.mobile.path.makeUrlAbsolute( url, this._findBaseWithDefault() ),
604612
fileUrl, dataUrl, pblEvent, triggerData;
605613

606-
// DEPRECATED reloadPage
607-
settings.reload = settings.reloadPage;
608-
609614
// If the caller provided data, and we're using "get" request,
610615
// append the data to the URL.
611616
if ( settings.data && settings.type === "get" ) {

tests/unit/pagecontainer/pagecontainer_core.js

Lines changed: 25 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,12 @@ test( "_find() can handle weird data-url attributes", function() {
1313
});
1414

1515
( function() {
16-
var originalLoad = $.mobile.pagecontainer.prototype._triggerWithDeprecated
16+
var triggerData,
17+
originalLoad = $.mobile.pagecontainer.prototype._triggerWithDeprecated;
1718
module( "load method", {
1819
setup: function(){
19-
$.mobile.pagecontainer.prototype._triggerWithDeprecated = function(){
20+
$.mobile.pagecontainer.prototype._triggerWithDeprecated = function( eventName, data ) {
21+
triggerData = data;
2022
return {
2123
deprecatedEvent: {
2224
isDefaultPrevented: function() {
@@ -30,6 +32,7 @@ module( "load method", {
3032
}
3133
},
3234
teardown: function(){
35+
triggerData = null;
3336
$.mobile.pagecontainer.prototype._triggerWithDeprecated = originalLoad;
3437
}
3538
});
@@ -40,6 +43,26 @@ test( "load does not trigger an error when called withput a second param", funct
4043
ok( "no error triggered when load method called without options" );
4144
});
4245

46+
test( "Options 'reload' and 'reloadPage' both work, and 'reload' takes precedence", function() {
47+
var pagecontainer = $( ":mobile-pagecontainer" );
48+
49+
pagecontainer.pagecontainer( "load", "stuff.html", {
50+
reload: true,
51+
reloadPage: false
52+
});
53+
54+
deepEqual( triggerData.options.reload, true,
55+
"The value of option 'reload' is not affected by the value of option 'reloadPage'" );
56+
57+
pagecontainer.pagecontainer( "load", "stuff.html", {
58+
reloadPage: true
59+
});
60+
61+
deepEqual( triggerData.options.reload, true,
62+
"The value of option 'reloadPage' is copied to the value of option 'reload' if the " +
63+
"latter is absent from the options hash" );
64+
});
65+
4366
module( "_handleDialog()" );
4467

4568
test( "A dialog is recognized via presence of the data key, not the ui-dialog class", function() {

0 commit comments

Comments
 (0)