diff options
author | Yaroslav de la Peña Smirnov <contact@yaroslavps.com> | 2018-10-08 05:08:23 +0300 |
---|---|---|
committer | Yaroslav de la Peña Smirnov <contact@yaroslavps.com> | 2018-10-08 05:08:23 +0300 |
commit | 89b97e2ad786234a8e8f5ba38bbe5fc3cbd01022 (patch) | |
tree | 4f99d55b8522f77b403de62b0a2dd8a7157b11f5 /weblog/templates | |
parent | d42e64a09e6e1898d4423d786bc48a47a8b8fc0e (diff) | |
download | w3blog-89b97e2ad786234a8e8f5ba38bbe5fc3cbd01022.tar.gz w3blog-89b97e2ad786234a8e8f5ba38bbe5fc3cbd01022.zip |
dynamic, infinite load done
Diffstat (limited to 'weblog/templates')
-rwxr-xr-x | weblog/templates/weblog/index.html | 34 |
1 files changed, 30 insertions, 4 deletions
diff --git a/weblog/templates/weblog/index.html b/weblog/templates/weblog/index.html index aa0b70a..2fab730 100755 --- a/weblog/templates/weblog/index.html +++ b/weblog/templates/weblog/index.html @@ -62,14 +62,19 @@ </div>
</div>
{% endfor %}
+ {% if last_page > 1 %}
{% if dynamic_load %}
{% if not infinite_load %}
- <div class="nxtpage-container">
+ <div class="nxtpage-container text-center">
<a class="button nxtpage-button" href="#">{% trans 'Load more...' context 'Load more pages' %}</a>
</div>
{% endif %}
+ <div class="loader-container text-center hidden">
+ <div class="loader">
+ {% trans 'Loading...' %}
+ </div>
+ </div>
{% else %}
- {% if last_page > 1 %}
<ul class="pagination">
{% if current_page != 1 %}
<li title="{% trans 'First' context 'Page' %}"><a href="{% if category %}{% if category == 'misc' %}{% url 'weblog:CategoryIndex' category_slug='misc' %}{% else %}{% url 'weblog:CategoryIndex' category_slug=category.slug %}{% endif %}{% else %}{% url 'weblog:Index' %}{% endif %}">«</a></li>
@@ -115,6 +120,9 @@ <script>
var current_page = {{ current_page }};
var last_page = {{ last_page }};
+ {% if not infinite_load %}
+ var nxtpage_button = document.querySelector(".nxtpage-button");
+ {% endif %}
function loadNextPage(e){
try{
e.stopPropagation();
@@ -125,18 +133,36 @@ current_page++;
{% if category %}
var url = "{% url 'weblog:GetCategoryPosts' category_slug=category.slug nxtpage=current_page %}";
+ {% elif year %}
+ {% if month_num %}
+ var url = "{% url 'weblog:GetArchivePosts' year=year month=month_num nxtpage=current_page %}";
+ {% else %}
+ var url = "{% url 'weblog:GetArchivePosts' year=year nxtpage=current_page %}";
+ {% endif %}
{% else %}
var url = "{% url 'weblog:GetPosts' nxtpage=current_page %}";
{% endif %}
url = url.substring(0, url.length - 2)+current_page;
+ {% if infinite_load %}
+ loadBlogPosts(url, current_page, true);
+ {% else %}
loadBlogPosts(url, current_page);
- console.log("loading");
+ {% endif %}
+ {% if not infinite_load %}
+ if (current_page == last_page)
+ document.querySelector(".nxtpage-container").removeChild(nxtpage_button);
+ {% endif %}
}
}
{% if infinite_load %}
+ window.addEventListener("scroll", function(){
+ if (current_page != last_page){
+ if(document.documentElement.scrollHeight - document.documentElement.scrollTop === document.documentElement.clientHeight)
+ loadNextPage();
+ }
+ });
{% else %}
window.addEventListener("load", function(){
- var nxtpage_button = document.querySelector(".nxtpage-button");
nxtpage_button.addEventListener("click", loadNextPage);
});
{% endif %}
|