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, 'close'); 66 this.statusElement.innerHTML = this.closeMessage; 67 this.cartClosed = false; 68 } 69 else // Opened 70 { 71 BX.addClass(this.cartElement, 'close'); 72 this.statusElement.innerHTML = this.openMessage; 73 this.cartClosed = true; 74 } 75 setTimeout(this.fixCartClosure, 100); 76 }, 77 78 setVerticalCenter: function(windowHeight) 79 { 80 var top = windowHeight/2 - (this.cartElement.offsetHeight/2); 81 if (top < 5) 82 top = 5; 83 this.cartElement.style.top = top + 'px'; 84 }, 85 86 fixCart: function() 87 { 88 // set horizontal center 89 if (this.horizontalPosition == 'hcenter') 90 { 91 var windowWidth = 'innerWidth' in window 92 ? window.innerWidth 93 : document.documentElement.offsetWidth; 94 var left = windowWidth/2 - (this.cartElement.offsetWidth/2); 95 if (left < 5) 96 left = 5; 97 this.cartElement.style.left = left + 'px'; 98 } 99 100 var windowHeight = 'innerHeight' in window 101 ? window.innerHeight 102 : document.documentElement.offsetHeight; 103 104 // set vertical position 105 switch (this.verticalPosition) { 106 case 'top': 107 if (this.topPanelElement) 108 this.cartElement.style.top = this.topPanelElement.offsetHeight + 5 + 'px'; 109 break; 110 case 'vcenter': 111 this.setVerticalCenter(windowHeight); 112 break; 113 } 114 115 // toggle max height 116 if (this.productsElement) 117 { 118 if (this.cartClosed) 119 { 120 if (this.maxHeight) 121 { 122 BX.removeClass(this.cartElement, 'max_height'); 123 this.maxHeight = false; 124 } 125 } 126 else // Opened 127 { 128 if (this.maxHeight) 129 { 130 if (this.productsElement.scrollHeight == this.productsElement.clientHeight) 131 { 132 BX.removeClass(this.cartElement, 'max_height'); 133 this.maxHeight = false; 134 } 135 } 136 else 137 { 138 if (this.verticalPosition == 'top' || this.verticalPosition == 'vcenter') 139 { 140 if (this.cartElement.offsetTop + this.cartElement.offsetHeight >= windowHeight) 141 { 142 BX.addClass(this.cartElement, 'max_height'); 143 this.maxHeight = true; 144 } 145 } 146 else 147 { 148 if (this.cartElement.offsetHeight >= windowHeight) 149 { 150 BX.addClass(this.cartElement, 'max_height'); 151 this.maxHeight = true; 152 } 153 } 154 } 155 } 156 157 if (this.verticalPosition == 'vcenter') 158 this.setVerticalCenter(windowHeight); 159 } 160 }, 161 162 refreshCart: function (data) 163 { 164 if (this.itemRemoved) 165 { 166 this.itemRemoved = false; 167 return; 168 } 169 data.sessid = BX.bitrix_sessid(); 170 data.siteId = this.siteId; 171 data.templateName = this.templateName; 172 data.arParams = this.arParams; 173 BX.ajax({ 174 url: this.ajaxPath, 175 method: 'POST', 176 dataType: 'html', 177 data: data, 178 onsuccess: this.setCartBodyClosure 179 }); 180 }, 181 182 setCartBody: function (result) 183 { 184 if (this.cartElement) 185 this.cartElement.innerHTML = result; 186 if (this.fixedPosition) 187 setTimeout(this.fixAfterRenderClosure, 100); 188 }, 189 190 removeItemFromCart: function (id) 191 {
192 this.refreshCart ({sbblRemoveItemFromCart: id}); 193 this.itemRemoved = true; 194 BX.onCustomEvent('OnBasketChange'); 195 } 196};
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.