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
This commit is contained in:
Julian Lam
2017-12-06 12:31:55 -05:00
parent 32a8076f2a
commit 94e8b2b38d
2 changed files with 10 additions and 4 deletions

View File

@@ -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 });