NDOJ/templates/feed/feed_js.html

43 lines
1.4 KiB
HTML
Raw Normal View History

<script>
window.page = {{page_obj.number}};
window.has_next_page = {{1 if page_obj.has_next() else 0}};
window.loading_page = false;
$(function() {
2023-04-02 22:57:32 +00:00
function getQueryParams() {
var queryParams = {};
var query = window.location.search.substring(1);
var vars = query.split("&");
for (var i = 0; i < vars.length; i++) {
var pair = vars[i].split("=");
queryParams[pair[0]] = decodeURIComponent(pair[1]);
}
return queryParams;
}
$(window).on("scroll", function() {
if (window.loading_page || !window.has_next_page) return;
var distanceFromBottom = $(document).height() - ($(window).scrollTop() + $(window).height());
if (distanceFromBottom < 500) {
window.loading_page = true;
var params = {
"only_content": 1,
"page": window.page + 1,
};
2023-04-02 22:57:32 +00:00
params = Object.assign({}, getQueryParams(), params);
$.get("{{feed_content_url}}", params)
.done(function(data) {
$(".has_next").remove();
$(".middle-content").append(data);
window.loading_page = false;
window.has_next_page = parseInt($(".has_next").attr("value"));
window.page++;
MathJax.typeset($('.middle-content')[0]);
onWindowReady();
activateBlogBoxOnClick();
})
}
});
});
</script>