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

Hey man #9

Merged
merged 1 commit into from Aug 31, 2012
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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 );