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
7 scrollHeight = scroller.scrollHeight || $('body')[0].scrollHeight;
8 var num_scrollers = $(window).data("arv-num-scrollers");
9 if ($(scroller).scrollTop() + $(scroller).height()
13 for (var i = 0; i < num_scrollers; i++) {
14 $container = $($(this).data('infinite-container'+i));
15 src = $container.attr('data-infinite-content-href');
16 if (!src || !$container.is(':visible'))
19 // Don't start another request until this one finishes
20 $container.attr('data-infinite-content-href', null);
21 spinner = '<div class="spinner spinner-32px spinner-h-center"></div>';
22 if ($(container).is('table,tbody,thead,tfoot')) {
23 // Hack to determine how many columns a new tr should have
24 // in order to reach full width.
25 colspan = $container.closest('table').
26 find('tr').eq(0).find('td,th').length;
29 spinner = ('<tr class="spinner"><td colspan="' + colspan + '">' +
33 $container.append(spinner);
38 context: {container: $container, src: src}}).
40 $(this.container).find(".spinner").detach();
42 fail(function(jqxhr, status, error) {
43 if (jqxhr.readyState == 0 || jqxhr.status == 0) {
44 message = "Cancelled."
45 } else if (jqxhr.responseJSON && jqxhr.responseJSON.errors) {
46 message = jqxhr.responseJSON.errors.join("; ");
48 message = "Request failed.";
50 // TODO: report this to the user.
52 $(this.container).attr('data-infinite-content-href', this.src);
54 done(function(data, status, jqxhr) {
55 $(this.container).append(data.content);
56 $(this.container).attr('data-infinite-content-href', data.next_page_href);
64 on('ready ajax:complete', function() {
65 var num_scrollers = 0;
66 $('[data-infinite-scroller]').each(function() {
67 var $scroller = $($(this).attr('data-infinite-scroller'));
68 if (!$scroller.hasClass('smart-scroll') &&
69 'scroll' != $scroller.css('overflow-y'))
70 $scroller = $(window);
72 addClass('infinite-scroller').
73 data('infinite-container'+num_scrollers, this).
74 on('scroll', maybe_load_more_content);
77 $(window).data("arv-num-scrollers", num_scrollers);