{% set link = _args.link|default(curpath()) %}
{% set search = _args.search %}
{% set listSelector = _args.listSelector|default('[data-cms-lazyload]') %}
{% set itemSelector = _args.itemSelector|default(listSelector ~ ' [data-cms-lazyload-item]') %}
{% inline_script %}
<script>
$(function () {
$('{{ listSelector|escape('js') }}').infiniteScroll({
append: '{{ itemSelector|escape('js') }}',
scrollThreshold: 600,
prefill: true,
history: false,
checkLastPage: '{{ listSelector|escape('js') }}',
path: function() {
var url = URI('{{ link|escape('js') }}'),
cql = '{{ search.build(false)|escape('js') }}',
pagination = 'pagination:' + (this.loadCount + 1) + 'x' + {{ search.pagination.size }};
url
.addSearch('cql', (cql + ' ' + pagination))
.normalizeSearch();
return url.href();
},
onInit: function() {
// plugin tries to load the already loaded (page 0) elements
// need to bump this value up to handle the problem
this.loadCount = 1;
}
});
var $body = $('body');
$body.on('append.infiniteScroll', function(e, response, path, items) {
var $bulks = $(items).find('[data-bulk-category]');
var categories = [];
$bulks.each(function (index, elem) {
var $elem = $(elem),
cat = $elem.attr('data-bulk-category');
if (categories.indexOf(cat) === -1) {
categories.push(cat);
}
});
for (var i = 0; i < categories.length; i++) {
$body.trigger('campussuite.bulk.' + categories[i] + '.update');
}
});
});
</script>
{% endinline %}