Skip to content

Commit

Permalink
Update to v0.4.0
Browse files Browse the repository at this point in the history
See release notes for details
  • Loading branch information
michaelbromley committed Nov 20, 2014
1 parent 5f3b6ec commit 9c2ae9e
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 5 deletions.
2 changes: 1 addition & 1 deletion bower.json
Original file line number Diff line number Diff line change
@@ -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 <michael@michaelbromley.co.uk>"
Expand Down
38 changes: 34 additions & 4 deletions dirPagination.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
* Config
*/
var moduleName = 'angularUtils.directives.dirPagination';
var templatePath = 'directives/pagination/dirPagination.tpl.html';

/**
* Module
Expand All @@ -34,6 +33,7 @@
}

module.directive('dirPaginate', ['$compile', '$parse', '$timeout', 'paginationService', function($compile, $parse, $timeout, paginationService) {

return {
terminal: true,
multiElement: true,
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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; }
Expand All @@ -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);
Expand Down Expand Up @@ -255,6 +266,7 @@
}]);

module.filter('itemsPerPage', ['paginationService', function(paginationService) {

return function(collection, itemsPerPage, paginationId) {
if (typeof (paginationId) === 'undefined') {
paginationId = '__default';
Expand Down Expand Up @@ -282,6 +294,7 @@
}]);

module.service('paginationService', function() {

var instances = {};
var lastRegisteredInstance;

Expand Down Expand Up @@ -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;
}
};
};
});
})();

0 comments on commit 9c2ae9e

Please sign in to comment.