1'use strict'; 2 3function BitrixSmallCart(){} 4BitrixSmallCart.prototype = { 5 6 activate: function () 7 { 8 this.cartElement = BX(this.cartId); 9 this.fixedPosition = this.arParams.POSITION_FIXED == 'Y'; 10 if (this.fixedPosition) 11 { 12 this.cartClosed = true; 13 this.maxHeight = false; 14 this.itemRemoved = false; 15 this.verticalPosition = this.arParams.POSITION_VERTICAL; 16 this.horizontalPosition = this.arParams.POSITION_HORIZONTAL; 17 this.topPanelElement = BX("bx-panel"); 18 19 this.fixAfterRender(); // TODO onready 20 this.fixAfterRenderClosure = this.closure('fixAfterRender'); 21 22 var fixCartClosure = this.closure('fixCart'); 23 this.fixCartClosure = fixCartClosure; 24 25 if (this.topPanelElement && this.verticalPosition == 'top') 26 BX.addCustomEvent(window, 'onTopPanelCollapse', fixCartClosure); 27 28 var resizeTimer = null; 29 BX.bind(window, 'resize', function() { 30 clearTimeout(resizeTimer); 31 resizeTimer = setTimeout(fixCartClosure, 200); 32 }); 33 } 34 this.setCartBodyClosure = this.closure('setCartBody'); 35 BX.addCustomEvent(window, 'OnBasketChange', this.closure('refreshCart', {})); 36 37 }, 38 39 fixAfterRender: function () 40 { 41 this.statusElement = BX(this.cartId + 'status'); 42 if (this.statusElement) 43 { 44 if (this.cartClosed) 45 this.statusElement.innerHTML = this.openMessage; 46 else 47 this.statusElement.innerHTML = this.closeMessage; 48 } 49 this.productsElement = BX(this.cartId + 'products'); 50 this.fixCart(); 51 52 this.bindEvent(); 53 }, 54 55 bindEvent: function() 56 { 57 var flyBasket, flyBasketContainer; 58 59 flyBasket = BX('fly_basket'); 60 if(flyBasket) 61 { 62 flyBasketContainer = flyBasket.querySelector('.bx-basket-fixed'); 63 if(flyBasketContainer) 64 BX.bind(flyBasketContainer, 'mouseover', BX.proxy(this.onHoverBasket, this)); 65 } 66 }, 67 68 onHoverBasket: function(event) 69 { 70 var flyBasket, flyBasketContainer; 71 72 flyBasket = BX('fly_basket'); 73 if(flyBasket) 74 { 75 flyBasketContainer = flyBasket.querySelector('.bx-basket-fixed'); 76 if(flyBasketContainer) 77 BX.removeClass(flyBasketContainer, 'basket-showed'); 78 } 79 }, 80 81 onRefreshBasket: function(data) 82 { 83 var flyBasket, numProductBasketContainer; 84 85 flyBasket = BX('fly_basket'); 86 87 if(flyBasket) 88 { 89 numProductBasketContainer = flyBasket.querySelector('.basket-num-product'); 90 if(numProductBasketContainer) 91 { 92 numProductBasketContainer.innerText = data['productNum']; 93 numProductBasketContainer.style.display = 'inline-block'; 94 } 95 if (data['productNum'] === '0') 96 { 97 numProductBasketContainer.style.display = 'none'; 98 } 99 100 } 101 }, 102 103 closure: function (fname, data) 104 { 105 var obj = this; 106 return data 107 ? function(){obj[fname](data)} 108 : function(arg1){obj[fname](arg1)}; 109 }, 110 111 toggleOpenCloseCart: function () 112 { 113 if (this.cartClosed) 114 { 115 BX.removeClass(this.cartElement, 'bx-closed'); 116 BX.addClass(this.cartElement, 'bx-opener'); 117 this.statusElement.innerHTML = this.closeMessage; 118 this.cartClosed = false; 119 this.fixCart(); 120 } 121 else // Opened 122 { 123 BX.addClass(this.cartElement, 'bx-closed'); 124 BX.removeClass(this.cartElement, 'bx-opener'); 125 BX.removeClass(this.cartElement, 'bx-max-height'); 126 this.statusElement.innerHTML = this.openMessage; 127 this.cartClosed = true; 128 var itemList = this.cartElement.querySelector("[data-role='basket-item-list']"); 129 if (itemList) 130 itemList.style.top = "auto"; 131 } 132 setTimeout(this.fixCartClosure, 100); 133 }, 134 135 setVerticalCenter: function(windowHeight) 136 { 137 var top = windowHeight/2 - (this.cartElement.offsetHeight/2); 138 if (top < 5) 139 top = 5; 140 this.cartElement.style.top = top + 'px'; 141 }, 142 143 fixCart: function() 144 { 145 // set horizontal center 146 if (this.horizontalPosition == 'hcenter') 147 { 148 var windowWidth = 'innerWidth' in window 149 ? window.innerWidth 150 : document.documentElement.offsetWidth; 151 var left = windowWidth/2 - (this.cartElement.offsetWidth/2); 152 if (left < 5) 153 left = 5; 154 this.cartElement.style.left = left + 'px'; 155 } 156 157 var windowHeight = 'innerHeight' in window 158 ? window.innerHeight 159 : document.documentElement.offsetHeight; 160 161 // set vertical position 162 switch (this.verticalPosition) { 163 case 'top': 164 if (this.topPanelElement) 165 this.cartElement.style.top = this.topPanelElement.offsetHeight + 5 + 'px'; 166 break; 167 case 'vcenter': 168 this.setVerticalCenter(windowHeight); 169 break; 170 } 171 172 // toggle max height 173 if (this.productsElement) 174 { 175 var itemList = this.cartElement.querySelector("[data-role='basket-item-list']"); 176 if (this.cartClosed) 177 { 178 if (this.maxHeight) 179 { 180 BX.removeClass(this.cartElement, 'bx-max-height'); 181 if (itemList) 182 itemList.style.top = "auto"; 183 this.maxHeight = false;
184 } 185 } 186 else // Opened 187 { 188 if (this.maxHeight) 189 { 190 if (this.productsElement.scrollHeight == this.productsElement.clientHeight) 191 { 192 BX.removeClass(this.cartElement, 'bx-max-height'); 193 if (itemList) 194 itemList.style.top = "auto"; 195 this.maxHeight = false; 196 } 197 } 198 else 199 { 200 if (this.verticalPosition == 'top' || this.verticalPosition == 'vcenter') 201 { 202 if (this.cartElement.offsetTop + this.cartElement.offsetHeight >= windowHeight) 203 { 204 BX.addClass(this.cartElement, 'bx-max-height'); 205 if (itemList) 206 itemList.style.top = 82+"px"; 207 this.maxHeight = true; 208 } 209 } 210 else 211 { 212 if (this.cartElement.offsetHeight >= windowHeight) 213 { 214 BX.addClass(this.cartElement, 'bx-max-height'); 215 if (itemList) 216 itemList.style.top = 82+"px"; 217 this.maxHeight = true; 218 } 219 } 220 } 221 } 222 223 if (this.verticalPosition == 'vcenter') 224 this.setVerticalCenter(windowHeight); 225 } 226 }, 227 228 refreshCart: function (data) 229 { 230 if (this.itemRemoved) 231 { 232 this.itemRemoved = false; 233 return; 234 } 235 data.sessid = BX.bitrix_sessid(); 236 data.siteId = this.siteId; 237 data.templateName = this.templateName; 238 data.arParams = this.arParams; 239 BX.ajax({ 240 url: this.ajaxPath, 241 method: 'POST', 242 dataType: 'html', 243 data: data, 244 onsuccess: this.setCartBodyClosure 245 }); 246 247 }, 248 249 setCartBody: function (result) 250 { 251 if (this.cartElement) 252 this.cartElement.innerHTML = result.replace(/#CURRENT_URL#/g, this.currentUrl); 253 if (this.fixedPosition) 254 setTimeout(this.fixAfterRenderClosure, 100); 255 }, 256 257 removeItemFromCart: function (id) 258 { 259 this.refreshCart ({sbblRemoveItemFromCart: id}); 260 this.itemRemoved = true; 261 BX.onCustomEvent('OnBasketChange'); 262 sendBasketInfo(); 263 } 264};
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.