From 54e36f7c548a47450b069da20deb3d6063f5fa9d Mon Sep 17 00:00:00 2001 From: Julian Lam Date: Wed, 16 Mar 2016 17:47:12 -0400 Subject: [PATCH] Update ajaxify logic w/ returnPath support If returnPath is defined, and url is null, then ajaxify will execute a replaceState instead of an ajaxification. Used in cases where a separate route is pushed but you'll want to return to the page you were on previously. (see: #4371) --- public/src/ajaxify.js | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/public/src/ajaxify.js b/public/src/ajaxify.js index 608e0a6cda..ecd8276c69 100644 --- a/public/src/ajaxify.js +++ b/public/src/ajaxify.js @@ -22,10 +22,16 @@ $(document).ready(function() { $(window).on('popstate', function (ev) { ev = ev.originalEvent; - if (ev !== null && ev.state && ev.state.url !== undefined) { - ajaxify.go(ev.state.url, function() { - $(window).trigger('action:popstate', {url: ev.state.url}); - }, true); + if (ev !== null && ev.state) { + if (ev.state.url === null && ev.state.returnPath !== undefined) { + window.history.replaceState({ + url: ev.state.returnPath + }, ev.state.returnPath, config.relative_path + '/' + ev.state.returnPath); + } else if (ev.state.url !== undefined) { + ajaxify.go(ev.state.url, function() { + $(window).trigger('action:popstate', {url: ev.state.url}); + }, true); + } } });