1(function (w, $) { 2 const ProductManager = w.ProductManager || {}; 3 4 // Compare list 5 ProductManager.CompareList = (function () { 6 /** 7 * Main settings 8 */ 9 let settings; 10 11 /** 12 * Other settings 13 */ 14 let ajaxLoadingInProgress = true, 15 productsList = []; 16 17 /** 18 * Dom elements 19 */ 20 let $buttons, 21 $mainCart, 22 $mainCartCounter, 23 $cartCounters; 24 25 /** 26 * Main wish list function 27 * 28 * @param settings 29 */ 30 const init = function (settings) { 31 _initVars(settings); 32 33 _loadList(); 34 }; 35 36 /** 37 * Init main variables 38 * 39 * @param listSettings 40 * @private 41 */ 42 const _initVars = function (listSettings) { 43 settings = listSettings; 44 45 $buttons = $(listSettings.buttonIdentifier + '.' + listSettings.loadingClass); 46 $mainCart = $(listSettings.mainCartIdentifier); 47 $mainCartCounter = $(listSettings.mainCartIdentifier).find(listSettings.cartCounterIdentifier); 48 $cartCounters = $(listSettings.cartsIdentifier).find(listSettings.cartCounterIdentifier); 49 }; 50 51 /** 52 * Load list of compre from server 53 * 54 * @private 55 */ 56 const _loadList = function () { 57 ajaxLoadingInProgress = true; 58 59 $.ajax({ 60 url: settings.listUrl, 61 dataType: 'json' 62 }).done(function (data) { 63 for (let i in data.compareList) { 64 if (data.compareList.hasOwnProperty(i)) { 65 productsList.push(data.compareList[i]); 66 } 67 } 68 69 initButtons($buttons); 70 ProductManager.Main.updateCartCounter($mainCartCounter, $cartCounters, productsList.length); 71 }).fail(function (jqXHR, textStatus) { 72 console.log('Request failed: ' + textStatus); 73 }).always(function () { 74 ajaxLoadingInProgress = false; 75 }); 76 }; 77 78 /** 79 * Perform request 80 * 81 * @param button 82 * @private 83 */ 84 const _toggleWishListAjaxAction = function (button) { 85 ajaxLoadingInProgress = true; 86 87 let parentToRemove = button.data('delete-parent-on-remove'), 88 productUid = parseInt(button.data('product-uid')), 89 uri = button.data('ajax-uri'); 90 91 if (parentToRemove) { 92 parentToRemove = button.parents(parentToRemove); 93 } 94 95 button 96 .addClass(settings.loadingClass) 97 .prop('disabled', true); 98 99 $.ajax({ 100 url: uri, 101 dataType: 'json' 102 }).done(function (data) { 103 if (data.success) { 104 button 105 .toggleClass(settings.inListClass) 106 .toggleClass(settings.notInListClass) 107 .removeClass(settings.loadingClass) 108 .prop('disabled', false) 109 .find(settings.compareListButtonSingleView).text(data.inList ? button.data('remove-from-list-text') : button.data('add-to-list-text')) 110 .attr('title', data.inList ? button.data('remove-from-list-text') : button.data('add-to-list-text')); 111 112 if ($mainCart.length === 1 && data.inList) { 113 let itemImg = $('[data-fly-image="' + productUid + '"]'); 114 115 if (itemImg.length === 1 && settings.enableFlyToCartAnimation) { 116 ProductManager.Main.flyToElement(itemImg, $mainCart); 117 } 118 } 119 120 if (parentToRemove.length === 1) { 121 parentToRemove.fadeOut('fast', function () { 122 parentToRemove.remove(); 123 }); 124 } 125 126 ProductManager.Main.updateCartCounter($mainCartCounter, $cartCounters, data.inList ? 1 : -1); 127 128 ProductManager.Messanger.showSuccessMessage(data.message); 129 } 130 ProductManager.Main.trigger( 131 data.inList ? 'PRODUCT_ADDED_TO_COMPARELIST' : 'PRODUCT_REMOVED_FROM_COMPARELIST', 132 { 133 data: { 134 response: data, 135 button: button, 136 productUid: productUid 137 } 138 } 139 ); 140 }).fail(function (jqXHR, textStatus) { 141 ProductManager.Messanger.showErrorMessage('Request failed: ' + textStatus); 142 console.log('Request failed: ' + textStatus); 143 }).always(function () { 144 ajaxLoadingInProgress = false; 145 }); 146 }; 147 148 /** 149 * Init buttons state 150 * 151 * @param $buttons 152 * @public 153 */ 154 const initButtons = function ($buttons) { 155 $buttons.on('click', function (e) { 156 e.preventDefault(); 157 158 if (!ajaxLoadingInProgress) { 159 _toggleWishListAjaxAction($(this)); 160 } 161 }); 162 163 $buttons.each(function () { 164 let button = $(this), 165 productUid = parseInt(button.data('product-uid')), 166 text = '', 167 className = ''; 168 169 if (ProductManager.Main.isInList(productsList.join(), productUid)) { 170 text = button.data('remove-from-list-text'); 171 className = settings.inListClass; 172 } else { 173 text = button.data('add-to-list-text'); 174 className = settings.notInListClass; 175 } 176 177 button 178 .attr('title', text) 179 .removeClass(settings.loadingClass) 180 .removeClass(settings.initializationClass) 181 .addClass(className) 182 .find(settings.compareListButtonSingleView).text(text); 183 }); 184 }; 185 186 /** 187 * Compare list settings 188 * 189 * @return string 190 */ 191 const getSettings = function () { 192 return settings; 193 }; 194 195 return { 196 init: init, 197 initButtons: initButtons, 198 getSettings: getSettings 199 } 200 })(); 201 202 w.ProductManager = ProductManager; 203})(window, $);
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.