1'use strict'; 2 3function BitrixSmallCart(){} 4 5BitrixSmallCart.prototype = { 6 7 activate: function () 8 { 9 this.cartElement = BX(this.cartId); 10 this.fixedPosition = this.arParams.POSITION_FIXED == 'Y'; 11 if (this.fixedPosition) 12 { 13 this.cartClosed = true; 14 this.maxHeight = false; 15 this.itemRemoved = false; 16 this.verticalPosition = this.arParams.POSITION_VERTICAL; 17 this.horizontalPosition = this.arParams.POSITION_HORIZONTAL; 18 this.topPanelElement = BX("bx-panel"); 19 20 this.fixAfterRender(); // TODO onready 21 this.fixAfterRenderClosure = this.closure('fixAfterRender'); 22 23 var fixCartClosure = this.closure('fixCart'); 24 this.fixCartClosure = fixCartClosure; 25 26 if (this.topPanelElement && this.verticalPosition == 'top') 27 BX.addCustomEvent(window, 'onTopPanelCollapse', fixCartClosure); 28 29 var resizeTimer = null; 30 BX.bind(window, 'resize', function() { 31 clearTimeout(resizeTimer); 32 resizeTimer = setTimeout(fixCartClosure, 200); 33 }); 34 } 35 this.setCartBodyClosure = this.closure('setCartBody'); 36 BX.addCustomEvent(window, 'OnBasketChange', this.closure('refreshCart', {})); 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 53 closure: function (fname, data) 54 { 55 var obj = this; 56 return data 57 ? function(){obj[fname](data)} 58 : function(arg1){obj[fname](arg1)}; 59 }, 60 61 toggleOpenCloseCart: function () 62 { 63 if (this.cartClosed) 64 { 65 BX.removeClass(this.cartElement, 'bx-closed'); 66 BX.addClass(this.cartElement, 'bx-opener'); 67 this.statusElement.innerHTML = this.closeMessage; 68 this.cartClosed = false; 69 this.fixCart(); 70 } 71 else // Opened 72 { 73 BX.addClass(this.cartElement, 'bx-closed'); 74 BX.removeClass(this.cartElement, 'bx-opener'); 75 BX.removeClass(this.cartElement, 'bx-max-height'); 76 this.statusElement.innerHTML = this.openMessage; 77 this.cartClosed = true; 78 var itemList = this.cartElement.querySelector("[data-role='basket-item-list']"); 79 if (itemList) 80 itemList.style.top = "auto"; 81 } 82 setTimeout(this.fixCartClosure, 100); 83 }, 84 85 setVerticalCenter: function(windowHeight) 86 { 87 var top = windowHeight/2 - (this.cartElement.offsetHeight/2); 88 if (top < 5) 89 top = 5; 90 this.cartElement.style.top = top + 'px'; 91 }, 92 93 fixCart: function() 94 { 95 // set horizontal center 96 if (this.horizontalPosition == 'hcenter') 97 { 98 var windowWidth = 'innerWidth' in window 99 ? window.innerWidth 100 : document.documentElement.offsetWidth; 101 var left = windowWidth/2 - (this.cartElement.offsetWidth/2); 102 if (left < 5) 103 left = 5; 104 this.cartElement.style.left = left + 'px'; 105 } 106 107 var windowHeight = 'innerHeight' in window 108 ? window.innerHeight 109 : document.documentElement.offsetHeight; 110 111 // set vertical position 112 switch (this.verticalPosition) { 113 case 'top': 114 if (this.topPanelElement) 115 this.cartElement.style.top = this.topPanelElement.offsetHeight + 5 + 'px'; 116 break; 117 case 'vcenter': 118 this.setVerticalCenter(windowHeight); 119 break; 120 } 121 122 // toggle max height 123 if (this.productsElement) 124 { 125 var itemList = this.cartElement.querySelector("[data-role='basket-item-list']"); 126 if (this.cartClosed) 127 { 128 if (this.maxHeight) 129 { 130 BX.removeClass(this.cartElement, 'bx-max-height'); 131 if (itemList) 132 itemList.style.top = "auto"; 133 this.maxHeight = false; 134 } 135 } 136 else // Opened 137 { 138 if (this.maxHeight) 139 { 140 if (this.productsElement.scrollHeight == this.productsElement.clientHeight) 141 { 142 BX.removeClass(this.cartElement, 'bx-max-height'); 143 if (itemList) 144 itemList.style.top = "auto"; 145 this.maxHeight = false; 146 } 147 } 148 else 149 { 150 if (this.verticalPosition == 'top' || this.verticalPosition == 'vcenter') 151 { 152 if (this.cartElement.offsetTop + this.cartElement.offsetHeight >= windowHeight) 153 { 154 BX.addClass(this.cartElement, 'bx-max-height'); 155 if (itemList) 156 itemList.style.top = 82+"px"; 157 this.maxHeight = true; 158 } 159 } 160 else 161 { 162 if (this.cartElement.offsetHeight >= windowHeight) 163 { 164 BX.addClass(this.cartElement, 'bx-max-height'); 165 if (itemList) 166 itemList.style.top = 82+"px"; 167 this.maxHeight = true; 168 } 169 } 170 } 171 } 172 173 if (this.verticalPosition == 'vcenter') 174 this.setVerticalCenter(windowHeight); 175 } 176 }, 177 178 refreshCart: function (data) 179 { 180 if (this.itemRemoved) 181 { 182 this.itemRemoved = false;
183 return; 184 } 185 data.sessid = BX.bitrix_sessid(); 186 data.siteId = this.siteId; 187 data.templateName = this.templateName; 188 data.arParams = this.arParams; 189 BX.ajax({ 190 url: this.ajaxPath, 191 method: 'POST', 192 dataType: 'html', 193 data: data, 194 onsuccess: this.setCartBodyClosure 195 }); 196 }, 197 198 setCartBody: function (result) 199 { 200 if (this.cartElement) 201 this.cartElement.innerHTML = result.replace(/#CURRENT_URL#/g, this.currentUrl); 202 if (this.fixedPosition) 203 setTimeout(this.fixAfterRenderClosure, 100); 204 }, 205 206 removeItemFromCart: function (id) 207 { 208 this.refreshCart ({sbblRemoveItemFromCart: id}); 209 this.itemRemoved = true; 210 BX.onCustomEvent('OnBasketChange'); 211 } 212};
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.