Skip to content
This repository was archived by the owner on Apr 2, 2019. It is now read-only.

Commit 6af43fc

Browse files
committed
Upgrade backbone-pageable to 1.2.3
1 parent 5443ed1 commit 6af43fc

1 file changed

Lines changed: 26 additions & 1 deletion

File tree

assets/js/backbone-pageable.js

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
backbone-pageable 1.2.2
2+
backbone-pageable 1.2.3
33
http://github.com/wyuenho/backbone-pageable
44
55
Copyright (c) 2013 Jimmy Yuen Ho Wong
@@ -65,6 +65,7 @@
6565
var _isUndefined = _.isUndefined;
6666
var _result = _.result;
6767
var ceil = Math.ceil;
68+
var floor = Math.floor;
6869
var max = Math.max;
6970

7071
var BBColProto = Backbone.Collection.prototype;
@@ -303,6 +304,8 @@
303304
state.firstPage :
304305
state.currentPage;
305306

307+
if (!_isArray(models)) models = models ? [models] : [];
308+
306309
if (mode != "server" && state.totalRecords == null && !_isEmpty(models)) {
307310
state.totalRecords = models.length;
308311
}
@@ -848,6 +851,28 @@
848851
return this.fetch(_omit(options, "fetch"));
849852
},
850853

854+
/**
855+
Fetch the page for the provided item offset in server mode, or reset the current page of this
856+
collection to the page for the provided item offset in client mode.
857+
858+
@param {Object} options {@link #getPage} options.
859+
860+
@chainable
861+
@return {XMLHttpRequest|Backbone.PageableCollection} The XMLHttpRequest
862+
from fetch or this.
863+
*/
864+
getPageByOffset: function (offset, options) {
865+
if (offset < 0) {
866+
throw new RangeError("`offset must be > 0`");
867+
}
868+
offset = finiteInt(offset);
869+
870+
var page = floor(offset / this.state.pageSize);
871+
if (this.state.firstPage !== 0) page++;
872+
if (page > this.state.lastPage) page = this.state.lastPage;
873+
return this.getPage(page, options);
874+
},
875+
851876
/**
852877
Overidden to make `getPage` compatible with Zepto.
853878

0 commit comments

Comments
 (0)