Skip to content

Commit

Permalink
removed - firstPage and lastPage from range when the `currentPa…
Browse files Browse the repository at this point in the history
…ge` is equals to one of them
  • Loading branch information
renancouto committed Apr 16, 2015
1 parent f3708ab commit 66a6bba
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 6 deletions.
3 changes: 3 additions & 0 deletions HISTORY.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
# pagination-object version history


## 1.1.0
- removed `firstPage` and `lastPage` from `range` when the `currentPage` is equals to one of them

## 1.0.1
- fixed README.md output reference

Expand Down
10 changes: 8 additions & 2 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -118,10 +118,14 @@ Pagination.prototype.getRangeEnd = function () {
* @return {array} [array of range items]
*/
Pagination.prototype.getRange = function () {
var range = [{ page : this.firstPage, isFirst : true, label : this.firstLabel }];
var range = [];
var i = this.rangeStart;
var t = this.rangeEnd;

if (this.firstPage !== this.currentPage) {
range.push({ page : this.firstPage, isFirst : true, label : this.firstLabel });
}

if (this.previousPage) {
range.push({ page : this.previousPage, isPrevious : true, label : this.previousLabel });
}
Expand All @@ -140,7 +144,9 @@ Pagination.prototype.getRange = function () {
range.push({ page : this.nextPage, isNext : true, label : this.nextLabel });
}

range.push({ page : this.lastPage, isLast : true, label : this.lastLabel });
if (this.lastPage !== this.currentPage) {
range.push({ page : this.lastPage, isLast : true, label : this.lastLabel });
}

return range;
};
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "pagination-object",
"version": "1.0.1",
"version": "1.1.0",
"description": "Generate a pagination object to be used on Node.js",
"main": "index.js",
"scripts": {
Expand Down
4 changes: 1 addition & 3 deletions test/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -250,7 +250,6 @@ describe('Pagination Object Tests', function () {
});

assert.deepEqual(pagination.range, [
{ page : 1, isFirst : true, label : '«' },
{ page : 1, isCurrent : true },
{ page : 2 },
{ page : 3 },
Expand Down Expand Up @@ -295,8 +294,7 @@ describe('Pagination Object Tests', function () {
{ page : 3 },
{ page : 4 },
{ page : 5 },
{ page : 6, isCurrent : true },
{ page : 6, isLast : true, label : '»' }
{ page : 6, isCurrent : true }
]);
});

Expand Down

0 comments on commit 66a6bba

Please sign in to comment.