From 123f5bb46d4932bd31c3b30e0c07511d650145a7 Mon Sep 17 00:00:00 2001 From: "Dustin D. Clark" Date: Tue, 20 Aug 2019 17:41:02 -0700 Subject: [PATCH] Add support for callbacks on error. Fixes #38 --- README.md | 1 + docs/configuration.md | 9 ++++++++- jquery.jscroll.js | 6 +++++- 3 files changed, 14 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index e539889..b677510 100644 --- a/README.md +++ b/README.md @@ -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/). diff --git a/docs/configuration.md b/docs/configuration.md index 1762605..c19fc30 100644 --- a/docs/configuration.md +++ b/docs/configuration.md @@ -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. \ No newline at end of file +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. \ No newline at end of file diff --git a/jquery.jscroll.js b/jquery.jscroll.js index 951b416..3ff271c 100644 --- a/jquery.jscroll.js +++ b/jquery.jscroll.js @@ -25,7 +25,8 @@ nextSelector: 'a:last', contentSelector: '', pagingSelector: '', - callback: false + callback: false, + errorCallback: false } }; @@ -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();