From 50795d9b2644acb1e9dbe4d1e808256699fc8f29 Mon Sep 17 00:00:00 2001 From: Gabriel Schulhof Date: Sun, 26 Oct 2014 02:52:44 +0300 Subject: [PATCH 1/2] Pagecontainer: Honor both reload and reloadPage during load Option reload takes precedence over options reloadPage Fixes gh-7769 --- js/widgets/pagecontainer.js | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/js/widgets/pagecontainer.js b/js/widgets/pagecontainer.js index a20a735c1d0..06a98d215c7 100644 --- a/js/widgets/pagecontainer.js +++ b/js/widgets/pagecontainer.js @@ -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, @@ -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" ) { From bede67a86725b607649aa75cde36833368eeefc9 Mon Sep 17 00:00:00 2001 From: Gabriel Schulhof Date: Sun, 26 Oct 2014 02:58:44 +0300 Subject: [PATCH 2/2] Pagecontainer: Test correct backcompat reload option behavior --- .../unit/pagecontainer/pagecontainer_core.js | 27 +++++++++++++++++-- 1 file changed, 25 insertions(+), 2 deletions(-) diff --git a/tests/unit/pagecontainer/pagecontainer_core.js b/tests/unit/pagecontainer/pagecontainer_core.js index 87b5dbcc4bb..9ee3625d1e1 100644 --- a/tests/unit/pagecontainer/pagecontainer_core.js +++ b/tests/unit/pagecontainer/pagecontainer_core.js @@ -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() { @@ -30,6 +32,7 @@ module( "load method", { } }, teardown: function(){ + triggerData = null; $.mobile.pagecontainer.prototype._triggerWithDeprecated = originalLoad; } }); @@ -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() {