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

Commit 7b97a67

Browse files
author
Gabriel Schulhof
committed
Pagecontainer: Honor both reload and reloadPage during load
Option reload takes precedence over option reloadPage (cherry picked from commit 5f622de) Closes gh-7801 Fixes gh-7769
1 parent 198e5d2 commit 7b97a67

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
@@ -587,8 +587,16 @@ define( [
587587
// know when the content is done loading, or if an error has occurred.
588588
var deferred = ( options && options.deferred ) || $.Deferred(),
589589

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

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

601-
// DEPRECATED reloadPage
602-
settings.reload = settings.reloadPage;
603-
604609
// If the caller provided data, and we're using "get" request,
605610
// append the data to the URL.
606611
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)