diff --git a/js/app_link.js b/js/app_link.js index 73c261b..de98d82 100644 --- a/js/app_link.js +++ b/js/app_link.js @@ -31,17 +31,20 @@ * Primary URL that we will attempt to redirect to. */ function app_link (platforms, fallbackUrl) { + // Set variables, allowing before hooks to alter. + app_link.platforms = platforms; + app_link.fallbackUrl = fallbackUrl; // Exexcute any before hooks. if (app_link.before) { return app_link.before(function() { app_link.before = null; - app_link(platforms, fallbackUrl); + app_link(app_link.platforms, app_link.fallbackUrl); }); } // Add referrer to fallback (Server is unable to do this accurately). var platform = platforms.app_link_platform_fallback; if (platform && platform.supports_qs) { - fallbackUrl = app_link.applyReferrer(app_link.fallbackUrl); + app_link.fallbackUrl = app_link.applyReferrer(app_link.fallbackUrl); } // Determine the user's platform. var platformKey = app_link.getPlatformKey(navigator.userAgent) || app_link.getPlatformKey(navigator.appVersion); @@ -52,7 +55,6 @@ function app_link (platforms, fallbackUrl) { el.className = ""; } // If we don't recognize the platform, or have data about the platform -- fallback. - app_link.fallbackUrl = fallbackUrl; if (!platform) { return app_link.fallback(); } diff --git a/test/app_link.js b/test/app_link.js index 80e8529..71e7784 100644 --- a/test/app_link.js +++ b/test/app_link.js @@ -271,12 +271,23 @@ describe("App Link Redirects", function() { * Test Async Before Hook. */ describe("Before Hook", function() { - it("Should run sync.", function(done) { + it("Modifies fallback variable.", function(done) { testApplinkRedirect({inject: function() { - app_link.before = function(cb){ cb(); }; - }}, applink.app_link_platform_fallback.fallback_url, done); + app_link.before = function(cb){ + app_link.fallbackUrl += "?a=b"; + cb(); + }; + }}, applink.app_link_platform_fallback.fallback_url + "?a=b", done); + }); + it("Modifies platform variables.", function(done) { + testApplinkRedirect({browser: "iPhone", inject: function() { + app_link.before = function(cb){ + app_link.platforms.app_link_platform_iphone.app_url += "?a=b"; + cb(); + }; + }}, applink.app_link_platform_iphone.app_url + "?a=b", done); }); - it("Should wait for async.", function(done) { + it("Wait for async.", function(done) { testApplinkRedirect({inject: function() { app_link.before = function(cb){ setTimeout(cb, 33); }; }}, applink.app_link_platform_fallback.fallback_url, done);