1// ÐинамиÑеÑкое обновление иконки ÑÑÐ°Ð²Ð½ÐµÐ½Ð¸Ñ 2(function() { 3 'use strict'; 4 5 function updateCompareIcon() { 6 var compareCol = document.getElementById('compare-header-col'); 7 8 // ÐагÑÑжаем header ÑеÑез AJAX 9 fetch(window.location.href) 10 .then(function(response) { return response.text(); }) 11 .then(function(html) { 12 var parser = new DOMParser(); 13 var doc = parser.parseFromString(html, 'text/html'); 14 var newCompareCol = doc.getElementById('compare-header-col'); 15 16 // ÐбновлÑем оÑновной Ñ ÐµÐ´ÐµÑ 17 if (newCompareCol) { 18 // ÐÑÑÑ ÑоваÑÑ - показÑваем/обновлÑем 19 if (compareCol && compareCol.parentNode) { 20 compareCol.outerHTML = newCompareCol.outerHTML; 21 } else if (!compareCol) { 22 // ÐобавлÑем новÑй блок 23 var searchCol = document.querySelector('.col-search'); 24 if (searchCol && searchCol.nextElementSibling) { 25 searchCol.parentNode.insertBefore(newCompareCol, searchCol.nextElementSibling); 26 } 27 } 28 } else { 29 // ÐÐµÑ ÑоваÑов - ÑдалÑем блок 30 if (compareCol && compareCol.parentNode) { 31 compareCol.remove(); 32 } 33 } 34 35 // ÐбновлÑем мобилÑное Ð¼ÐµÐ½Ñ (.nav.js-sticky) 36 var mobileNav = document.querySelector('.nav.js-sticky'); 37 var newMobileNav = doc.querySelector('.nav.js-sticky'); 38 39 if (mobileNav && newMobileNav) { 40 // ÐÐ°Ñ Ð¾Ð´Ð¸Ð¼ Ð¸ÐºÐ¾Ð½ÐºÑ ÑÑÐ°Ð²Ð½ÐµÐ½Ð¸Ñ Ð² мобилÑном Ð¼ÐµÐ½Ñ 41 var mobileCompareIcon = mobileNav.querySelector('#compare-icon-header'); 42 var newMobileCompareIcon = newMobileNav.querySelector('#compare-icon-header'); 43 44 if (newMobileCompareIcon) { 45 if (mobileCompareIcon && mobileCompareIcon.parentNode) { 46 // ÐбновлÑем ÑÑÑеÑÑвÑÑÑÑÑ Ð¸ÐºÐ¾Ð½ÐºÑ 47 mobileCompareIcon.outerHTML = newMobileCompareIcon.outerHTML; 48 } else if (!mobileCompareIcon) { 49 // ÐобавлÑем новÑÑ Ð¸ÐºÐ¾Ð½ÐºÑ Ð² мобилÑное Ð¼ÐµÐ½Ñ 50 var ctrlBlock = mobileNav.querySelector('.ctrl'); 51 if (ctrlBlock) { 52 // ÐÑÑавлÑем пеÑед пеÑвÑм ÑлеменÑом в .ctrl 53 ctrlBlock.insertBefore(newMobileCompareIcon, ctrlBlock.firstChild); 54 } 55 } 56 } else if (mobileCompareIcon && mobileCompareIcon.parentNode) { 57 // УдалÑем иконкÑ, еÑли Ð½ÐµÑ ÑоваÑов 58 mobileCompareIcon.remove(); 59 } 60 } 61 }); 62 } 63 64 // ÐеÑÐµÑ Ð²Ð°ÑÑваем AJAX оÑвеÑÑ OpenCart 65 var originalOpen = XMLHttpRequest.prototype.open; 66 XMLHttpRequest.prototype.open = function(method, url) { 67 this.addEventListener('load', function() { 68 // ТолÑко Ð´Ð»Ñ Ð´Ð¾Ð±Ð°Ð²Ð»ÐµÐ½Ð¸Ñ/ÑÐ´Ð°Ð»ÐµÐ½Ð¸Ñ Ð² ÑÑавнение 69 if ((url.indexOf('product/compare/add') !== -1 || url.indexOf('account/compare/add') !== -1) || 70 (url.indexOf('compare') !== -1 && url.indexOf('remove') !== -1)) { 71 setTimeout(updateCompareIcon, 300); 72 } 73 }); 74 originalOpen.apply(this, arguments); 75 }; 76})();
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.