Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

enable using $.ajax instead of load() using a callback #62

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,8 @@ $('.jscroll').jscroll({
* `contentSelector ('')` - A convenience selector for loading only part of the content in the response for the next set of content. This selector will be ignored if left blank and will apply the entire response to the DOM.
* `pagingSelector ('')` - Optionally define a selector for your paging controls so that they will be hidden, instead of just hiding the next page link.
* `callback (false)` - Optionally define a callback function to be called after a set of content has been loaded.
* `loadFunc (null)` - Optionally define an alternate loading function (the default being jQuery.load). Use this to load data
e.g. using POST instead of GET, or AJAX with data that is not known at the time of the last page load. The callback expects the target DOM element to be `this` (as in load()), so please use: `callback.call(target, ...)`, and not just `callback(...)`.

For more information on the `contentSelector` option and how it loads a response fragment, see the [jQuery documentation for the .load() method](http://api.jquery.com/load/).

Expand All @@ -56,4 +58,4 @@ In lieu of a formal styleguide, take care to maintain the existing coding style.
## LICENSES:

* MIT: http://www.opensource.org/licenses/mit-license.php
* GPL-2.0: http://www.gnu.org/licenses/gpl-2.0.html
* GPL-2.0: http://www.gnu.org/licenses/gpl-2.0.html
12 changes: 10 additions & 2 deletions jquery.jscroll.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
nextSelector: 'a:last',
contentSelector: '',
pagingSelector: '',
loadFunc: null, // function (jscrollData, domTarget, on_complete) { domTarget.html("arbitrary content"); on_complete.call(domTarget, success ? null : "error"); }
callback: false
}
};
Expand Down Expand Up @@ -142,6 +143,10 @@
}
},

_defaultLoadFunc = function (data, target, callback) {
target.load(data.nextHref, function (r, status) { $.proxy(callback, target)(status); });
},

// Load the next set of content, if available
_load = function() {
var $inner = $e.find('div.jscroll-inner').first(),
Expand All @@ -152,8 +157,11 @@
.children('.jscroll-added').last()
.html('<div class="jscroll-loading">' + _options.loadingHtml + '</div>');

var loadFunc = _options.loadFunc || _defaultLoadFunc;
return $e.animate({scrollTop: $inner.outerHeight()}, 0, function() {
$inner.find('div.jscroll-added').last().load(data.nextHref, function(r, status) {
loadFunc(data,
$inner.find('div.jscroll-added').last(),
function(status) {
if (status === 'error') {
return _destroy();
}
Expand Down Expand Up @@ -216,4 +224,4 @@
});
};

})(jQuery);
})(jQuery);
2 changes: 1 addition & 1 deletion jquery.jscroll.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.