1/************************ AJAX PRODUCT PAGE LOADER ************************/ 2/************************ [email protected] ************************/ 3/********************** пÑовеÑено на ocStore 2.1.x **********************/ 4var pagination_exist = true; 5var button_more = true; 6var top_offset = 100; 7var window_height = 0; 8var product_block_offset = 0; 9 10var product_block = ''; 11var pages_count = 0; 12var pages = []; 13var waiting = false; 14 15function getNextProductPage(pages, pages_count) { 16 if (waiting) return; 17 if (pages_count >= pages.length) return; 18 waiting = true; 19 $('.load_more_wrapper').after('<div id="ajax_loader"><img style="margin-bottom: 30px;" src="/image/ajax_loader.gif" /></div>'); 20 $.ajax({ 21 url: pages[pages_count], 22 type: "GET", 23 data: '', 24 success: function (data) { 25 $data = $(data); 26 27 $('#ajax_loader').remove(); 28 29 // --- ÐÐÐÐÐÐ: ÐÑдÑÐ°Ñ Ñнок ÑоваÑÑв, Ñо пÑилеÑÑли --- 30 var incoming_products = $data.find('.product-thumb').length; 31 if (incoming_products === 0) incoming_products = $data.find('.product-layout').length; 32 if (incoming_products === 0) incoming_products = $data.find('.product-list > div, .product-grid > div').length; 33 34 if ($data) { 35 if ($data.find('.product-list').length > 0) { 36 $(product_block).parent().append($data.find('.product-list').parent().html()); 37 if (product_block == '.product-grid') { $('#grid-view').trigger('click') }; 38 } else { 39 $(product_block).parent().append($data.find('.product-grid').parent().html()); 40 if (product_block == '.product-list') { 41 $('img.lazy-load').lazyload({ 42 effect: "fadeIn", 43 effectspeed: 500, 44 threshold: 1, 45 skip_invisible: true, 46 placeholder: "image/catalog/preloader-100x100.svg" 47 }); 48 $('#list-view').trigger('click'); 49 }; 50 } 51 var mySelect = $("select").customSelect(); 52 $("select.disable-custom-style").customSelect("destroy"); 53 54 if (pagination_exist) { 55 // ФÐÐС: беÑемо .last() Ñоб гаÑанÑовано оновиÑи акÑÐ¸Ð²Ð½Ñ ÐºÐ½Ð¾Ð¿ÐºÑ Ð½Ð° пÑавилÑÐ½Ñ ÑиÑÑÑ 56 var new_pag_html = $data.find('.pagination').last().html(); 57 if (new_pag_html) { 58 $('.pagination').html(new_pag_html); 59 } 60 } 61 } 62 63 waiting = false; 64 65 // --- ÐÐÐÐÐÐ: ХоваÑмо ÐºÐ½Ð¾Ð¿ÐºÑ "ÐÑлÑÑе", ÑкÑо Ñе бÑла оÑÑÐ°Ð½Ð½Ñ Ð¿Ð°ÑÑÑÑ --- 66 if (incoming_products < 15 || incoming_products === 0 || pages_count + 1 >= pages.length) { 67 $('.load_more_wrapper').hide(); 68 } 69 70 }, 71 error: function (data) { 72 console.log(data); 73 waiting = false; 74 } 75 }); 76 console.log('pages_count ' + pages_count); 77 console.log('pages.length ' + pages.length); 78} 79 80function scroll_to_top() { 81 $('html, body').animate({ 82 scrollTop: 0 83 }, 300, function () { 84 $('.arrow_top').remove(); 85 }); 86} 87 88function getProductBlock() { 89 if ($('.product-list').length > 0) { 90 product_block = '.product-list'; 91 } else { 92 product_block = '.product-grid'; 93 } 94 return product_block; 95} 96 97// --- ÐÐÐÐÐÐ: ФÑнкÑÑÑ Ð¿ÐµÑевÑÑки поÑаÑÐºÐ¾Ð²Ð¾Ñ ÐºÑлÑкоÑÑÑ ÑоваÑÑв --- 98function checkInitialProductCount() { 99 product_block = getProductBlock(); 100 if (!product_block || $(product_block).length === 0) return false; 101 102 var current_count = $(product_block).find('.product-thumb').length; 103 if (current_count === 0) current_count = $(product_block).find('.product-layout').length; 104 if (current_count === 0) current_count = $(product_block).find('> div').length; 105 106 // ÐадÑйний поÑÑк акÑÐ¸Ð²Ð½Ð¾Ñ ÑÑоÑÑнки (Ñоб пагÑнаÑÑÑ Ð½Ðµ зникала на 2-й ÑÑоÑÑнÑÑ) 107 var active_text = $('.pagination li.active').text().trim(); 108 var active_page = parseInt(active_text) || 1; 109 110 if (active_page === 1 && current_count > 0 && current_count < 15) { 111 // ТÑлÑки ÑкÑо ми на пеÑÑÑй ÑÑоÑÑнÑÑ Ñ ÑоваÑÑв мало - Ñ Ð¾Ð²Ð°Ñмо вÑе 112 $('.pagination').parent().parent().hide(); 113 $('.load_more_wrapper').hide(); 114 return true; 115 } else { 116 // ЯкÑо ÑоваÑÑв >= 15 ÐÐРми вже на 2-й ÑÑоÑÑнÑÑ - гаÑанÑÑÑмо, Ñо пагÑнаÑÑÑ Ð²Ð¸Ð´Ð¸Ð¼Ð° 117 $('.pagination').parent().parent().show(); 118 } 119 return false;
120} 121 122$(document).ready(function () { 123 window_height = $(window).height(); 124 product_block = getProductBlock(); 125 126 // --- ÐÐÐÐÐÐ: ÐапÑÑк пеÑевÑÑки пÑи заванÑÐ°Ð¶ÐµÐ½Ð½Ñ ÑÑоÑÑнки --- 127 var is_hidden_initially = checkInitialProductCount(); 128 if (is_hidden_initially) { 129 button_more = false; 130 } 131 132 // --- ÐÐÐÐ ÐÐÐÐÐÐÐÐÐÐЯ СТÐÐУ Ð SESSIONSTORAGE --- 133 var currentPath = window.location.pathname; 134 var savedProducts = sessionStorage.getItem('saved_products_' + currentPath); 135 136 if (savedProducts) { 137 $(product_block).parent().html(savedProducts); 138 var savedPagination = sessionStorage.getItem('saved_pagination_' + currentPath); 139 if (savedPagination) { 140 $('.pagination').html(savedPagination); 141 } 142 var savedScroll = sessionStorage.getItem('saved_scroll_' + currentPath); 143 if (savedScroll) { 144 setTimeout(function () { 145 $(window).scrollTop(parseInt(savedScroll)); 146 }, 50); 147 } 148 sessionStorage.removeItem('saved_products_' + currentPath); 149 sessionStorage.removeItem('saved_scroll_' + currentPath); 150 sessionStorage.removeItem('saved_pagination_' + currentPath); 151 } 152 // --- ÐÐÐÐЦЬ ÐÐÐÐУ ÐÐÐÐÐÐÐÐÐÐЯ --- 153 154 var button_more_block = $('#load_more').html(); // 155 var arrow_top = $('#arrow_top'); // 156 if ($(product_block).length > 0) { 157 product_block_offset = $(product_block).offset().top; 158 var href = $('.pagination li').eq(-2).find('a').attr('href'); 159 160 var lastPageLink = $("ul.pagination li:last-child a[href]"); 161 var lastPageUrl = lastPageLink.attr("href"); 162 if (lastPageUrl != undefined) { 163 var pageCount = parseInt(lastPageUrl.substring(lastPageUrl.lastIndexOf("=") + 1)); 164 } else { 165 var pageCount = 0; 166 } 167 168 var TotalPages = pageCount; 169 $('.pagination').each(function () { 170 if (href) { 171 var First_index = $(this).find('li.active span').html(); 172 i = parseInt(First_index) + 1; 173 while (i <= TotalPages) { 174 pages.push(href.substring(0, href.indexOf("page=") + 5) + i); 175 i++; 176 } 177 } 178 }); 179 180 $(window).scroll(function () { 181 if (arrow_top) { 182 if ($(document).scrollTop() > top_offset) { 183 $('#arrow_top').show(); 184 } else { 185 $('#arrow_top').hide(); 186 } 187 } 188 }); 189 190 if (button_more && href) { 191 $('.pagination').first().parent().parent().find('.load_more_wrapper').remove(); 192 $('.pagination').first().parent().parent().append(button_more_block); 193 194 if (!pagination_exist) { 195 $('.pagination').parent().parent().remove(); 196 } else { 197 $('.pagination').parent().parent().find('.col-sm-6.text-right').remove(); 198 } 199 $('.load_more').click(function (event) { 200 $('.product-sl').remove(); 201 event.preventDefault(); 202 if (pages > 0) { 203 204 } 205 getNextProductPage(pages, pages_count); 206 pages_count++; 207 }); 208 } else if (href) { 209 $('.pagination').parent().parent().hide(); 210 $(window).scroll(function () { 211 product_block = getProductBlock(); 212 product_block_height = $(product_block).parent().height(); 213 if (pages.length > 0) { 214 if ((product_block_offset + product_block_height - window_height) < ($(this).scrollTop())) { 215 getNextProductPage(pages, pages_count); 216 pages_count++; 217 } 218 } 219 }); 220 } 221 } 222 223 // --- ÐÐÐÐ ÐÐÐÐ ÐÐÐÐÐЯ СТÐÐУ (ÐÐÐ ÐÐ ÐÐÐÐÐÐ ÐРТÐÐÐÐ ) --- 224 $(document).on('click', '.product-list a, .product-grid a', function (e) { 225 var href = $(this).attr('href'); 226 if (href && href.indexOf('#') === -1 && href.indexOf('javascript') === -1) { 227 var currentPath = window.location.pathname; 228 if ($.fn.customSelect) { 229 $('select').customSelect('destroy'); 230 } 231 sessionStorage.setItem('saved_products_' + currentPath, $(product_block).parent().html()); 232 sessionStorage.setItem('saved_scroll_' + currentPath, $(window).scrollTop()); 233 sessionStorage.setItem('saved_pagination_' + currentPath, $('.pagination').html()); 234 } 235 }); 236 237 // --- ÐÐÐÐÐÐ: ÐÑдÑÑÐµÐ¶ÐµÐ½Ð½Ñ AJAX-ÑÑлÑÑÑÑв --- 238 $(document).ajaxComplete(function (event, xhr, settings) { 239 if (!waiting) { 240 setTimeout(function () { 241 checkInitialProductCount(); 242 }, 300); 243 } 244 }); 245});
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.