1 function maybe_load_more_content() {
2 var scroller = this; // element with scroll bars
3 var container; // element that receives new content
4 var src; // url for retrieving content
6 scrollHeight = scroller.scrollHeight || $('body')[0].scrollHeight;
7 if ($(scroller).scrollTop() + $(scroller).height()
10 container = $(this).data('infinite-container');
11 src = $(container).attr('data-infinite-content-href');
15 // Don't start another request until this one finishes
16 $(container).attr('data-infinite-content-href', null);
17 $(container).append('<div class="spinner spinner-32px spinner-h-center infinite-scroller-spinner"></div>');
22 context: {container: container, src: src}}).
23 fail(function(jqxhr, status, error) {
24 if (jqxhr.readyState == 0 || jqxhr.status == 0) {
25 message = "Cancelled."
26 } else if (jqxhr.responseJSON && jqxhr.responseJSON.errors) {
27 message = jqxhr.responseJSON.errors.join("; ");
29 message = "Request failed.";
31 // TODO: report this to the user.
33 $(this.container).attr('data-infinite-content-href', this.src);
35 done(function(data, status, jqxhr) {
36 $(this.container).find(".spinner").detach();
37 $(this.container).append(data.content);
38 $(this.container).attr('data-infinite-content-href', data.next_page_href);
43 on('ready ajax:complete', function() {
44 $('[data-infinite-scroller]').each(function() {
45 var $scroller = $($(this).attr('data-infinite-scroller'));
46 if (!$scroller.hasClass('smart-scroll') &&
47 'scroll' != $scroller.css('overflow-y'))
48 $scroller = $(window);
50 addClass('infinite-scroller').
51 data('infinite-container', this).
52 on('scroll', maybe_load_more_content);