Skip to content

Commit

Permalink
feat: add partials/footer/js.tpl
Browse files Browse the repository at this point in the history
add ajaxify.coldLoad which gets called from partials/footer/js.tpl
  • Loading branch information
barisusakli committed Sep 5, 2020
1 parent 4031a8c commit 94da9fe
Show file tree
Hide file tree
Showing 4 changed files with 70 additions and 38 deletions.
72 changes: 39 additions & 33 deletions public/src/ajaxify.js
Expand Up @@ -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;

Expand All @@ -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;

Expand Down Expand Up @@ -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;
};
Expand Down Expand Up @@ -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...
Expand Down Expand Up @@ -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();
}
Expand All @@ -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();
});
10 changes: 5 additions & 5 deletions public/src/app.js
Expand Up @@ -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) {
Expand Down
7 changes: 7 additions & 0 deletions src/views/admin/footer.tpl
Expand Up @@ -8,5 +8,12 @@
<div id="footer" class="container" style="padding-top: 50px; display:none;">
<footer class="footer">Copyright &copy; 2015 <a target="_blank" href="https://nodebb.org">NodeBB</a> by <a target="_blank" href="https://github.com/psychobunny">psychobunny</a>, <a href="https://github.com/julianlam" target="_blank">julianlam</a>, <a href="https://github.com/barisusakli" target="_blank">barisusakli</a> from <a target="_blank" href="http://www.designcreateplay.com">designcreateplay</a></footer>
</div>
<script>
window.addEventListener('DOMContentLoaded', function () {
$(document).ready(function () {
ajaxify.coldLoad();
});
});
</script>
</body>
</html>
19 changes: 19 additions & 0 deletions src/views/partials/footer/js.tpl
@@ -0,0 +1,19 @@
<script defer src="{relative_path}/assets/nodebb.min.js?{config.cache-buster}"></script>

{{{each scripts}}}
<script defer type="text/javascript" src="{scripts.src}"></script>
{{{end}}}

<script>
window.addEventListener('DOMContentLoaded', function () {
require(['forum/footer']);
<!-- IF useCustomJS -->
{{customJS}}
<!-- ENDIF useCustomJS -->
$(document).ready(function () {
ajaxify.coldLoad();
});
});
</script>

0 comments on commit 94da9fe

Please sign in to comment.