diff --git a/public/src/ajaxify.js b/public/src/ajaxify.js index 0f8668858aca..db5c034ccf95 100644 --- a/public/src/ajaxify.js +++ b/public/src/ajaxify.js @@ -3,9 +3,7 @@ ajaxify = window.ajaxify || {}; -$(document).ready(function () { - var location = document.location || window.location; - var rootUrl = location.protocol + '//' + (location.hostname || location.host) + (location.port ? ':' + location.port : ''); +(function () { var apiXHR = null; var ajaxifyTimer; @@ -22,22 +20,6 @@ $(document).ready(function () { Benchpress = _Benchpress; }); - $(window).on('popstate', function (ev) { - ev = ev.originalEvent; - - 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); - } - } - }); - ajaxify.count = 0; ajaxify.currentPage = null; @@ -102,6 +84,14 @@ $(document).ready(function () { return true; }; + // this function is called just once from footer on page load + ajaxify.coldLoad = function () { + var url = ajaxify.start(window.location.pathname.slice(1) + window.location.search + window.location.hash); + ajaxify.updateHistory(url, true); + ajaxify.end(url, app.template); + $(window).trigger('action:ajaxify.coldLoad'); + }; + ajaxify.isCold = function () { return ajaxify.count <= 1; }; @@ -334,11 +324,35 @@ $(document).ready(function () { }); }; + require(['translator', 'benchpress'], function (translator, Benchpress) { + translator.translate('[[error:no-connection]]'); + Benchpress.registerLoader(ajaxify.loadTemplate); + }); +}()); + +$(document).ready(function () { + $(window).on('popstate', function (ev) { + ev = ev.originalEvent; + + 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); + } + } + }); + function ajaxifyAnchors() { function hrefEmpty(href) { return href === undefined || href === '' || href === 'javascript:;'; } - + var location = document.location || window.location; + var rootUrl = location.protocol + '//' + (location.hostname || location.host) + (location.port ? ':' + location.port : ''); var contentEl = document.getElementById('content'); // Enhancing all anchors to ajaxify... @@ -412,13 +426,11 @@ $(document).ready(function () { return; } - translator.translate('[[global:unsaved-changes]]', function (text) { - bootbox.confirm(text, function (navigate) { - if (navigate) { - app.flags._unsaved = false; - process.call(_self); - } - }); + bootbox.confirm('[[global:unsaved-changes]]', function (navigate) { + if (navigate) { + app.flags._unsaved = false; + process.call(_self); + } }); return e.preventDefault(); } @@ -427,14 +439,8 @@ $(document).ready(function () { }); } - require(['benchpress'], function (Benchpress) { - Benchpress.registerLoader(ajaxify.loadTemplate); - }); - if (window.history && window.history.pushState) { // Progressive Enhancement, ajaxify available only to modern browsers ajaxifyAnchors(); } - - app.load(); }); diff --git a/public/src/app.js b/public/src/app.js index 82439c270fab..c40bc607ef4f 100644 --- a/public/src/app.js +++ b/public/src/app.js @@ -37,14 +37,14 @@ app.cacheBuster = null; locale: config.userLang, }); + $(document).ready(function () { + ajaxify.parseData(); + app.load(); + }); + app.load = function () { overrides.overrideTimeago(); - var url = ajaxify.start(window.location.pathname.slice(1) + window.location.search + window.location.hash); - ajaxify.updateHistory(url, true); - ajaxify.parseData(); - ajaxify.end(url, app.template); - handleStatusChange(); if (config.searchEnabled) { diff --git a/src/views/admin/footer.tpl b/src/views/admin/footer.tpl index 1f6d36eb707a..1593e636c3cb 100644 --- a/src/views/admin/footer.tpl +++ b/src/views/admin/footer.tpl @@ -8,5 +8,12 @@ + diff --git a/src/views/partials/footer/js.tpl b/src/views/partials/footer/js.tpl new file mode 100644 index 000000000000..1f5cbc50a853 --- /dev/null +++ b/src/views/partials/footer/js.tpl @@ -0,0 +1,19 @@ + + +{{{each scripts}}} + +{{{end}}} + + \ No newline at end of file