diff --git a/README.md b/README.md index b8338d9..6b5645a 100644 --- a/README.md +++ b/README.md @@ -33,4 +33,4 @@ This code is made available under the MIT license, so feel free to use any of th ## License -MIT \ No newline at end of file +MIT diff --git a/src/directives/pagination/README.md b/src/directives/pagination/README.md index 6791ebe..24ac048 100644 --- a/src/directives/pagination/README.md +++ b/src/directives/pagination/README.md @@ -9,6 +9,8 @@ an attribute, drop in your navigation wherever you like, and boom - instant, ful (**Looking for the Angular2 version? [Right here!](https://github.com/michaelbromley/ng2-pagination)**) ## Demo +# Working Plunker +[Updated Plunker](http://plnkr.co/edit/ZU2iAOMf0SrmoAC5cdjU?p=preview) [Here is a working demo on Plunker](http://plnkr.co/edit/Wtkv71LIqUR4OhzhgpqL?p=preview) which demonstrates some cool features such as live-binding the "itemsPerPage" and filtering of the collection. diff --git a/src/directives/pagination/dirPagination.js b/src/directives/pagination/dirPagination.js index a1a7265..6451378 100644 --- a/src/directives/pagination/dirPagination.js +++ b/src/directives/pagination/dirPagination.js @@ -222,7 +222,7 @@ } function dirPaginationControlsTemplateInstaller($templateCache) { - $templateCache.put('angularUtils.directives.dirPagination.template', '
'); + $templateCache.put('angularUtils.directives.dirPagination.template', ''); } function dirPaginationControlsDirective(paginationService, paginationTemplate) { @@ -327,10 +327,21 @@ }); scope.setCurrent = function(num) { - if (paginationService.isRegistered(paginationId) && isValidPageNumber(num)) { - num = parseInt(num, 10); + //quick fix for bug with previous arrow + if(num === 0) return; + + if (paginationService.isRegistered(paginationId) && (isValidPageNumber(num.id) || isValidPageNumber(num))) { + num = isValidPageNumber(num.id) === true ? parseInt(num.id, 10) : parseInt(num, 10); paginationService.setCurrentPage(paginationId, num); } + else { //ellipses were hit + if(num.id == "before-ellipses"){ //before ellipses + paginationService.setCurrentPage(paginationId, scope.pages[1].id - 1); + } + else { //after ellipses + paginationService.setCurrentPage(paginationId, scope.pages[3].id + 1); + } + } }; /** @@ -369,7 +380,7 @@ var page = parseInt(paginationService.getCurrentPage(paginationId)) || 1; scope.pages = generatePagesArray(page, paginationService.getCollectionLength(paginationId), paginationService.getItemsPerPage(paginationId), paginationRange); scope.pagination.current = page; - scope.pagination.last = scope.pages[scope.pages.length - 1]; + scope.pagination.last = scope.pages.last; if (scope.pagination.last < scope.pagination.current) { scope.setCurrent(scope.pagination.last); } else { @@ -426,16 +437,22 @@ var i = 1; while (i <= totalPages && i <= paginationRange) { var pageNumber = calculatePageNumber(i, currentPage, paginationRange, totalPages); - - var openingEllipsesNeeded = (i === 2 && (position === 'middle' || position === 'end')); - var closingEllipsesNeeded = (i === paginationRange - 1 && (position === 'middle' || position === 'start')); - if (ellipsesNeeded && (openingEllipsesNeeded || closingEllipsesNeeded)) { - pages.push('...'); - } else { - pages.push(pageNumber); + + var openingEllipsesNeeded = (i === 1 && (position === 'middle' || position === 'end')); + var closingEllipsesNeeded = (i === paginationRange && (position === 'middle' || position === 'start')); + if (ellipsesNeeded && openingEllipsesNeeded) { + pages.push({"id":"before-ellipses", "display": "..."}); + } + else if(ellipsesNeeded && closingEllipsesNeeded){ + pages.push({"id":"after-ellipses", "display": "..."}); + }else { + pages.push({"id":pageNumber, "display": pageNumber}); } i ++; } + + //set last page value + pages.last = totalPages; return pages; }