Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Merge pull request #9 from droope/master
Added two optional parameters: onError and stopFunction
  • Loading branch information
SamJoan committed Aug 31, 2012
2 parents d684bfe + 1d6fc4f commit e7aff98
Showing 1 changed file with 10 additions and 5 deletions.
15 changes: 10 additions & 5 deletions jquery.esn.autobrowse.js
Expand Up @@ -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( $ ){
Expand All @@ -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
Expand Down Expand Up @@ -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();
}
Expand All @@ -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);
}
}
};
Expand Down Expand Up @@ -237,4 +242,4 @@ jQuery.fn.autobrowse = function (options)
}
});
};
})( jQuery );
})( jQuery );

0 comments on commit e7aff98

Please sign in to comment.