From 0b39968a9c95df1ef9edf8c66e2eac97d36ae651 Mon Sep 17 00:00:00 2001 From: Julian Lam Date: Mon, 25 Nov 2013 15:56:16 -0500 Subject: [PATCH] fixing back button behaviour and playing nice with History API --- public/src/ajaxify.js | 38 ++++++++++++++++++-------------------- 1 file changed, 18 insertions(+), 20 deletions(-) diff --git a/public/src/ajaxify.js b/public/src/ajaxify.js index 0773a8f21e..d3581e947e 100644 --- a/public/src/ajaxify.js +++ b/public/src/ajaxify.js @@ -67,26 +67,24 @@ var ajaxify = {}; } if (templates.is_available(tpl_url) && !templates.force_refresh(tpl_url)) { - //if (quiet !== true) { - if (window.history && window.history.pushState) { - window.history.pushState({ - url: url - }, url, RELATIVE_PATH + '/' + url); - - $.ajax(RELATIVE_PATH + '/plugins/fireHook', { - type: 'PUT', - data: { - _csrf: $('#csrf_token').val(), - hook: 'page.load', - args: { - template: tpl_url, - url: url, - uid: app.uid - } + if (window.history && window.history.pushState) { + window.history[!quiet ? 'pushState' : 'replaceState']({ + url: url + }, url, RELATIVE_PATH + '/' + url); + + $.ajax(RELATIVE_PATH + '/plugins/fireHook', { + type: 'PUT', + data: { + _csrf: $('#csrf_token').val(), + hook: 'page.load', + args: { + template: tpl_url, + url: url, + uid: app.uid } - }); - } - //} + } + }); + } translator.load(tpl_url); @@ -114,7 +112,7 @@ var ajaxify = {}; if (hash) { require(['forum/topic'], function(topic) { - topic.scrollToPost(hash.substr(1)) + topic.scrollToPost(hash.substr(1)); }); } });