Created
January 17, 2014 10:44
-
-
Save jrbarron/8471458 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// This class and api was inspired by https://github.com/ptnplanet/backbone-pagination | |
function KinveyPaginator() { | |
return { | |
_paginatorConfig: { | |
itemsPerPage: 10 | |
}, | |
nextPage: function() { | |
this.currentPage++; | |
this.loadPage(this.currentPage); | |
}, | |
previousPage: function() { | |
this.currentPage--; | |
this.loadPage(this.currentPage); | |
}, | |
loadPage: function(page) { | |
this.currentPage = page; | |
var query = this.query || new Kinvey.Query(); | |
var ipp = this._paginatorConfig.itemsPerPage; | |
query.limit(ipp); | |
query.skip(ipp * (page-1)); | |
this.fetch({query: query}); | |
} | |
}; | |
} | |
if (window.define) { | |
define(function(){return KinveyPaginator();}) | |
} else if (window.Kinvey) { | |
window.Kinvey.KinveyPaginator = KinveyPaginator(); | |
} else { | |
window.KinveyPaginator = KinveyPaginator(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment