Skip to content

Instantly share code, notes, and snippets.

@anyt
Last active January 2, 2016 12:39
Show Gist options
  • Save anyt/8304684 to your computer and use it in GitHub Desktop.
Save anyt/8304684 to your computer and use it in GitHub Desktop.
// Make sure that autopager plugin is loaded
if ($.autopager) {
if (!autopager_was_initialised) {
autopager_was_initialised = true;
var container = '#courses div.content';
var items_selector = container + ' > .course';
var pager_selector = container + ' > div.item-list ul.pager';
var next_selector = container + ' ' + 'li.pager-next a:first';
var img = '<div id="autopager-ajax-loader"><div class="ajax-loader"></div></div>';
$(pager_selector).hide();
var handle = $.autopager({
appendTo:container,
content:items_selector,
link:next_selector,
page:0,
start:function () {
$(container).after(img);
},
load:function () {
$('div#autopager-ajax-loader').remove();
Drupal.attachBehaviors(this);
}
});
// Trigger autoload if content height is less than doc height already
var prev_content_height = $(container).height();
do {
var last = $(items_selector).filter(':last');
if (last.offset().top + last.height() < $(document).scrollTop() + $(window).height()) {
last = $(items_selector).filter(':last');
handle.autopager('load');
}
else {
break;
}
}
while ($(container).height() > prev_content_height);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment