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

Pagecontainer: Honor both reload and reloadPage during load #7801

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 9 additions & 4 deletions js/widgets/pagecontainer.js
Original file line number Diff line number Diff line change
Expand Up @@ -592,8 +592,16 @@ define( [
// know when the content is done loading, or if an error has occurred.
var deferred = ( options && options.deferred ) || $.Deferred(),

// Examining the option "reloadPage" passed by the user is deprecated as of 1.4.0
// and will be removed in 1.5.0.
// Copy option "reloadPage" to "reload", but only if option "reload" is not present
reloadOptionExtension =
( ( options && options.reload === undefined &&
options.reloadPage !== undefined ) ?
{ reload: options.reloadPage } : {} ),

// The default load options with overrides specified by the caller.
settings = $.extend( {}, this._loadDefaults, options ),
settings = $.extend( {}, this._loadDefaults, options, reloadOptionExtension ),

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

// DEPRECATED reloadPage
settings.reload = settings.reloadPage;

// If the caller provided data, and we're using "get" request,
// append the data to the URL.
if ( settings.data && settings.type === "get" ) {
Expand Down
27 changes: 25 additions & 2 deletions tests/unit/pagecontainer/pagecontainer_core.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,12 @@ test( "_find() can handle weird data-url attributes", function() {
});

( function() {
var originalLoad = $.mobile.pagecontainer.prototype._triggerWithDeprecated
var triggerData,
originalLoad = $.mobile.pagecontainer.prototype._triggerWithDeprecated;
module( "load method", {
setup: function(){
$.mobile.pagecontainer.prototype._triggerWithDeprecated = function(){
$.mobile.pagecontainer.prototype._triggerWithDeprecated = function( eventName, data ) {
triggerData = data;
return {
deprecatedEvent: {
isDefaultPrevented: function() {
Expand All @@ -30,6 +32,7 @@ module( "load method", {
}
},
teardown: function(){
triggerData = null;
$.mobile.pagecontainer.prototype._triggerWithDeprecated = originalLoad;
}
});
Expand All @@ -40,6 +43,26 @@ test( "load does not trigger an error when called withput a second param", funct
ok( "no error triggered when load method called without options" );
});

test( "Options 'reload' and 'reloadPage' both work, and 'reload' takes precedence", function() {
var pagecontainer = $( ":mobile-pagecontainer" );

pagecontainer.pagecontainer( "load", "stuff.html", {
reload: true,
reloadPage: false
});

deepEqual( triggerData.options.reload, true,
"The value of option 'reload' is not affected by the value of option 'reloadPage'" );

pagecontainer.pagecontainer( "load", "stuff.html", {
reloadPage: true
});

deepEqual( triggerData.options.reload, true,
"The value of option 'reloadPage' is copied to the value of option 'reload' if the " +
"latter is absent from the options hash" );
});

module( "_handleDialog()" );

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