Your IP : 3.137.188.141
'use strict';
function BitrixSmallCart(){}
BitrixSmallCart.prototype = {
activate: function ()
{
this.cartElement = BX(this.cartId);
this.fixedPosition = this.arParams.POSITION_FIXED == 'Y';
if (this.fixedPosition)
{
this.cartClosed = true;
this.maxHeight = false;
this.itemRemoved = false;
this.verticalPosition = this.arParams.POSITION_VERTICAL;
this.horizontalPosition = this.arParams.POSITION_HORIZONTAL;
this.topPanelElement = BX("bx-panel");
this.fixAfterRender(); // TODO onready
this.fixAfterRenderClosure = this.closure('fixAfterRender');
var fixCartClosure = this.closure('fixCart');
this.fixCartClosure = fixCartClosure;
if (this.topPanelElement && this.verticalPosition == 'top')
BX.addCustomEvent(window, 'onTopPanelCollapse', fixCartClosure);
var resizeTimer = null;
BX.bind(window, 'resize', function() {
clearTimeout(resizeTimer);
resizeTimer = setTimeout(fixCartClosure, 200);
});
}
this.setCartBodyClosure = this.closure('setCartBody');
BX.addCustomEvent(window, 'OnBasketChange', this.closure('refreshCart', {}));
},
fixAfterRender: function ()
{
this.statusElement = BX(this.cartId + 'status');
if (this.statusElement)
{
if (this.cartClosed)
this.statusElement.innerHTML = this.openMessage;
else
this.statusElement.innerHTML = this.closeMessage;
}
this.productsElement = BX(this.cartId + 'products');
this.fixCart();
},
closure: function (fname, data)
{
var obj = this;
return data
? function(){obj[fname](data)}
: function(arg1){obj[fname](arg1)};
},
toggleOpenCloseCart: function ()
{
if (this.cartClosed)
{
BX.removeClass(this.cartElement, 'close');
this.statusElement.innerHTML = this.closeMessage;
this.cartClosed = false;
}
else // Opened
{
BX.addClass(this.cartElement, 'close');
this.statusElement.innerHTML = this.openMessage;
this.cartClosed = true;
}
setTimeout(this.fixCartClosure, 100);
},
setVerticalCenter: function(windowHeight)
{
var top = windowHeight/2 - (this.cartElement.offsetHeight/2);
if (top < 5)
top = 5;
this.cartElement.style.top = top + 'px';
},
fixCart: function()
{
// set horizontal center
if (this.horizontalPosition == 'hcenter')
{
var windowWidth = 'innerWidth' in window
? window.innerWidth
: document.documentElement.offsetWidth;
var left = windowWidth/2 - (this.cartElement.offsetWidth/2);
if (left < 5)
left = 5;
this.cartElement.style.left = left + 'px';
}
var windowHeight = 'innerHeight' in window
? window.innerHeight
: document.documentElement.offsetHeight;
// set vertical position
switch (this.verticalPosition) {
case 'top':
if (this.topPanelElement)
this.cartElement.style.top = this.topPanelElement.offsetHeight + 5 + 'px';
break;
case 'vcenter':
this.setVerticalCenter(windowHeight);
break;
}
// toggle max height
if (this.productsElement)
{
if (this.cartClosed)
{
if (this.maxHeight)
{
BX.removeClass(this.cartElement, 'max_height');
this.maxHeight = false;
}
}
else // Opened
{
if (this.maxHeight)
{
if (this.productsElement.scrollHeight == this.productsElement.clientHeight)
{
BX.removeClass(this.cartElement, 'max_height');
this.maxHeight = false;
}
}
else
{
if (this.verticalPosition == 'top' || this.verticalPosition == 'vcenter')
{
if (this.cartElement.offsetTop + this.cartElement.offsetHeight >= windowHeight)
{
BX.addClass(this.cartElement, 'max_height');
this.maxHeight = true;
}
}
else
{
if (this.cartElement.offsetHeight >= windowHeight)
{
BX.addClass(this.cartElement, 'max_height');
this.maxHeight = true;
}
}
}
}
if (this.verticalPosition == 'vcenter')
this.setVerticalCenter(windowHeight);
}
},
refreshCart: function (data)
{
if (this.itemRemoved)
{
this.itemRemoved = false;
return;
}
data.sessid = BX.bitrix_sessid();
data.siteId = this.siteId;
data.templateName = this.templateName;
data.arParams = this.arParams;
BX.ajax({
url: this.ajaxPath,
method: 'POST',
dataType: 'html',
data: data,
onsuccess: this.setCartBodyClosure
});
},
setCartBody: function (result)
{
if (this.cartElement)
this.cartElement.innerHTML = result;
if (this.fixedPosition)
setTimeout(this.fixAfterRenderClosure, 100);
},
removeItemFromCart: function (id)
{
this.refreshCart ({sbblRemoveItemFromCart: id});
this.itemRemoved = true;
BX.onCustomEvent('OnBasketChange');
}
};