Skip to content

Commit

Permalink
Update to version 0.9.0
Browse files Browse the repository at this point in the history
See release notes
  • Loading branch information
michaelbromley committed Oct 1, 2015
1 parent 79513cd commit ff5ed48
Show file tree
Hide file tree
Showing 5 changed files with 42 additions and 12 deletions.
6 changes: 3 additions & 3 deletions .versions
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
angular:angular@1.2.24
angularutils:pagination@0.7.0
meteor@1.1.6
underscore@1.0.3
angularutils:pagination@0.9.0
meteor@1.1.9
underscore@1.0.4
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.8.4",
"version": "0.9.0",
"homepage": "https://github.com/michaelbromley/angularUtils/tree/master/src/directives/pagination",
"authors": [
"Michael Bromley <michael@michaelbromley.co.uk>"
Expand Down
40 changes: 35 additions & 5 deletions dirPagination.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,10 +53,10 @@
function dirPaginationCompileFn(tElement, tAttrs){

var expression = tAttrs.dirPaginate;
// regex taken directly from https://github.com/angular/angular.js/blob/master/src/ng/directive/ngRepeat.js#L211
var match = expression.match(/^\s*([\s\S]+?)\s+in\s+([\s\S]+?)(?:\s+track\s+by\s+([\s\S]+?))?\s*$/);
// regex taken directly from https://github.com/angular/angular.js/blob/v1.4.x/src/ng/directive/ngRepeat.js#L339
var match = expression.match(/^\s*([\s\S]+?)\s+in\s+([\s\S]+?)(?:\s+as\s+([\s\S]+?))?(?:\s+track\s+by\s+([\s\S]+?))?\s*$/);

var filterPattern = /\|\s*itemsPerPage\s*:[^|\)]*/;
var filterPattern = /\|\s*itemsPerPage\s*:\s*(.*\(\s*\w*\)|([^\)]*?(?=as))|[^\)]*)/;
if (match[2].match(filterPattern) === null) {
throw 'pagination directive: the \'itemsPerPage\' filter must be set.';
}
Expand Down Expand Up @@ -443,7 +443,7 @@
}
var end;
var start;
if (collection instanceof Array) {
if (angular.isObject(collection)) {
itemsPerPage = parseInt(itemsPerPage) || 9999999999;
if (paginationService.isAsyncMode(paginationId)) {
start = 0;
Expand All @@ -453,13 +453,43 @@
end = start + itemsPerPage;
paginationService.setItemsPerPage(paginationId, itemsPerPage);

return collection.slice(start, end);
if (collection instanceof Array) {
// the array just needs to be sliced
return collection.slice(start, end);
} else {
// in the case of an object, we need to get an array of keys, slice that, then map back to
// the original object.
var slicedObject = {};
angular.forEach(keys(collection).slice(start, end), function(key) {
slicedObject[key] = collection[key];
});
return slicedObject;
}
} else {
return collection;
}
};
}

/**
* Shim for the Object.keys() method which does not exist in IE < 9
* @param obj
* @returns {Array}
*/
function keys(obj) {
if (!Object.keys) {
var objKeys = [];
for (var i in obj) {
if (obj.hasOwnProperty(i)) {
objKeys.push(i);
}
}
return objKeys;
} else {
return Object.keys(obj);
}
}

/**
* This service allows the various parts of the module to communicate and stay in sync.
*/
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.8.4',
version: '0.9.0',
git: 'https://github.com/Urigo/angularUtils-pagination'
});

Expand Down
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
{
"name": "angular-utils-pagination",
"version": "0.8.4",
"version": "0.9.0",
"description": "Magical automatic pagination for anything in AngularJS",
"main": "index.js",
"main": "dirPagination.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
Expand Down

0 comments on commit ff5ed48

Please sign in to comment.