Skip to content

Commit

Permalink
Programmatic toggle and disable only page pagination
Browse files Browse the repository at this point in the history
* Don't send the jQuery script if no more pages
* Adjust comment reply box value to accommodate on the fly
* This also allows some fixing of rendering on pages that have no items in the list e.g. too far out in `p` QSP.

Closes OpenUserJS#531

**MISC NOTE**:
* Existing `pagination` object is "late" object creation e.g. accumulation of it's properties and methods occurs from iteration through existing methods and `lastPage` is calculated near the end of the process.
  • Loading branch information
Martii committed Jan 19, 2015
1 parent 3f30956 commit f0a6594
Show file tree
Hide file tree
Showing 15 changed files with 101 additions and 14 deletions.
9 changes: 9 additions & 0 deletions libs/templateHelpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,11 @@ var paginateTemplate = function (aOpts) {
var distVisible = aOpts.distVisible || 4;
var firstVisible = aOpts.firstVisible || true;
var lastVisible = aOpts.firstVisible || true;
var soleVisible = aOpts.soleVisible || false;

if (!soleVisible && lastPage === 1) {
return null;
}

var linkedPages = [];

Expand All @@ -33,6 +38,10 @@ var paginateTemplate = function (aOpts) {
if (lastVisible && linkedPages.length > 0 && linkedPages[linkedPages.length - 1] !== lastPage)
linkedPages.push(lastPage);

if (linkedPages.length === 0) {
return null;
}

var html = '';
html += '<ul class="pagination">';
for (var i = 0; i < linkedPages.length; i++) {
Expand Down
2 changes: 1 addition & 1 deletion views/includes/scripts/commentReplyScript.html
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
// Show spacer div
$('#reply-control').on('show.bs.collapse', function () {
$('#show-reply-form-when-visible').css({
height: '210px'
height: '{{#paginationRendered}}210{{/paginationRendered}}{{^paginationRendered}}268{{/paginationRendered}}px'
});
});

Expand Down
8 changes: 7 additions & 1 deletion views/pages/categoryListPage.html
Original file line number Diff line number Diff line change
Expand Up @@ -22,21 +22,27 @@ <h4 class="list-group-item-heading">{{name}}</h4>
{{/categoryList}}
</div>
<div class="panel-group col-sm-offset-0 col-md-offset-2 col-lg-offset-3">
{{#paginationRendered}}
<div class="text-center collapse">
{{{paginationRendered}}}
</div>
{{/paginationRendered}}
<div class="panel panel-default col-sm-12 col-md-12 col-lg-12">
{{> includes/discussionList.html }}
</div>
{{#paginationRendered}}
<div class="text-center">
{{{paginationRendered}}}
</div>
{{/paginationRendered}}
</div>
</div>
</div>
</div>
{{> includes/footer.html }}
{{> includes/scripts/showTopPagination.html }}
{{#paginationRendered}}
{{> includes/scripts/showTopPagination.html }}
{{/paginationRendered}}
{{> includes/scripts/tableTrLinkScript.html }}
</body>
</html>
8 changes: 7 additions & 1 deletion views/pages/discussionListPage.html
Original file line number Diff line number Diff line change
Expand Up @@ -18,20 +18,26 @@
<i class="fa fa-plus"></i> Create Topic
</a>
</div>
{{#paginationRendered}}
<div class="text-center collapse">
{{{paginationRendered}}}
</div>
{{/paginationRendered}}
<div class="panel panel-default">
{{> includes/discussionList.html }}
</div>
{{#paginationRendered}}
<div class="text-center">
{{{paginationRendered}}}
</div>
{{/paginationRendered}}
</div>
</div>
</div>
{{> includes/footer.html }}
{{> includes/scripts/showTopPagination.html }}
{{#paginationRendered}}
{{> includes/scripts/showTopPagination.html }}
{{/paginationRendered}}
{{> includes/scripts/tableTrLinkScript.html }}
</body>
</html>
8 changes: 7 additions & 1 deletion views/pages/discussionPage.html
Original file line number Diff line number Diff line change
Expand Up @@ -31,15 +31,19 @@
<div class="container-fluid comments">
<div class="row">
<section class="topic-area list-group">
{{#paginationRendered}}
<div class="text-center collapse">
{{{paginationRendered}}}
</div>
{{/paginationRendered}}
{{#commentList}}
{{> includes/comment.html }}
{{/commentList}}
{{#paginationRendered}}
<div class="text-center">
{{{paginationRendered}}}
</div>
{{/paginationRendered}}
</section>
</div>
</div>
Expand All @@ -53,7 +57,9 @@
<div id="show-reply-form-when-visible"></div>
{{> includes/commentForm.html }}
{{> includes/footer.html }}
{{> includes/scripts/showTopPagination.html }}
{{#paginationRendered}}
{{> includes/scripts/showTopPagination.html }}
{{/paginationRendered}}
{{#authedUser}}
{{> includes/scripts/markdownEditor.html }}
{{> includes/scripts/commentReplyScript.html }}
Expand Down
8 changes: 7 additions & 1 deletion views/pages/groupListPage.html
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,19 @@
<h2 class="page-heading">
Groups
</h2>
{{#paginationRendered}}
<div class="text-center collapse">
{{{paginationRendered}}}
</div>
{{/paginationRendered}}
<div class="panel panel-default">
{{> includes/groupList.html }}
</div>
{{#paginationRendered}}
<div class="text-center">
{{{paginationRendered}}}
</div>
{{/paginationRendered}}
</div>
<div class="col-sm-4">
{{> includes/searchBarPanel.html }}
Expand All @@ -29,7 +33,9 @@ <h2 class="page-heading">
</div>
</div>
{{> includes/footer.html }}
{{> includes/scripts/showTopPagination.html }}
{{#paginationRendered}}
{{> includes/scripts/showTopPagination.html }}
{{/paginationRendered}}
{{> includes/scripts/tableTrLinkScript.html }}
</body>
</html>
8 changes: 7 additions & 1 deletion views/pages/groupScriptListPage.html
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,19 @@
<h2 class="page-heading">
<a href="{{{group.groupPageUrl}}}" class="script-name">{{group.name}}</a>
</h2>
{{#paginationRendered}}
<div class="text-center collapse">
{{{paginationRendered}}}
</div>
{{/paginationRendered}}
<div class="panel panel-default">
{{> includes/scriptList.html }}
</div>
{{#paginationRendered}}
<div class="text-center">
{{{paginationRendered}}}
</div>
{{/paginationRendered}}
</div>
<div class="col-sm-4">
{{> includes/searchBarPanel.html }}
Expand All @@ -31,7 +35,9 @@ <h2 class="page-heading">
</div>
{{> includes/footer.html }}
{{> includes/scripts/tableTrLinkScript.html }}
{{> includes/scripts/showTopPagination.html }}
{{#paginationRendered}}
{{> includes/scripts/showTopPagination.html }}
{{/paginationRendered}}
{{> includes/scripts/lazyIconScript.html }}
</body>
</html>
8 changes: 7 additions & 1 deletion views/pages/removedItemListPage.html
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,19 @@
<h2 class="page-heading">
Removed Items
</h2>
{{#paginationRendered}}
<div class="text-center collapse">
{{{paginationRendered}}}
</div>
{{/paginationRendered}}
<div class="panel panel-default">
{{> includes/removedItemList.html }}
</div>
{{#paginationRendered}}
<div class="text-center">
{{{paginationRendered}}}
</div>
{{/paginationRendered}}
</div>
<div class="col-sm-4">
{{> includes/searchBarPanel.html }}
Expand All @@ -35,6 +39,8 @@ <h3>Filters</h3>
</div>
{{> includes/footer.html }}
{{> includes/scripts/tableTrLinkScript.html }}
{{> includes/scripts/showTopPagination.html }}
{{#paginationRendered}}
{{> includes/scripts/showTopPagination.html }}
{{/paginationRendered}}
</body>
</html>
8 changes: 7 additions & 1 deletion views/pages/scriptIssueListPage.html
Original file line number Diff line number Diff line change
Expand Up @@ -29,15 +29,19 @@
The script author requests that you use their preferred primary support method when filing an issue. Please consider using that for regular issues.
</div>
{{/script.hasSupport}}
{{#paginationRendered}}
<div class="text-center collapse">
{{{paginationRendered}}}
</div>
{{/paginationRendered}}
<div class="panel panel-default">
{{> includes/discussionList.html }}
</div>
{{#paginationRendered}}
<div class="text-center">
{{{paginationRendered}}}
</div>
{{/paginationRendered}}
</div>
<div class="container-fluid col-sm-4">
{{> includes/searchBarPanel.html }}
Expand All @@ -54,7 +58,9 @@
</div>
{{> includes/footer.html }}
{{> includes/scripts/tableTrLinkScript.html }}
{{> includes/scripts/showTopPagination.html }}
{{#paginationRendered}}
{{> includes/scripts/showTopPagination.html }}
{{/paginationRendered}}
{{> includes/scripts/lazyIconScript.html }}
</body>
</html>
8 changes: 7 additions & 1 deletion views/pages/scriptIssuePage.html
Original file line number Diff line number Diff line change
Expand Up @@ -39,15 +39,19 @@
<div class="container-fluid comments">
<div class="row">
<section class="topic-area list-group">
{{#paginationRendered}}
<div class="text-center collapse">
{{{paginationRendered}}}
</div>
{{/paginationRendered}}
{{#commentList}}
{{> includes/comment.html }}
{{/commentList}}
{{#paginationRendered}}
<div class="text-center">
{{{paginationRendered}}}
</div>
{{/paginationRendered}}
</section>
</div>
</div>
Expand All @@ -62,7 +66,9 @@
<div id="show-reply-form-when-visible"></div>
{{> includes/commentForm.html }}
{{> includes/footer.html }}
{{> includes/scripts/showTopPagination.html }}
{{#paginationRendered}}
{{> includes/scripts/showTopPagination.html }}
{{/paginationRendered}}
{{> includes/scripts/lazyIconScript.html }}
{{#authedUser}}
{{> includes/scripts/markdownEditor.html }}
Expand Down
8 changes: 7 additions & 1 deletion views/pages/scriptListPage.html
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,19 @@
<h2 class="page-heading">
{{pageHeading}}
</h2>
{{#paginationRendered}}
<div class="text-center collapse">
{{{paginationRendered}}}
</div>
{{/paginationRendered}}
<div class="panel panel-default">
{{> includes/scriptList.html }}
</div>
{{#paginationRendered}}
<div class="text-center">
{{{paginationRendered}}}
</div>
{{/paginationRendered}}
</div>
<div class="col-sm-4">
{{> includes/searchBarPanel.html }}
Expand All @@ -30,7 +34,9 @@ <h2 class="page-heading">
</div>
</div>
{{> includes/footer.html }}
{{> includes/scripts/showTopPagination.html }}
{{#paginationRendered}}
{{> includes/scripts/showTopPagination.html }}
{{/paginationRendered}}
{{> includes/scripts/tableTrLinkScript.html }}
{{> includes/scripts/lazyIconScript.html }}
</body>
Expand Down
8 changes: 7 additions & 1 deletion views/pages/userCommentListPage.html
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,11 @@
<div class="container-fluid comments">
<div class="row">
<section class="topic-area list-group">
{{#paginationRendered}}
<div class="text-center collapse">
{{{paginationRendered}}}
</div>
{{/paginationRendered}}
{{#commentList}}
<div class="topic-title row container-fluid">
<ol class="breadcrumb pull-left">
Expand All @@ -36,9 +38,11 @@
</div>
</div>
{{/commentList}}
{{#paginationRendered}}
<div class="text-center">
{{{paginationRendered}}}
</div>
{{/paginationRendered}}
</section>
</div>
</div>
Expand All @@ -51,6 +55,8 @@
</div>
</div>
{{> includes/footer.html }}
{{> includes/scripts/showTopPagination.html }}
{{#paginationRendered}}
{{> includes/scripts/showTopPagination.html }}
{{/paginationRendered}}
</body>
</html>
8 changes: 7 additions & 1 deletion views/pages/userGitHubRepoListPage.html
Original file line number Diff line number Diff line change
Expand Up @@ -11,25 +11,31 @@
<div class="row">
<div class="col-md-8">
<h2><a href="{{{userGitHubRepoListPageUrl}}}" class="script-author">{{githubUser.login}}</a></h2>
{{#paginationRendered}}
<div class="text-center collapse">
{{{paginationRendered}}}
</div>
{{/paginationRendered}}
<div class="list-group">
{{#githubRepoList}}
<a href="{{{userGitHubRepoPageUrl}}}" class="list-group-item">
<h4 class="list-group-item-heading"><i class="octicon octicon-fw octicon-repo"></i> {{full_name}}</h4>
</a>
{{/githubRepoList}}
</div>
{{#paginationRendered}}
<div class="text-center">
{{{paginationRendered}}}
</div>
{{/paginationRendered}}
</div>
<div class="col-md-4">
</div>
</div>
</div>
{{> includes/footer.html }}
{{> includes/scripts/showTopPagination.html }}
{{#paginationRendered}}
{{> includes/scripts/showTopPagination.html }}
{{/paginationRendered}}
</body>
</html>
Loading

0 comments on commit f0a6594

Please sign in to comment.