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 if ($(scroller).scrollTop() + $(scroller).height()
11 container = $(this).data('infinite-container');
12 src = $(container).attr('data-infinite-content-href');
16 // Don't start another request until this one finishes
17 $(container).attr('data-infinite-content-href', null);
18 spinner = '<div class="spinner spinner-32px spinner-h-center"></div>';
19 if ($(container).is('table,tbody,thead,tfoot')) {
20 // Hack to determine how many columns a new tr should have
21 // in order to reach full width.
22 colspan = $(container).closest('table').
23 find('tr').eq(0).find('td,th').length;
26 spinner = ('<tr class="spinner"><td colspan="' + colspan + '">' +
30 $(container).append(spinner);
35 context: {container: container, src: src}}).
37 $(this.container).find(".spinner").detach();
39 fail(function(jqxhr, status, error) {
40 if (jqxhr.readyState == 0 || jqxhr.status == 0) {
41 message = "Cancelled."
42 } else if (jqxhr.responseJSON && jqxhr.responseJSON.errors) {
43 message = jqxhr.responseJSON.errors.join("; ");
45 message = "Request failed.";
47 // TODO: report this to the user.
49 $(this.container).attr('data-infinite-content-href', this.src);
51 done(function(data, status, jqxhr) {
52 $(this.container).append(data.content);
53 $(this.container).attr('data-infinite-content-href', data.next_page_href);
58 on('ready ajax:complete', function() {
59 $('[data-infinite-scroller]').each(function() {
60 var $scroller = $($(this).attr('data-infinite-scroller'));
61 if (!$scroller.hasClass('smart-scroll') &&
62 'scroll' != $scroller.css('overflow-y'))
63 $scroller = $(window);
65 addClass('infinite-scroller').
66 data('infinite-container', this).
67 on('scroll', maybe_load_more_content);