1jQuery(function($){ 2 "use strict"; 3 4 var load_more_class = 'ts-shop-load-more'; 5 var selector = { 6 pagination: '.woocommerce-pagination' 7 ,pagination_button: '.woocommerce-pagination a' 8 ,next_button: '.woocommerce-pagination a.next' 9 ,products_container: '#main-content .main-products div.products' 10 ,product_item: 'section.product' 11 ,breadcrumb_container: '.breadcrumbs-container' 12 ,result_count: '.ts-shop-result-count' 13 ,woo_result_count: '.woocommerce-result-count' 14 ,load_more_wrapper: '.' + load_more_class 15 ,load_more_button: '.' + load_more_class + ' .load-more' 16 }; 17 18 var product_is_loading = false; 19 var loading_type = typeof druco_params != 'undefined'?druco_params.shop_loading_type:'default'; 20 21 if( loading_type != 'ajax-pagination' ){ 22 if( $(selector.next_button).length == 0 ){ 23 return; 24 } 25 /* Hide pagination */ 26 $(selector.pagination).hide(); 27 } 28 29 if( 'scrollRestoration' in history ){ 30 history.scrollRestoration = 'manual'; 31 } 32 33 switch( loading_type ){ 34 case 'infinity-scroll': 35 $(window).on('scroll', function(){ 36 if( product_is_loading ){ 37 return; 38 } 39 var product_bottom = $(selector.products_container).offset().top + $(selector.products_container).height() - 100; 40 var window_bottom = $(window).scrollTop() + $(window).height(); 41 if( product_bottom < window_bottom ){ 42 ts_load_next_page(); 43 } 44 }); 45 break; 46 case 'load-more-button': 47 $(document).on('click', selector.load_more_button, function(){ 48 if( product_is_loading ){ 49 return; 50 } 51 ts_load_next_page(); 52 }); 53 break; 54 default: /* Ajax Pagination */ 55 $(document).on('click', selector.pagination_button, function(e){ 56 e.preventDefault(); 57 if( product_is_loading ){ 58 return; 59 } 60 var href = $(this).attr('href'); 61 var speed = Math.round( $(selector.products_container).height() / 4 ); 62 $('html, body').animate({scrollTop: ts_get_scroll_top_position()}, speed).promise().done(function(){ 63 if( history.pushState ){ 64 history.pushState(null, null, href); 65 } 66 ts_load_next_page('replace', href); 67 }); 68 }); 69 70 $(window).on('popstate', function(){ 71 setTimeout(function(){ 72 $('html, body').animate({scrollTop: ts_get_scroll_top_position()}, 500).promise().done(function(){ 73 ts_load_next_page('replace', location.href); 74 }); 75 }); 76 }); 77 } 78 79 function ts_get_scroll_top_position(){ 80 var scroll_top = $('.before-loop-wrapper').offset().top; 81 scroll_top -= $('#wpadminbar').length > 0?$('#wpadminbar').height():0; 82 scroll_top -= $('.is-sticky .header-sticky').length > 0?$('.is-sticky .header-sticky').height():0; 83 return scroll_top; 84 } 85 86 function ts_load_next_page( action, next_page_href ){ 87 if( typeof action == 'undefined' ){ 88 var action = 'append'; 89 } 90 if( typeof next_page_href == 'undefined' ){ 91 var next_page_href = ts_get_next_page_href(); 92 } 93 if( !next_page_href ){ 94 return; 95 } 96 97 product_is_loading = true; 98 99 /* Add loading */ 100 $(selector.load_more_button).addClass('loading'); 101 $(selector.products_container).addClass('loading'); 102 103 $.get(next_page_href, function(data){ 104 var new_page = $('<div>' + data + '</div>'); 105 new_page.find(selector.product_item).addClass('hidden-item').hide(); 106 var products = new_page.find(selector.products_container).html(); 107 if( action == 'append' ){ 108 $(selector.products_container).append(products); 109 } 110 else{ 111 $(selector.products_container).html(products); 112 $(selector.breadcrumb_container).html( new_page.find(selector.breadcrumb_container).html() ); 113 document.title = new_page.find('title').html(); 114 } 115 $(selector.product_item + '.hidden-item').removeClass('hidden-item').fadeIn(1000); 116 117 $(selector.result_count).html( new_page.find(selector.result_count).html() ); 118 $(selector.woo_result_count).html( new_page.find(selector.woo_result_count).html() ); 119 120 /* Lazy Load */ 121 $(window).trigger('ts_lazy_load'); 122 123 $(selector.pagination).replaceWith( new_page.find(selector.pagination) ); 124 if( action == 'append' ){ 125 $(selector.pagination).hide(); 126 if( !ts_get_next_page_href() ){ 127 $(selector.load_more_wrapper).remove(); 128 } 129 } 130 131 product_is_loading = false;
132 $(selector.load_more_button).removeClass('loading'); 133 $(selector.products_container).removeClass('loading'); 134 135 $(document).trigger('ts_shop_load_more_end', [loading_type]); 136 }); 137 } 138 139 function ts_get_next_page_href(){ 140 if( $(selector.next_button).length > 0 ){ 141 return $(selector.next_button).attr('href'); 142 } 143 return ''; 144 } 145});
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.