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

Add support for callbacks on error. #169

Open
wants to merge 1 commit 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
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ $('.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.
* `errorCallback (false)` - Optionally define a callback function to be called after an AJAX failure occurs. This can be useful to clear the loading HTML.

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

Expand Down
9 changes: 8 additions & 1 deletion docs/configuration.md
Original file line number Diff line number Diff line change
Expand Up @@ -70,4 +70,11 @@ Optionally define a selector for your paging controls so that they will be hidde
- Type: `Function|Boolean`
- Default: `false`

Optionally define a callback function to be called after a set of content has been loaded.
Optionally define a callback function to be called after a set of content has been loaded.

## errorCallback

- Type: `Function|Boolean`
- Default: `false`

Optionally define a callback function to be called after an AJAX failure occurs. This can be useful to clear the loading HTML.
6 changes: 5 additions & 1 deletion jquery.jscroll.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,8 @@
nextSelector: 'a:last',
contentSelector: '',
pagingSelector: '',
callback: false
callback: false,
errorCallback: false
}
};

Expand Down Expand Up @@ -162,6 +163,9 @@
var nextHref = data.nextHref;
$inner.find('div.jscroll-added').last().load(nextHref, function(r, status) {
if (status === 'error') {
if (_options.errorCallback) {
_options.errorCallback();
}
return _destroy();
}
var $next = $(this).find(_options.nextSelector).first();
Expand Down