This repository was archived by the owner on Apr 2, 2019. It is now read-only.
File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 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
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 ;
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 }
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
You can’t perform that action at this time.
0 commit comments