Skip to content

Commit

Permalink
Update to v0.11.0
Browse files Browse the repository at this point in the history
See release notes
  • Loading branch information
michaelbromley committed Mar 1, 2016
1 parent 98594f3 commit 7c25c68
Show file tree
Hide file tree
Showing 4 changed files with 53 additions and 7 deletions.
3 changes: 2 additions & 1 deletion bower.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "angularUtils-pagination",
"version": "0.10.1",
"version": "0.11.0",
"homepage": "https://github.com/michaelbromley/angularUtils/tree/master/src/directives/pagination",
"authors": [
"Michael Bromley <michael@michaelbromley.co.uk>"
Expand Down Expand Up @@ -29,3 +29,4 @@
"tests"
]
}

53 changes: 49 additions & 4 deletions dirPagination.js
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,9 @@
// Now that we have access to the `scope` we can interpolate any expression given in the paginationId attribute and
// potentially register a new ID if it evaluates to a different value than the rawId.
var paginationId = $parse(attrs.paginationId)(scope) || attrs.paginationId || DEFAULT_ID;
// In case rawId != paginationId we deregister using rawId for the sake of general cleanliness
// before registering using paginationId
paginationService.deregisterInstance(rawId);
paginationService.registerInstance(paginationId);

var repeatExpression = getRepeatExpression(expression, paginationId);
Expand Down Expand Up @@ -102,6 +105,12 @@

// Delegate to the link function returned by the new compilation of the ng-repeat
compiled(scope);

// When the scope is destroyed, we make sure to remove the reference to it in paginationService
// so that it can be properly garbage collected
scope.$on('$destroy', function destroyDirPagination() {
paginationService.deregisterInstance(paginationId);
});
};
}

Expand Down Expand Up @@ -215,11 +224,8 @@

var numberRegex = /^\d+$/;

return {
var DDO = {
restrict: 'AE',
templateUrl: function(elem, attrs) {
return attrs.templateUrl || paginationTemplate.getPath();
},
scope: {
maxSize: '=?',
onPageChange: '&?',
Expand All @@ -229,6 +235,23 @@
link: dirPaginationControlsLinkFn
};

// We need to check the paginationTemplate service to see whether a template path or
// string has been specified, and add the `template` or `templateUrl` property to
// the DDO as appropriate. The order of priority to decide which template to use is
// (highest priority first):
// 1. paginationTemplate.getString()
// 2. attrs.templateUrl
// 3. paginationTemplate.getPath()
var templateString = paginationTemplate.getString();
if (templateString !== undefined) {
DDO.template = templateString;
} else {
DDO.templateUrl = function(elem, attrs) {
return attrs.templateUrl || paginationTemplate.getPath();
};
}
return DDO;

function dirPaginationControlsLinkFn(scope, element, attrs) {

// rawId is the un-interpolated value of the pagination-id attribute. This is only important when the corresponding dir-paginate directive has
Expand Down Expand Up @@ -520,6 +543,10 @@
}
};

this.deregisterInstance = function(instanceId) {
delete instances[instanceId];
};

this.isRegistered = function(instanceId) {
return (typeof instances[instanceId] !== 'undefined');
};
Expand Down Expand Up @@ -573,15 +600,33 @@
function paginationTemplateProvider() {

var templatePath = 'angularUtils.directives.dirPagination.template';
var templateString;

/**
* Set a templateUrl to be used by all instances of <dir-pagination-controls>
* @param {String} path
*/
this.setPath = function(path) {
templatePath = path;
};

/**
* Set a string of HTML to be used as a template by all instances
* of <dir-pagination-controls>. If both a path *and* a string have been set,
* the string takes precedence.
* @param {String} str
*/
this.setString = function(str) {
templateString = str;
};

this.$get = function() {
return {
getPath: function() {
return templatePath;
},
getString: function() {
return templateString;
}
};
};
Expand Down
2 changes: 1 addition & 1 deletion package.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
Package.describe({
name: 'angularutils:pagination',
summary: 'Magical automatic pagination for anything in AngularJS',
version: '0.10.1',
version: '0.11.0',
git: 'https://github.com/michaelbromley/angularUtils-pagination'
});

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": "angular-utils-pagination",
"version": "0.10.1",
"version": "0.11.0",
"description": "Magical automatic pagination for anything in AngularJS",
"main": "index.js",
"scripts": {
Expand Down

0 comments on commit 7c25c68

Please sign in to comment.