templates/ContentBlock/block.html.twig line 1

Open in your IDE?
  1. {% set aParams = aParams is defined ? aParams : {} %}
  2. {% if aParams.results_template is not defined %}
  3.     {% set aParams = aParams|merge({'results_template': 'ContentBlock/results.html.twig'}) %}
  4. {% endif %}
  5. {% if aParams.pagination_template is not defined %}
  6.     {% set aParams = aParams|merge({'pagination_template': 'ContentBlock/pagination.html.twig'}) %}
  7. {% endif %}
  8. {% if aParams.preloader_template is not defined %}
  9.     {% set aParams = aParams|merge({'preloader_template': 'ContentBlock/preloaders/dots.html.twig'}) %}
  10. {% endif %}
  11. {% if aParams.page is not defined %}
  12.     {% set aParams = aParams|merge({'page': 1}) %}
  13. {% endif %}
  14. {% if aParams.container_id is not defined %}
  15.     {% set aParams = aParams|merge({'container_id': random()}) %}
  16. {% endif %}
  17. {% if aParams.ajax_pagination_callback is not defined %}
  18.     {% set aParams = aParams|merge({'ajax_pagination_callback': false}) %}
  19. {% endif %}
  20. {% if aParams.initial_load is not defined %}
  21.     {% set aParams = aParams|merge({'initial_load': true}) %}
  22. {% endif %}
  23. {% if aParams.reverse_results is not defined %}
  24.     {% set aParams = aParams|merge({'reverse_results': false}) %}
  25. {% endif %}
  26. {% if aParams.infinite_scroll is not defined %}
  27.     {% set aParams = aParams|merge({'infinite_scroll': false}) %}
  28. {% endif %}
  29. {% if aParams.infinite_scroll %}
  30.     {% set aParams = aParams|merge({'ajax_pagination': true}) %}
  31.     {% set aParams = aParams|merge({'show_pagination': true}) %}
  32.     {% if aParams.auto_scroll_top is defined %}
  33.         {% set aParams = aParams|merge({'auto_scroll_top': aParams.auto_scroll_top}) %}
  34.     {% else %}
  35.         {% set aParams = aParams|merge({'auto_scroll_top': false}) %}
  36.     {% endif %}
  37. {% else %}
  38.     {% if aParams.ajax_pagination is defined %}
  39.         {% set aParams = aParams|merge({'show_pagination': true}) %}
  40.         {# 'auto_scroll_top': can be FALSE or the amount of pixels to add to the offset #}
  41.         {% if aParams.auto_scroll_top is defined %}
  42.             {% set aParams = aParams|merge({'auto_scroll_top': aParams.auto_scroll_top}) %}
  43.         {% else %}
  44.             {% set aParams = aParams|merge({'auto_scroll_top': 100}) %}
  45.         {% endif %}
  46.     {% endif %}
  47. {% endif %}
  48. {% set aParams = aParams.container_id is defined ? aParams|merge({'container_id': aParams.container_id}) : aParams|merge({'container_id': random()}) %}
  49. {% set data_pagination = {
  50.     'ajax_pagination': aParams.ajax_pagination is defined and aParams.ajax_pagination ? true : false,
  51.     'auto_scroll_top': aParams.auto_scroll_top is defined ? aParams.auto_scroll_top : false,
  52.     'ajax_pagination_callback': aParams.ajax_pagination_callback
  53. } %}
  54. <div class="_xlabs_results_wrapper {{ aParams.infinite_scroll ? '_iscroll' : '' }} {{ aParams.initial_load ? '_iload' : '' }} {{ aParams.results_wrapper_class is defined ? aParams.results_wrapper_class : '' }}" data-container-id="{{ aParams.container_id }}" data-ajax-path="{{ path('results_pagination') }}" data-ajax-params="{{ aParams|json_encode() }}" data-original-params="{{ aParams|json_encode() }}" data-pagination="{{ data_pagination|json_encode() }}">
  55.     <div class="_xlabs_results">
  56.         {% if aParams.initial_load %}
  57.             {{ render(controller('App\\Controller\\ContentBlockController::renderResults', {
  58.                 'aParams': aParams
  59.             })) }}
  60.         {% endif %}
  61.     </div>
  62.     <div class="preloader text-center my-4 d-none">{% include aParams.preloader_template %}</div>
  63.     <div class="_goTop btn btn-primary position-fixed bottom-0 end-0 m-3 d-none"><i class="fas fa-arrow-up"></i></div>
  64. </div>
  65. <script>
  66.     {% if aParams.ajax_pagination is defined and aParams.ajax_pagination %}
  67.         // Pagination buttons
  68.         {#
  69.         $(document).on('click', '[data-container-id="{{ aParams.container_id }}"] ._xlabs_results .pageBtn', function(e){
  70.             e.preventDefault();
  71.             let btn = $(this);
  72.             let aParams_container = $('[data-container-id="{{ aParams.container_id }}"]');
  73.             let results = aParams_container.resultsContainer();
  74.             results.setParam('page', btn.attr('data-page'));
  75.             results.reload(false, function(){
  76.                 {% if aParams.auto_scroll_top %}
  77.                     //$('[data-container-id="{{ aParams.container_id }}"] ._xlabs_results').get(0).scrollIntoView();
  78.                     $('html, body').animate({scrollTop: $('[data-container-id="{{ aParams.container_id }}"] ._xlabs_results').offset().top - {{ aParams.auto_scroll_top }}}, 100);
  79.                 {% endif %}
  80.                 {% if aParams.ajax_pagination_callback %}
  81.                     if(typeof {{ aParams.ajax_pagination_callback }} === 'function')
  82.                     {
  83.                         {{ aParams.ajax_pagination_callback }}();
  84.                     }
  85.                 {% endif %}
  86.             });
  87.         });
  88.         #}
  89.         /*function findContent()
  90.         {
  91.             // create form and submit it to send post parameters
  92.             let aParams_container = $('[data-container-id="{{ aParams.container_id }}"]');
  93.             let aParams = JSON.parse(aParams_container.attr('data-ajax-params'));
  94.             let form = $('<form />');
  95.             //if(!href)
  96.             //{
  97.             //    href = getCleanURI();
  98.             //    if(aParams.search_terms)
  99.             //    {
  100.             //        href += '?s=' + aParams.search_terms;
  101.             //    }
  102.             //}
  103.             form.attr({
  104.                 action: href,
  105.                 method: 'post',
  106.                 enctype: 'multipart/form-data'
  107.             }).css('display', 'none');
  108.             $('body').append(form);
  109.             //let form_data = new FormData(form.get(0));
  110.             //form_data.append('aParams', JSON.stringify(aParams));
  111.             form.append($('<input/>', {
  112.                 type: 'hidden',
  113.                 name: 'aParams',
  114.                 value: JSON.stringify(aParams)
  115.             }));
  116.             form.submit();
  117.         }*/
  118.     {% endif %}
  119. </script>