diff --git a/_config.yml b/_config.yml index 59e58d5..caea207 100644 --- a/_config.yml +++ b/_config.yml @@ -13,5 +13,10 @@ github_username: jekyll # Layout settings header_type: default # values [ drawer, default ] post_type: default # values [ highlight, default ] +pagination_type: default # values [ ops, default ] + # Build settings markdown: kramdown + +# Pagination +paginate: 3 diff --git a/_layouts/default.html b/_layouts/default.html index ee8d852..4c39d77 100644 --- a/_layouts/default.html +++ b/_layouts/default.html @@ -26,7 +26,9 @@ - + {% if site.pagination_type == 'ops' %} + + {% endif %} diff --git a/index.html b/index.html index 0e104e2..63999ef 100644 --- a/index.html +++ b/index.html @@ -1,7 +1,6 @@ --- layout: default --- - {% if site.post_type == 'highlight' %}
diff --git a/js/site.js b/js/site.js new file mode 100644 index 0000000..6fa0e51 --- /dev/null +++ b/js/site.js @@ -0,0 +1,49 @@ +var _this = document.getElementById("js-load-more"); +_this.onclick = loadMorePosts; + +var HttpClient = function() { + 'use strict'; + this.get = function(Url, Callback) { + var HttpRequest = new XMLHttpRequest(); + HttpRequest.onreadystatechange = function() { + if (HttpRequest.readyState == 4 && HttpRequest.status == 200) + Callback(HttpRequest.responseText); + }; + + HttpRequest.open("GET", Url, true); + HttpRequest.send(null); + }; +}; + +Element.prototype.remove = function() { + this.parentElement.removeChild(this); +}; + +NodeList.prototype.remove = HTMLCollection.prototype.remove = function() { + for (var i = this.length - 1; i >= 0; i--) { + if (this[i] && this[i].parentElement) { + this[i].parentElement.removeChild(this[i]); + } + } +}; + +function loadMorePosts() { + var blogContainer = document.getElementById("js-post-container"); + var nextPage = parseInt(blogContainer.dataset.page) + 1; + + _this.className += " loading"; + + Client = new HttpClient(); + Client.get('/page' + nextPage, function(data) { + parser = new DOMParser(); + var htmlData = parser.parseFromString(data, "text/html"); + var articles = htmlData.getElementsByTagName("article"); + blogContainer.parentNode.insertBefore(articles[0], blogContainer.nextSibling); + + if (blogContainer.dataset.totalPages == nextPage) { + document.getElementById("js-load-more").remove(); + } + _this.className = ""; + + }); +}