From 94e8b2b38d588698fcaf3e1c856c2e65476aac53 Mon Sep 17 00:00:00 2001 From: Julian Lam Date: Wed, 6 Dec 2017 12:31:55 -0500 Subject: [PATCH] Added ajaxify.isCold() And used it in app.js, so window.scrollTo(0, 0); is not called on cold load (since you're already at the top). Useful in low- bandwidth modes since you might accidentally get kicked to the top of the page due to a slow connection and delayed .init(). Slightly related to testing in #6150 --- public/src/ajaxify.js | 10 +++++++--- public/src/app.js | 4 +++- 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/public/src/ajaxify.js b/public/src/ajaxify.js index 914fdf8974..35c30ab1a1 100644 --- a/public/src/ajaxify.js +++ b/public/src/ajaxify.js @@ -37,6 +37,7 @@ $(document).ready(function () { } }); + ajaxify.count = 0; ajaxify.currentPage = null; ajaxify.go = function (url, callback, quiet) { @@ -100,6 +101,10 @@ $(document).ready(function () { return true; }; + ajaxify.isCold = function () { + return ajaxify.count <= 1; + }; + ajaxify.handleRedirects = function (url) { url = ajaxify.removeRelativePath(url.replace(/^\/|\/$/g, '')).toLowerCase(); var isClientToAdmin = url.startsWith('admin') && window.location.pathname.indexOf(RELATIVE_PATH + '/admin') !== 0; @@ -113,7 +118,6 @@ $(document).ready(function () { return false; }; - ajaxify.start = function (url) { url = ajaxify.removeRelativePath(url.replace(/^\/|\/$/g, '')); @@ -123,6 +127,8 @@ $(document).ready(function () { $(window).trigger('action:ajaxify.start', payload); + ajaxify.count += 1; + return payload.url; }; @@ -197,7 +203,6 @@ $(document).ready(function () { ajaxify.end = function (url, tpl_url) { var count = 2; - function done() { count -= 1; if (count === 0) { @@ -205,7 +210,6 @@ $(document).ready(function () { } } ajaxify.loadScript(tpl_url, done); - ajaxify.widgets.render(tpl_url, done); $(window).trigger('action:ajaxify.contentLoaded', { url: url, tpl: tpl_url }); diff --git a/public/src/app.js b/public/src/app.js index f3d27e7ef0..f56d894de8 100644 --- a/public/src/app.js +++ b/public/src/app.js @@ -278,7 +278,9 @@ app.cacheBuster = null; app.replaceSelfLinks(); // Scroll back to top of page - window.scrollTo(0, 0); + if (!ajaxify.isCold()) { + window.scrollTo(0, 0); + } }; app.showMessages = function () {