The auto-pagination infinite scrolling script has a variable called offset. I want to pass it to the scrollPagination method (for when it’s called again), but I don’t know how to do it.
I need to do this because the offset variable changes inside the afterLoad section, and right now the offset for the contentPage parameter is always 0.
var offset = 0;
$('#stuffhere').scrollPagination({
'contentPage': 'themes/[var.theme]/ajaxcontrols.php?page=products&offset='+offset, // the page where you are searching for results
},
'afterLoad': function(elementsLoaded, offset){ // after loading, some function to animate results and hide a preloader div
offset = offset + [var.homelist]; alert(offset);
}
});
The code sample is trimmed.
Update
Here’s the result I’m getting.

I do know variable scope. I want to pass the variable offset to .scrollPagination({ and just don’t know how to do it. Using .scrollPagination function(offset){ doesn’t work.
Better yet… Use before load, removing the original contentPage string. Otherwise the search will often be duplicated. Example:
Update
You know, I think there’s actually a simpler solution in this case that doesn’t require hacking the plugin or even monkeypatching it:
I just noticed that
afterLoadis called asopts.afterLoad, which in this case should bindthistooptsinside the function.Original Answer
Ok, it looks to me like the URL you intially pass to the ScrollPagination plugin is used for every request, and not exposed externally for you to change in between requests (e.g. in your
afterLoad). You could hack the plugin to allow that, or monkeypatch it with a newloadContent(), e.g.:I’d think about contacting the plugin author to see if they’ll release it under the MIT or Simplified BSD license, so that it can be modified and distributed.