1$(function(){ 2 var compareUrl = shop2.uri + "/compare", ajax; 3 var comparePreviewEvent = new Event(`comparePrevievInit`, {bubbles: true}); 4 5 $(document).on('click', '.gr-compare-btn, .shop-panel-compare a, .go-to-compare-btn, .custom-underlined-link', function(e){ 6 e.preventDefault(); 7 $('.popover-close').click(); 8 getCompare(); 9 }); 10 11 function getCompare () { 12 if (ajax) ajax.abort(); 13 14 ajax = $.ajax({ 15 url: compareUrl, 16 async: true, 17 success: function (data) { 18 var data = $(data).filter('.shop2-compare-container').html(); 19 $('.compare-remodal__body').html(data); 20 21 initCompare(); 22 document.dispatchEvent(comparePreviewEvent); 23 } 24 }); 25 }; 26 27 function initCompare(){ 28 29 $('.compare-remodal .shop2-compare-product-image').lightGallery({ 30 thumbnail: false, 31 download: true, 32 loop: false, 33 counter: false, 34 share: false, 35 getCaptionFromTitleOrAlt: true, 36 selector: 'a' 37 }); 38 39 $('.shop2-compare-table').each(function() { 40 var $this = $(this), 41 relay = $this.find('.shop2-compare-switch a'), 42 options = $this.find('.shop2-compare-data'); 43 44 $this.find('.shop2-compare-delete').on('click', function(e) { 45 var $this = $(this), 46 kind_id = $this.data().id; 47 48 shop2.compare.remove(kind_id, function() { 49 getCompare(); 50 var compareCount = $('.shop2-compare-table').data('compare-count'); 51 52 if (compareCount == 1) { 53 $('.compare-remodal .remodal-close-btn').click(); 54 $('.gr-compare-btn').removeClass('active'); 55 $('.gr-compare-btn .gr-compare-btn-amount').html('0'); 56 57 $('.shop2-compare-table').remove(); 58 setTimeout(function(){ 59 $('#shop2-msg').remove(); 60 }, 170); 61 }; 62 63 $('.product-compare').each(function(){ 64 var $input = $(this).find('input'); 65 var inputVal = $input.val(); 66 67 if (inputVal == kind_id) { 68 $input.click(); 69 } 70 }); 71 72 $('.lpc-product-compare').each(function(){ 73 var $input = $(this).find('input'); 74 var inputVal = $input.val(); 75 76 if (inputVal == kind_id) { 77 $input.click(); 78 } 79 }); 80 81 if (+$('.gr-compare-btn .gr-compare-btn-amount').text() == 0) { 82 $('.gr-compare-btn').removeClass('active'); 83 } else { 84 $('.gr-compare-btn').addClass('active'); 85 }; 86 }); 87 88 return false; 89 }); 90 91 function compareTd(tr) { 92 var td = tr.find('td'), 93 val = $.trim(td.eq(1).html()), 94 differ = false, 95 i = 2, 96 len = td.length; 97 98 if (len <= 2) { 99 return false; 100 } 101 102 for (; i < len; i += 1) { 103 if (val != $.trim(td.eq(i).html())) { 104 differ = true; 105 break; 106 } 107 } 108 109 return differ; 110 } 111 112 relay.on('click', function() { 113 114 var $this = $(this); 115 116 relay.removeClass('shop2-compare-switch-active'); 117 $this.addClass('shop2-compare-switch-active'); 118 119 if ($this.index() === 0) { 120 options.show(); 121 } else { 122 options.each(function() { 123 var $this = $(this), 124 differ = compareTd($this); 125 126 if (differ) { 127 $this.show(); 128 } else { 129 $this.hide(); 130 } 131 }); 132 } 133 134 return false; 135 136 }); 137 138 var productsCount = $this.find('.shop2-compare-header td').length - 1; 139 140 if (productsCount === 1) { 141 options.show(); 142 143 $this.find('.shop2-compare-header2 > .shop2-compare-switch').css({ 144 opacity: hasSame ? '1' : '0', 145 visibility: hasSame ? 'visible' : 'hidden' 146 }); 147 148 return; 149 } 150 151 var hasSame = false;
152 153 options.each(function() { 154 if (!compareTd($(this))) { 155 hasSame = true; 156 return false; 157 } 158 }); 159 160 $this.find('.shop2-compare-header2 > .shop2-compare-switch').css({ 161 opacity: hasSame ? '1' : '0', 162 visibility: hasSame ? 'visible' : 'hidden' 163 }); 164 165 if (hasSame) { 166 relay.eq(1).trigger('click'); 167 } else { 168 relay.eq(0).trigger('click'); 169 } 170 171 }); 172 }; 173});
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.