From d42e64a09e6e1898d4423d786bc48a47a8b8fc0e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Yaroslav=20de=20la=20Pe=C3=B1a=20Smirnov?= Date: Mon, 8 Oct 2018 00:03:23 +0300 Subject: dynamic (no infinite) scrolling working on categories, index (not archive) --- weblog/static/weblog/js/weblog.js | 20 +++++++++++++++++++- weblog/templates/weblog/index.html | 30 ++++++++++++++++++++++++++++++ 2 files changed, 49 insertions(+), 1 deletion(-) (limited to 'weblog') diff --git a/weblog/static/weblog/js/weblog.js b/weblog/static/weblog/js/weblog.js index 3d93770..f885da2 100755 --- a/weblog/static/weblog/js/weblog.js +++ b/weblog/static/weblog/js/weblog.js @@ -12,5 +12,23 @@ function toggleNode(caller){ target.classList.toggle('show'); } -function loadBlogPosts(page = 2, category = null){ +function loadBlogPosts(url, page = 2){ + var req = new XMLHttpRequest(); + function insert(){ + if (this.status == 200 && this.readyState == 4){ + var blog_content = document.querySelector(".blog-content"); + try{ + var nxtpage_button = document.querySelector(".nxtpage-button"); + nxtpage_button.insertAdjacentHTML("beforebegin", this.responseText); + } + catch(er){ + console.log("error "+er); + blog_content.insertAdjacentHTML("beforeend", this.responseText); + } + console.log(this.responseText); + } + } + req.addEventListener("readystatechange", insert); + req.open("GET", url, true); + req.send(); } diff --git a/weblog/templates/weblog/index.html b/weblog/templates/weblog/index.html index b30c0ff..aa0b70a 100755 --- a/weblog/templates/weblog/index.html +++ b/weblog/templates/weblog/index.html @@ -62,6 +62,13 @@ {% endfor %} + {% if dynamic_load %} + {% if not infinite_load %} +
+ {% trans 'Load more...' context 'Load more pages' %} +
+ {% endif %} + {% else %} {% if last_page > 1 %} {% endif %} {% endif %} + {% endif %} {% else %}

{% trans 'Nothing has been posted yet.' %}

{% endif %} @@ -107,8 +115,30 @@ {% endif %} -- cgit v1.2.3