|
@ -24,43 +24,29 @@ module.exports= |
|
|
* @param totalPosts -- total amount of blog in the category |
|
|
* @param totalPosts -- total amount of blog in the category |
|
|
* @returns {Promise} promise which renders the buttons |
|
|
* @returns {Promise} promise which renders the buttons |
|
|
*/ |
|
|
*/ |
|
|
main: function(baseURL, currentPage, postsPerPage, totalPosts) |
|
|
|
|
|
|
|
|
main: function(baseURL, currentPage, postsPerPage, totalPosts, templateContext) |
|
|
{ |
|
|
{ |
|
|
return new Promise(function(resolve, reject) |
|
|
|
|
|
{ |
|
|
|
|
|
|
|
|
|
|
|
if(!isValidPage(currentPage, postsPerPage, totalPosts)) |
|
|
|
|
|
{ |
|
|
|
|
|
reject("Invalid Page"); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
var nextPage = currentPage + 1; |
|
|
|
|
|
var previousPage = currentPage - 1; |
|
|
|
|
|
|
|
|
if(typeof currentPage == "undefined") |
|
|
|
|
|
currentPage = 1; |
|
|
|
|
|
currentPage = Number(currentPage); |
|
|
|
|
|
|
|
|
var olderPosts = ""; |
|
|
|
|
|
var newerPosts = ""; |
|
|
|
|
|
|
|
|
if(!isValidPage(currentPage, postsPerPage, totalPosts)) |
|
|
|
|
|
{ |
|
|
|
|
|
reject("Invalid Page"); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
if (isValidPage(previousPage, postsPerPage, totalPosts)) |
|
|
|
|
|
{ |
|
|
|
|
|
newerPosts = "<button class=\"btn btn-secondary btn-lg " + |
|
|
|
|
|
"w3-padding-large w3-white w3-border\" onclick=\"location.href='" + |
|
|
|
|
|
baseURL + "?page=" + previousPage + |
|
|
|
|
|
"'\"><b>Newer Posts »</b></button>"; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
var nextPage = currentPage + 1; |
|
|
|
|
|
var previousPage = currentPage - 1; |
|
|
|
|
|
|
|
|
if (isValidPage(nextPage, postsPerPage, totalPosts)) |
|
|
|
|
|
{ |
|
|
|
|
|
olderPosts = "<button class=\"btn btn-secondary btn-lg " + |
|
|
|
|
|
"w3-padding-large w3-white w3-border\" onclick=\"location.href='" + |
|
|
|
|
|
baseURL + "?page=" + nextPage + |
|
|
|
|
|
"'\"><b>Older Posts »</b></button>"; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
if (isValidPage(previousPage, postsPerPage, totalPosts)) |
|
|
|
|
|
{ |
|
|
|
|
|
templateContext.newPostsURL = baseURL + "?page=" + previousPage; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
resolve(" <div class=\"row\">\n" + |
|
|
|
|
|
" <div class=\"col-6\">" + newerPosts + "</div>\n" + |
|
|
|
|
|
" <div class=\"col-6\"><span class=\"float-right\">" + olderPosts + "</span></div>\n" + |
|
|
|
|
|
" <br><br></div>"); |
|
|
|
|
|
}) |
|
|
|
|
|
|
|
|
if (isValidPage(nextPage, postsPerPage, totalPosts)) |
|
|
|
|
|
{ |
|
|
|
|
|
templateContext.oldPostsURL = baseURL + "?page=" + nextPage |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
} |
|
|
} |
|
|
}; |
|
|
}; |