From fdb7d278796389a194edb7c02f71880183e12549 Mon Sep 17 00:00:00 2001 From: Anthony Nemitz Date: Sat, 18 Aug 2012 19:41:26 -0700 Subject: [PATCH 1/2] increased configurability --- lib/infiniScroll.js | 27 ++++++++++++++++++++------- 1 file changed, 20 insertions(+), 7 deletions(-) diff --git a/lib/infiniScroll.js b/lib/infiniScroll.js index f2dac00..5fe7eec 100644 --- a/lib/infiniScroll.js +++ b/lib/infiniScroll.js @@ -21,15 +21,20 @@ error: function(){ }, onFetch: function(){ }, target: $(window), - param: "until", - extraParams: {}, pageSizeParam: "page_size", - untilAttr: "id", pageSize: pageSize, + includePageSize: true, + offsetParam: "offset", + includeOffset: false, + pageParam: "page", + param: "until", + untilAttr: "id", + includeUntil: true, scrollOffset: 100, add: true, strict: false, - includePage: false + includePage: false, + extraParams: {} }); var initialize = function() { @@ -100,12 +105,20 @@ function buildQueryParams(model) { var params = { }; - params[self.options.param] = typeof(model[self.options.untilAttr]) === "function" ? model[self.options.untilAttr]() : model.get(self.options.untilAttr); + if (self.options.includeUntil) { + params[self.options.param] = typeof(model[self.options.untilAttr]) === "function" ? model[self.options.untilAttr]() : model.get(self.options.untilAttr); + } - params[self.options.pageSizeParam] = self.options.pageSize + if (self.options.includePageSize) { + params[self.options.pageSizeParam] = self.options.pageSize + } if (self.options.includePage) { - params["page"] = page + 1; + params[self.options.pageParam] = page + 1; + } + + if (self.options.includeOffset) { + params[self.options.offsetParam] = (page + 1) * self.options.pageSize; } return params; From ccf17af88304515b9e0513ef9b27f7885b516c1f Mon Sep 17 00:00:00 2001 From: Anthony Nemitz Date: Mon, 20 Aug 2012 12:25:35 -0700 Subject: [PATCH 2/2] reset internal scrolling vars on collection reset --- lib/infiniScroll.js | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/lib/infiniScroll.js b/lib/infiniScroll.js index 5fe7eec..f1a00f3 100644 --- a/lib/infiniScroll.js +++ b/lib/infiniScroll.js @@ -39,12 +39,17 @@ var initialize = function() { $target = $(self.options.target); - fetchOn = true; - page = 1; - + self.reset(); $target.on("scroll", self.watchScroll); + self.collection.on('reset', self.reset); }; + self.reset = function() { + page = 1; + prevScrollY = 0; + self.enableFetch(); + }, + self.destroy = function() { $target.off("scroll", self.watchScroll); };