1'use strict'; 2 3function BitrixSmallCart(){} 4 5BitrixSmallCart.prototype = { 6 7 activate: function () 8 { 9 this.cartElement = BX(this.cartId); 10 this.setCartBodyClosure = this.closure('setCartBody'); 11 BX.addCustomEvent(window, 'OnBasketChange', this.closure('refreshCart', {})); 12 }, 13 14 closure: function (fname, data) 15 { 16 var obj = this; 17 return data 18 ? function(){ obj[fname](data); } 19 : function(arg1){ obj[fname](arg1); }; 20 }, 21 22 refreshCart: function (data) 23 { 24 data.sessid = BX.bitrix_sessid(); 25 data.siteId = this.siteId; 26 data.templateName = this.templateName; 27 data.arParams = this.arParams; 28 29 BX.ajax({ 30 url: this.ajaxPath, 31 method: 'POST', 32 dataType: 'html', 33 data: data, 34 onsuccess: this.setCartBodyClosure 35 }); 36 }, 37 38 setCartBody: function (result) 39 { 40 if (!this.cartElement) return; 41 42 // ÐаÑÑим HTML из ajax 43 var tmp = document.createElement('div'); 44 tmp.innerHTML = result.replace(/#CURRENT_URL#/g, this.currentUrl || ''); 45 46 var newMenuItem = tmp.querySelector('.menu-item'); 47 var curMenuItem = this.cartElement.querySelector('.menu-item'); 48 49 // ÐÑли вдÑÑг ÑÑÑÑкÑÑÑа не Ñовпала â fallback на полнÑй replace 50 if (!newMenuItem || !curMenuItem) 51 { 52 this.cartElement.innerHTML = tmp.innerHTML; 53 return; 54 } 55 56 // 1) data-count 57 var newCount = newMenuItem.getAttribute('data-count'); 58 if (newCount !== null) 59 curMenuItem.setAttribute('data-count', newCount); 60 61 // 2) label 62 var newLabel = newMenuItem.querySelector('.menu-item__label'); 63 var curLabel = curMenuItem.querySelector('.menu-item__label'); 64 if (newLabel && curLabel) 65 curLabel.innerHTML = newLabel.innerHTML; 66 67 // 3) popup: обновлÑем ТÐÐЬÐРвнÑÑÑенноÑÑи, не ÑÑÐ¾Ð³Ð°Ñ Ñам .menu-item 68 var newPopup = newMenuItem.querySelector('.basket-popup'); 69 var curPopup = curMenuItem.querySelector('.basket-popup'); 70 71 if (newPopup && curPopup) 72 { 73 // оÑÑавлÑем ÑÑаÑÑй DOM-Ñзел popup (кÑÑÑоÑÑ Ð¿ÑоÑе), менÑем его конÑÐµÐ½Ñ 74 curPopup.innerHTML = newPopup.innerHTML; 75 } 76 else if (newPopup && !curPopup) 77 { 78 // попап поÑвилÑÑ 79 curMenuItem.appendChild(newPopup); 80 } 81 else if (!newPopup && curPopup) 82 { 83 // попап иÑÑез (коÑзина ÑÑала пÑÑÑой) 84 curPopup.parentNode.removeChild(curPopup); 85 } 86 }, 87 88 removeItemFromCart: function (id) 89 { 90 this.refreshCart({ sbblRemoveItemFromCart: id }); 91 BX.onCustomEvent('OnBasketChange'); 92 } 93};
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.