ui/twig/common/lazyloadSearch.html.twig line 1

Open in your IDE?
  1. {% set link = _args.link|default(curpath()) %}
  2. {% set search = _args.search %}
  3. {% set listSelector = _args.listSelector|default('[data-cms-lazyload]') %}
  4. {% set itemSelector = _args.itemSelector|default(listSelector ~ ' [data-cms-lazyload-item]') %}
  5. {% inline_script %}
  6.     <script>
  7.         $(function () {
  8.             $('{{ listSelector|escape('js') }}').infiniteScroll({
  9.                 append: '{{ itemSelector|escape('js') }}',
  10.                 scrollThreshold: 600,
  11.                 prefill: true,
  12.                 history: false,
  13.                 checkLastPage: '{{ listSelector|escape('js') }}',
  14.                 path: function() {
  15.                     var url = URI('{{ link|escape('js') }}'),
  16.                         cql = '{{ search.build(false)|escape('js') }}',
  17.                         pagination = 'pagination:' + (this.loadCount + 1) + 'x' + {{ search.pagination.size }};
  18.                     url
  19.                         .addSearch('cql', (cql + ' ' + pagination))
  20.                         .normalizeSearch();
  21.                     return url.href();
  22.                 },
  23.                 onInit: function() {
  24.                     // plugin tries to load the already loaded (page 0) elements
  25.                     // need to bump this value up to handle the problem
  26.                     this.loadCount = 1;
  27.                 }
  28.             });
  29.             var $body = $('body');
  30.             $body.on('append.infiniteScroll', function(e, response, path, items) {
  31.                 var $bulks = $(items).find('[data-bulk-category]');
  32.                 var categories = [];
  33.                 $bulks.each(function (index, elem) {
  34.                     var $elem = $(elem),
  35.                         cat = $elem.attr('data-bulk-category');
  36.                     if (categories.indexOf(cat) === -1) {
  37.                         categories.push(cat);
  38.                     }
  39.                 });
  40.                 for (var i = 0; i < categories.length; i++) {
  41.                     $body.trigger('campussuite.bulk.' + categories[i] + '.update');
  42.                 }
  43.             });
  44.         });
  45.     </script>
  46. {% endinline %}