From 00abdeb61de89029f4a14741c0c09bbadc097c78 Mon Sep 17 00:00:00 2001 From: Alex Hill Date: Thu, 5 Jun 2014 12:56:41 +0800 Subject: [PATCH 1/2] Add failing test for fallback HTTP referer --- test/app.rb | 9 +++++++++ test/unit/pjax_fallback.js | 15 +++++++++++++++ 2 files changed, 24 insertions(+) diff --git a/test/app.rb b/test/app.rb index 9be09f53..4d75aaf7 100644 --- a/test/app.rb +++ b/test/app.rb @@ -78,6 +78,15 @@ def title(str) end end +get '/referer_timeout.html' do + if pjax? + sleep 1 + erb :referer, :layout => false + else + erb :referer + end +end + get '/boom.html' do status 500 erb :boom, :layout => !pjax? diff --git a/test/unit/pjax_fallback.js b/test/unit/pjax_fallback.js index 0ab5b032..9285af81 100644 --- a/test/unit/pjax_fallback.js +++ b/test/unit/pjax_fallback.js @@ -99,6 +99,21 @@ asyncTest("sends correct HTTP referer"+s, function() { }) }) +asyncTest("sends correct HTTP referer after failed request"+s, function() { + var frame = this.frame + + $('iframe')[0].onload = function() { + var referer = frame.document.getElementById("referer").textContent + equal(referer.substr(-10), "/home.html") + start() + } + + frame.$.pjax({ + url: "/referer_timeout.html", + container: "#main" + }) +}) + asyncTest("adds entry to browser history"+s, function() { var frame = this.frame var count = 0 From c40fecd34911a277bc49f426e67923a4b51ab597 Mon Sep 17 00:00:00 2001 From: Alex Hill Date: Thu, 5 Jun 2014 13:54:29 +0800 Subject: [PATCH 2/2] call history.back() then location.assign() in locationReplace --- jquery.pjax.js | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/jquery.pjax.js b/jquery.pjax.js index 0a9cb1e1..2fb43d24 100644 --- a/jquery.pjax.js +++ b/jquery.pjax.js @@ -376,8 +376,12 @@ function pjaxReload(container, options) { // // Returns nothing. function locationReplace(url) { - window.history.replaceState(null, "", "#") - window.location.replace(url) + window.history.back() + setTimeout(function() { + window.history.replaceState(null, "", "#") + window.location.assign(url) + }, 0) + }