diff --git a/bower.json b/bower.json index 16c16d2..36cc152 100644 --- a/bower.json +++ b/bower.json @@ -1,6 +1,6 @@ { "name": "angularUtils-pagination", - "version": "0.3.2", + "version": "0.4.0", "homepage": "https://github.com/michaelbromley/angularUtils/tree/master/src/directives/pagination", "authors": [ "Michael Bromley " diff --git a/dirPagination.js b/dirPagination.js index 70372fc..79549a4 100644 --- a/dirPagination.js +++ b/dirPagination.js @@ -20,7 +20,6 @@ * Config */ var moduleName = 'angularUtils.directives.dirPagination'; - var templatePath = 'directives/pagination/dirPagination.tpl.html'; /** * Module @@ -34,6 +33,7 @@ } module.directive('dirPaginate', ['$compile', '$parse', '$timeout', 'paginationService', function($compile, $parse, $timeout, paginationService) { + return { terminal: true, multiElement: true, @@ -103,8 +103,10 @@ }; }]); - module.directive('dirPaginationControls', ['paginationService', function(paginationService) { + module.directive('dirPaginationControls', ['paginationService', 'paginationTemplate', function(paginationService, paginationTemplate) { + var numberRegex = /^\d+$/; + /** * Generate an array of page numbers (or the '...' string) which is used in an ng-repeat to generate the * links used in pagination @@ -177,13 +179,14 @@ return { restrict: 'AE', templateUrl: function(elem, attrs) { - return attrs.templateUrl || templatePath; + return attrs.templateUrl || paginationTemplate.getPath(); }, scope: { maxSize: '=?', onPageChange: '&?' }, link: function(scope, element, attrs) { + var paginationId; paginationId = attrs.paginationId || '__default'; if (!scope.maxSize) { scope.maxSize = 9; } @@ -209,6 +212,14 @@ generatePagination(); } }); + + scope.$watch(function() { + return (paginationService.getItemsPerPage(paginationId)); + }, function(current, previous) { + if (current != previous) { + goToPage(scope.pagination.current); + } + }); scope.$watch(function() { return paginationService.getCurrentPage(paginationId); @@ -255,6 +266,7 @@ }]); module.filter('itemsPerPage', ['paginationService', function(paginationService) { + return function(collection, itemsPerPage, paginationId) { if (typeof (paginationId) === 'undefined') { paginationId = '__default'; @@ -282,6 +294,7 @@ }]); module.service('paginationService', function() { + var instances = {}; var lastRegisteredInstance; @@ -336,4 +349,21 @@ return instances[instanceId].asyncMode; }; }); -})(); + + module.provider('paginationTemplate', function() { + + var templatePath = 'directives/pagination/dirPagination.tpl.html'; + + this.setPath = function(path) { + templatePath = path; + }; + + this.$get = function() { + return { + getPath: function() { + return templatePath; + } + }; + }; + }); +})(); \ No newline at end of file