templates/application/partial/pagination-script.html.twig line 1

Open in your IDE?
  1. {% if tag is not defined %}
  2.     {% set tag = null %}
  3. {% endif %}
  4. {% if itemsRouteParams is not defined %}
  5.     {% set itemsRouteParams = {} %}
  6. {% endif %}
  7. {% if tag %}
  8.     {% set itemsRouteParams = {tag: tag, ...itemsRouteParams} %}
  9. {% endif %}
  10. <script>
  11.     function initView() {
  12.         $('#pagination a').click(function () {
  13.             let page = $(this).attr('data-page');
  14.             let href = '{{ path(itemsRouteName, itemsRouteParams) }}';
  15.             let query = '';
  16.             if (page > 1) {
  17.                 if (query) {
  18.                     query += '&';
  19.                 }
  20.                 query += 'page=' + page;
  21.             }
  22.             if (query) {
  23.                 query = '?' + query;
  24.             }
  25.             location.href = href + query;
  26.             return false;
  27.         });
  28.         initShowMore();
  29.     }
  30.     initView();
  31.     var busy = false;
  32.     var page = {{ pagination.current }};
  33.     function initShowMore() {
  34.         $('#showMore button').click(function () {
  35.             if (busy) {
  36.                 return false;
  37.             }
  38.             busy = true;
  39.             if (!page) {
  40.                 page = 1;
  41.             }
  42.             page++;
  43.             $(this).html('Загрузка...');
  44.             $.ajax({
  45.                 type: "POST",
  46.                 url: '{{ path(itemsRouteName ~ '-show-more', itemsRouteParams) }}',
  47.                 data: {page: page},
  48.                 success: function (data) {
  49.                     $('#items').html($('#items').html() + data.html);
  50.                     $('#pagination').html(data.paginationHtml);
  51.                     initView();
  52.                     prepareProductBlockCount($('#items'));
  53.                 },
  54.                 dataType: 'json'
  55.             }).fail(function () {
  56.                 alert('Error');
  57.             }).always(function () {
  58.                 busy = false;
  59.             });
  60.             return false;
  61.         });
  62.     }
  63. </script>