1(function () { 2 const data = reef.signal({ 3 items: [] 4 }, 'compare'); 5 window.compare = { 6 update(updateData) { 7 Object.keys(updateData).forEach(function (key) { 8 data[key] = updateData[key]; 9 }); 10 compare.reloadActive(); 11 }, 12 reload() { 13 fetch('/api/v2/compare').then(function (response) { 14 return response.json() 15 }).then(handleResponse); 16 }, 17 reloadActive() { 18 document.querySelectorAll('[data-compare]').forEach(function (item) { 19 item.classList.remove('is-active'); 20 let contain = false; 21 data.items.forEach(function (checkItem) { 22 if (String(checkItem.id) === item.dataset.compare) { 23 contain = true; 24 } 25 }); 26 if (contain) { 27 item.classList.add('is-active') 28 } 29 }) 30 }, 31 toggle(event, id) { 32 if (id === 'remove-all') { 33 return compare.remove(event, 'all') 34 } 35 let contain = false; 36 data.items.forEach(function (item) { 37 if (String(item.id) === String(id)) { 38 contain = true; 39 } 40 }); 41 if (contain) { 42 return compare.remove(event, id) 43 } else { 44 return compare.add(event, id) 45 } 46 }, 47 add(event, id) { 48 event.target.setAttribute('aria-busy', 'filled') 49 return fetch('/api/v2/compare/add/' + id + '?lang=' + window.translate.lang).then(function (response) { 50 return response.json(); 51 }).then(handleResponse).finally(function () { 52 event.target.removeAttribute('aria-busy') 53 }); 54 }, 55 remove(event, id) { 56 event.target.setAttribute('aria-busy', 'filled') 57 return fetch('/api/v2/compare/remove/' + id + '?lang=' + window.translate.lang).then(function (response) { 58 return response.json(); 59 }).then(handleResponse).finally(function () { 60 event.target.removeAttribute('aria-busy') 61 62 if( event.target.hasAttribute('data-reload') ){ 63 window.location.reload(); 64 } 65 }); 66 }, 67 }; 68 69 function handleResponse(response) { 70 if (response.data && response.data.items != null) { 71 data.items = response.data.items; 72 compare.reloadActive(); 73 if (document.querySelector('.select_mobile_link_item_label')) { 74 document.querySelector('.select_mobile_link_item_label').innerHTML = data.items.length; 75 } 76 } 77 } 78 79 reef.component('[data-badge="compare"]', function () { 80 return data.items.length > 0 ? data.items.length : ''; 81 }, {signals: ['compare']}); 82 83 reef.component('[data-template="compare-header"]', function () { 84 if (data.items.length === 0) { 85 return '<div class="dropdown_content_empty-text">' + (window.translate.compare_empty) + '</div><a class="header_basket_item_button is-disabled">\n' + 86 ' <div class="text">' + window.translate.compare_add + '</div>\n' + 87 '</a>'; 88 } else { 89 const parts = []; 90 const items = []; 91 data.items.forEach(function (item, index) { 92 items.push('<a href="' + window.translate.base.slice(0, -1) + item.url + '" class="dropdown_content_item">\n' + 93 ' <div class="dropdown_content_item_img"><img src="' + item.image + '&size=60x60"></div>\n' + 94 ' <div class="dropdown_content_item_text">\n' + item.name + '</div>' + 95 '</a>'); 96 }) 97 parts.push('<div style="" class="header_favorite_item_final">' 98 + '<a class="header_basket_item_button" href="' + window.translate.base + 'catalog/compare/">\n' + 99 ' <div class="text">' + window.translate.compare_add + '</div>' + '</a>' + '</div>'); 100 return '<div class="dropdown_container_items">' + items.join('') + '</div>' + parts 101 } 102 }, {signals: ['compare']}); 103 reef.component('[data-template="compare-ui"]', function () { 104 if (data.items.length === 0) { 105 return `<div class="header-ui-middle-buttons-item-modal-top__left">${window.translate.compare_empty}</div>`; 106 } 107 const htmlParts = [ 108 `<div class="header-ui-middle-buttons-item-modal__top"> 109 <div class="header-ui-middle-buttons-item-modal-top"> 110 <div class="header-ui-middle-buttons-item-modal-top__left"> 111 ${window.translate.products}
111, <span class="value">${data.items.length}</span> ${window.translate.pcs} 112 </div> 113 <div class="header-ui-middle-buttons-item-modal-top__right"> 114 <a href="#" class="header-ui-middle-buttons-item-modal-top-clear" data-compare="remove-all">${window.translate.cart_clear}</a> 115 </div> 116 </div> 117</div>` 118 ]; 119 htmlParts.push(`<div class="header-ui-middle-buttons-item-modal__body ui-scrollbar"><div class="header-ui-middle-buttons-item-modal-body"><div class="header-ui-middle-buttons-item-modal-body-list">`) 120 data.items.forEach(function (item) { 121 htmlParts.push(`<div class="header-ui-middle-buttons-item-modal-body-list-item"> 122 <a href="${item.url}" 123 class="header-ui-middle-buttons-item-modal-body-list-item__ava"><img 124 src="${item.image}&size=60x60" 125 alt="${item.name}"></a> 126 <a href="${item.url}" class="header-ui-middle-buttons-item-modal-body-list-item__info"> 127 <div class="header-ui-middle-buttons-item-modal-body-list-item__info-title"> 128 ${item.name} 129 </div> 130 </a> 131 <div class="header-ui-middle-buttons-item-modal-body-list-item__button"> 132 <a href="#" class="header-ui-middle-buttons-item-modal-body-list-item-clear" data-compare="${item.id}">${window.translate.icon_trash}</a> 133 </div> 134</div>`) 135 }) 136 htmlParts.push('</div></div></div>') 137 htmlParts.push(`<div class="header-ui-middle-buttons-item-modal__bottom"> 138 <div class="header-ui-middle-buttons-item-modal-bottom"> 139 <div class="header-ui-middle-buttons-item-modal-bottom__button ui-w-100"> 140 <a href="${window.translate.compare_url}" class="ui-btn is-primary ui-w-100">${window.translate.compare_add}</a> 141 </div> 142 </div> 143</div>`) 144 145 return htmlParts.join('') 146 }, {signals: ['compare']}); 147 addEvent(document, 'click', '[data-compare]', function (event) { 148 event.preventDefault(); 149 if (this.dataset.remove) { 150 return compare.remove({target: this}, this.dataset.compare).then(function () { 151 window.location.reload(); 152 }); 153 } 154 compare.toggle({target: this}, this.dataset.compare) 155 }) 156})()
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.