Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

added function that enables users to react to network errors and serv…

…er errors. Also added a function that allows users to tell the autoscroll to stop
  • Loading branch information...
commit 1d6fc4f4f06bc16421e1f1bdd9d7d1da6419a1f0 1 parent d684bfe
@droope droope authored
Showing with 10 additions and 5 deletions.
  1. +10 −5 jquery.esn.autobrowse.js
View
15 jquery.esn.autobrowse.js
@@ -45,6 +45,8 @@
* available on http://github.com/msjolund/jquery-esn-autobrowse. jStorage also
* requires jquery-json: http://code.google.com/p/jquery-json/. Default: false
* * expiration How long to keep cache, in hours. Default: 24
+ * * stopFunction a function that will return true if it is necessary to stop autoscrolling
+ * * onError a function that will be executed on error (HTTP response 500, etc.)
*
*/
(function( $ ){
@@ -62,7 +64,9 @@ jQuery.fn.autobrowse = function (options)
useCache: false,
expiration: 24,
sensitivity: 0,
- postData: null
+ postData: null,
+ stopFunction: function () {},
+ onError: function () {}
};
// flush cache command
@@ -150,12 +154,13 @@ jQuery.fn.autobrowse = function (options)
loader.remove();
// Check if these were the last items to fetch from the server, if so, stop listening
- if (options.itemsReturned(response) == 0 || (options.max != null && currentOffset >= options.max))
+ if (options.itemsReturned(response) == 0 || (options.max != null && currentOffset >= options.max) || options.stopFunction(response) === true)
{
_stopPlugin(scrollCallback)
stopping = true;
}
loading = false;
+
if (!stopping) {
scrollCallback();
}
@@ -173,11 +178,11 @@ jQuery.fn.autobrowse = function (options)
data = options.postData;
}
- jQuery.post(options.url(currentOffset), data, ajaxCallback, "json");
+ jQuery.post(options.url(currentOffset), data, ajaxCallback, "json").error(options.onError);
}
else
{
- jQuery.getJSON(options.url(currentOffset), ajaxCallback);
+ jQuery.getJSON(options.url(currentOffset), ajaxCallback).error(options.onError);
}
}
};
@@ -237,4 +242,4 @@ jQuery.fn.autobrowse = function (options)
}
});
};
-})( jQuery );
+})( jQuery );
Please sign in to comment.
Something went wrong with that request. Please try again.