%PDF- %PDF-
Direktori : /home/bitrix/www/bitrix/components/bitrix/sale.basket.basket/templates/.default/js/ |
Current File : /home/bitrix/www/bitrix/components/bitrix/sale.basket.basket/templates/.default/js/component.min.js |
(function(){"use strict";BX.namespace("BX.Sale.BasketComponent");BX.Sale.BasketComponent={isMobile:BX.browser.IsMobile(),isTouch:BX.hasClass(document.documentElement,"bx-touch"),lastAction:"initialLoad",maxItemsShowCount:30,precisionFactor:Math.pow(10,6),quantityDelay:null,quantityTimer:null,stickyHeaderOffset:0,duration:{priceAnimation:300,filterTimer:300},imagePopup:null,loadingScreen:null,templates:{},nodes:{},items:{},sortedItems:[],shownItems:[],changedItems:[],postponedItems:[],warningItems:[],ids:{item:"basket-item-",quantity:"basket-item-quantity-",price:"basket-item-price-",sumPrice:"basket-item-sum-price-",sumPriceOld:"basket-item-sum-price-old-",sumPriceDiff:"basket-item-sum-price-difference-",itemHeightAligner:"basket-item-height-aligner-",total:"basket-total-price",basketRoot:"basket-root",itemListWrapper:"basket-items-list-wrapper",itemListContainer:"basket-items-list-container",itemList:"basket-item-list",itemListTable:"basket-item-table",itemListEmptyResult:"basket-item-list-empty-result",itemListOverlay:"basket-items-list-overlay",warning:"basket-warning"},init:function(t){this.params=t.params||{};this.template=t.template||"";this.signedParamsString=t.signedParamsString||"";this.siteId=t.siteId||"";this.ajaxUrl=this.params.AJAX_PATH||"";this.templateFolder=t.templateFolder||"";this.useDynamicScroll=this.params.USE_DYNAMIC_SCROLL==="Y";this.useItemsFilter=this.params.SHOW_FILTER==="Y"&&!this.isMobile;this.initializeFilter();this.applyBasketResult(t.result);this.initializeActionPool();if(this.useItemsFilter){this.checkHeaderDisplay();this.bindHeaderEvents()}this.initializeBasketItems();this.editTotal();this.editWarnings();this.adjustBasketWrapperHeight();this.getCacheNode(this.ids.basketRoot).style.opacity=1;this.bindInitialEvents()},getTemplate:function(t){if(!this.templates.hasOwnProperty(t)){var e=BX(t);this.templates[t]=BX.type.isDomNode(e)?e.innerHTML:""}return this.templates[t]},getCacheNode:function(t){if(!this.nodes.hasOwnProperty(t)){this.nodes[t]=BX(t)}return this.nodes[t]},getEntity:function(t,e,i){if(!t||!e)return null;i=i||"";return t.querySelector(i+'[data-entity="'+e+'"]')},getEntities:function(t,e,i){if(!t||!e)return{length:0};i=i||"";return t.querySelectorAll(i+'[data-entity="'+e+'"]')},bindInitialEvents:function(){this.bindWarningEvents();BX.bind(window,"scroll",BX.proxy(this.checkStickyHeaders,this));BX.bind(window,"scroll",BX.proxy(this.lazyLoad,this));BX.bind(window,"resize",BX.throttle(this.checkStickyHeaders,20,this));BX.bind(window,"resize",BX.throttle(this.adjustBasketWrapperHeight,20,this))},bindWarningEvents:function(){var t=this.getEntity(BX(this.ids.warning),"basket-items-warning-count");if(BX.type.isDomNode(t)){t.style.display="";BX.bind(t,"click",BX.delegate(function(){this.toggleFilter("warning")},this))}BX.bind(this.getEntity(BX(this.ids.warning),"basket-items-warning-notification-close"),"click",BX.proxy(this.removeAllWarnings,this))},toggleFilter:function(t){var e=BX.type.isNotEmptyString(t)?this.getEntity(this.getCacheNode(this.ids.itemListWrapper),"basket-items-count",'[data-filter="'+t+'"]'):BX.getEventTarget(t);if(!BX.type.isDomNode(e)||BX.hasClass(e,"active"))return;var i=e.getAttribute("data-filter");var s=e.parentNode.querySelectorAll("[data-filter]");for(var a=0;a<s.length;a++){if(s[a].getAttribute("data-filter")===i){BX.addClass(s[a],"active")}else if(BX.hasClass(s[a],"active")){BX.removeClass(s[a],"active")}}this.filter.showFilterByName(i)},scrollToFirstItem:function(){var t=this.getEntity(this.getCacheNode(this.ids.itemListWrapper),"basket-items-list-header");if(BX.type.isDomNode(t)){var e=BX.pos(this.getCacheNode(this.ids.itemListContainer)).top;var i=BX.pos(t).bottom;if(e<i){window.scrollTo(0,e-this.stickyHeaderOffset)}}},showItemsOverlay:function(){var t=this.getCacheNode(this.ids.itemListOverlay);if(BX.type.isDomNode(t)){t.style.display=""}},hideItemsOverlay:function(){var t=this.getCacheNode(this.ids.itemListOverlay);if(BX.type.isDomNode(t)){t.style.display="none"}},checkHeaderDisplay:function(){var t=this.getCacheNode(this.ids.itemListWrapper);if(BX.type.isDomNode(t)){BX.removeClass(t,"basket-items-list-wrapper-light")}},bindHeaderEvents:function(){var t=this.getEntities(this.getCacheNode(this.ids.itemListWrapper),"basket-items-count");for(var e=0;e<t.length;e++){BX.bind(t[e],"click",BX.proxy(this.toggleFilter,this))}},checkStickyHeaders:function(){if(this.isMobile)return;var t,e;var i=2,s=0;var a=this.getDocumentScrollTop();var n=BX.pos(this.getCacheNode(this.ids.basketRoot));var r=a+200>=n.bottom;if(BX.util.in_array("top",this.params.TOTAL_BLOCK_DISPLAY)){var o=this.getEntity(this.getCacheNode(this.ids.basketRoot),"basket-total-block");if(BX.type.isDomNode(o)){t=this.getEntity(o,"basket-checkout-aligner");if(BX.type.isDomNode(t)){e=BX.pos(o);if(a>=e.top){s+=t.clientHeight;if(!BX.hasClass(t,"basket-checkout-container-fixed")){o.style.height=e.height+"px";t.style.width=t.clientWidth+i+"px";BX.addClass(t,"basket-checkout-container-fixed")}}else if(BX.hasClass(t,"basket-checkout-container-fixed")){o.style.height="";t.style.width="";BX.removeClass(t,"basket-checkout-container-fixed")}if(r){if(!BX.hasClass(t,"basket-checkout-container-fixed-hide")){BX.addClass(t,"basket-checkout-container-fixed-hide")}}else if(BX.hasClass(t,"basket-checkout-container-fixed-hide")){BX.removeClass(t,"basket-checkout-container-fixed-hide")}}}}if(this.useItemsFilter){var h=this.getCacheNode(this.ids.itemListWrapper);t=this.getEntity(h,"basket-items-list-header");if(BX.type.isDomNode(t)){e=BX.pos(h);if(a+s>=e.top&&!r){if(!BX.hasClass(t,"basket-items-list-header-fixed")){t.style.width=t.clientWidth+i+"px";h.style.paddingTop=t.clientHeight+"px";BX.addClass(t,"basket-items-list-header-fixed")}if(s){t.style.top=s+"px"}s+=t.clientHeight}else if(BX.hasClass(t,"basket-items-list-header-fixed")){h.style.paddingTop="";t.style.width="";t.style.top="";BX.removeClass(t,"basket-items-list-header-fixed")}}}var l=this.stickyHeaderOffset===s;this.stickyHeaderOffset=s;if(l&&!r){this.adjustBasketWrapperHeight()}},getDocumentScrollTop:function(){return window.scrollY||window.pageYOffset||document.body.scrollTop+(document.documentElement&&document.documentElement.scrollTop||0)},lazyLoad:function(){var t=BX.pos(this.getCacheNode(this.ids.itemListContainer));if(this.getDocumentScrollTop()+window.innerHeight>=t.bottom-400){var e=this.getItemsAfter();if(e.length){this.editBasketItems(e)}}},fireCustomEvents:function(){if(this.result.EVENT_ONCHANGE_ON_START==="Y"){BX.onCustomEvent("OnBasketChange")}},adjustBasketWrapperHeight:function(){var t=this.getCacheNode(this.ids.itemListContainer),e=this.getCacheNode(this.ids.itemList);if(BX.type.isDomNode(t)&&BX.type.isDomNode(e)){if(t.clientHeight+this.stickyHeaderOffset>window.innerHeight){t.style.minHeight="calc(100vh - 15px - "+this.stickyHeaderOffset+"px)";e.style.minHeight="calc(100vh - 15px - "+this.stickyHeaderOffset+"px)"}else{t.style.minHeight=t.clientHeight+"px";e.style.minHeight=t.clientHeight+"px"}}},editTotal:function(){this.fillTotalBlocks();this.showItemsCount();this.showWarningItemsCount();this.showNotAvailableItemsCount();this.showDelayedItemsCount()},fillTotalBlocks:function(){var t=this.getEntities(this.getCacheNode(this.ids.basketRoot),"basket-total-block");if(t&&t.length){var e=this.getTemplate("basket-total-template");if(e){var i=this.render(e,this.result.TOTAL_RENDER_DATA);for(var s in t){if(t.hasOwnProperty(s)&&BX.type.isDomNode(t[s])){t[s].innerHTML=i;this.bindTotalEvents(t[s])}}}}this.checkStickyHeaders()},showItemsCount:function(){var t=this.getEntity(this.getCacheNode(this.ids.itemListWrapper),"basket-items-count",'[data-filter="all"]');if(BX.type.isDomNode(t)){t.innerHTML=BX.message("SBB_IN_BASKET")+" "+this.result.BASKET_ITEMS_COUNT+" "+this.getGoodsMessage(this.result.BASKET_ITEMS_COUNT);t.style.display=""}},showSimilarCount:function(t){var e=this.getEntity(this.getCacheNode(this.ids.itemListWrapper),"basket-items-count",'[data-filter="similar"]');if(BX.type.isDomNode(e)){if(t){e.innerHTML=this.sortedItems.length+" "+this.getGoodsMessage(this.result.BASKET_ITEMS_COUNT,"SBB_SIMILAR_ITEM");e.style.display=""}else{e.style.display="none"}}},showWarningItemsCount:function(){var t=this.getEntity(this.getCacheNode(this.ids.itemListWrapper),"basket-items-count",'[data-filter="warning"]');if(BX.type.isDomNode(t)){if(this.warningItems.length){t.innerHTML=this.warningItems.length+" "+BX.message("SBB_BASKET_ITEMS_WARNING");t.style.display=""}else{t.style.display="none"}}},showNotAvailableItemsCount:function(){var t=this.getEntity(this.getCacheNode(this.ids.itemListWrapper),"basket-items-count",'[data-filter="not-available"]');if(BX.type.isDomNode(t)){if(parseInt(this.result.NOT_AVAILABLE_BASKET_ITEMS_COUNT)){t.innerHTML=this.result.NOT_AVAILABLE_BASKET_ITEMS_COUNT+" "+this.getGoodsMessage(this.result.NOT_AVAILABLE_BASKET_ITEMS_COUNT,"SBB_NOT_AVAILABLE_ITEM");t.style.display=""}else{t.style.display="none"}}},showDelayedItemsCount:function(){var t=this.getEntity(this.getCacheNode(this.ids.itemListWrapper),"basket-items-count",'[data-filter="delayed"]');if(BX.type.isDomNode(t)){if(parseInt(this.result.DELAYED_BASKET_ITEMS_COUNT)){t.innerHTML=this.result.DELAYED_BASKET_ITEMS_COUNT+" "+this.getGoodsMessage(this.result.DELAYED_BASKET_ITEMS_COUNT,"SBB_DELAYED_ITEM");t.style.display=""}else{t.style.display="none"}}},getGoodsMessage:function(t,e){var i;var s=t>10&&t<20?0:t%10;if(s===1){i=e||"SBB_GOOD"}else if(s>=2&&s<=4){i=e?e+"_2":"SBB_GOOD_2"}else{i=e?e+"S":"SBB_GOODS"}return BX.message(i)},bindTotalEvents:function(t){if(!this.result.TOTAL_RENDER_DATA.DISABLE_CHECKOUT){BX.bind(this.getEntity(t,"basket-checkout-button"),"click",BX.proxy(this.checkOutAction,this))}BX.bind(this.getEntity(t,"basket-coupon-input"),"change",BX.proxy(this.addCouponAction,this));BX.bind(this.getEntity(t,"basket-coupon-input"),"paste",BX.proxy(this.pasteCouponAction,this));var e=this.getEntities(t,"basket-coupon-delete");for(var i=0,s=e.length;i<s;i++){BX.bind(e[i],"click",BX.proxy(this.removeCouponAction,this))}},checkOutAction:function(){document.location.href=this.params.PATH_TO_ORDER},addCouponAction:function(t){var e=BX.getEventTarget(t);if(e&&e.value){this.actionPool.addCoupon(e.value);e.disabled=true}},pasteCouponAction:function(t){setTimeout(BX.delegate(function(){this.addCouponAction(t)},this),10)},removeCouponAction:function(){var t=BX.proxy_context&&BX.util.trim(BX.proxy_context.getAttribute("data-coupon"));if(t){this.actionPool.removeCoupon(t)}},initializeActionPool:function(){this.actionPool=new BX.Sale.BasketActionPool(this)},initializeFilter:function(){this.filter=new BX.Sale.BasketFilter(this)},sendRequest:function(t,e){this.lastAction=t;if(this.lastAction==="recalculateAjax"){e.lastAppliedDiscounts=BX.util.array_keys(this.result.FULL_DISCOUNT_LIST).join(",");if(this.params.USE_ENHANCED_ECOMMERCE==="Y"){this.checkAnalytics(e)}}BX.ajax({method:"POST",dataType:"json",url:this.ajaxUrl,data:this.getData(e),onsuccess:BX.delegate(function(t){this.actionPool.doProcessing(false);if(!BX.type.isPlainObject(t))return;this.actionPool.setRefreshStatus(t.BASKET_REFRESHED);if(t.RESTORED_BASKET_ITEMS){this.restoreBasketItems(t.RESTORED_BASKET_ITEMS)}if(t.DELETED_BASKET_ITEMS){this.deleteBasketItems(t.DELETED_BASKET_ITEMS,this.params.SHOW_RESTORE==="Y")}if(t.MERGED_BASKET_ITEMS){this.deleteBasketItems(t.MERGED_BASKET_ITEMS,false,true)}this.applyBasketResult(t.BASKET_DATA);this.editBasketItems(this.getItemsToEdit());this.editTotal();this.adjustBasketWrapperHeight();this.applyPriceAnimation();this.editWarnings();this.actionPool.switchTimer();if(this.isBasketIntegrated()&&this.isBasketChanged()){BX.Sale.OrderAjaxComponent.sendRequest()}},this),onfailure:BX.delegate(function(){this.actionPool.doProcessing(false)},this)})},isBasketIntegrated:function(){return this.params.BASKET_WITH_ORDER_INTEGRATION==="Y"},isBasketChanged:function(){return this.changedItems.length},addPriceAnimationData:function(t,e,i,s){if(!BX.type.isPlainObject(this.priceAnimationData)){this.clearPriceAnimationData()}this.priceAnimationData.start[t]=parseFloat(e);this.priceAnimationData.finish[t]=parseFloat(i);this.priceAnimationData.currency[t]=s;this.priceAnimationData.int[t]=parseFloat(e)===parseInt(e)&&parseFloat(i)===parseInt(i)},clearPriceAnimationData:function(){this.priceAnimationData={start:{},finish:{},currency:{},int:{}}},applyBasketResult:function(t){this.changedItems=[];this.clearPriceAnimationData();if(!BX.type.isPlainObject(t)){return}if(t.BASKET_ITEM_RENDER_DATA){var e,i;for(e in t.BASKET_ITEM_RENDER_DATA){if(t.BASKET_ITEM_RENDER_DATA.hasOwnProperty(e)){i=t.BASKET_ITEM_RENDER_DATA[e];i.WARNINGS=this.checkBasketItemWarnings(i,t.WARNING_MESSAGE_WITH_CODE);if(this.items[i.ID]){if(JSON.stringify(this.items[i.ID])===JSON.stringify(i)){continue}}else{this.addSortedItem(i.ID,true)}this.changedItems.push(i.ID);i=this.checkBasketItemsAnimation(i);this.items[i.ID]=i}}this.changedItems=BX.util.array_unique(this.changedItems.concat(this.getChangedSimilarOffers()));if(this.isBasketChanged()){this.sortSortedItems(true)}}if(t.TOTAL_RENDER_DATA){t.TOTAL_RENDER_DATA=this.checkTotalAnimation(t.TOTAL_RENDER_DATA)}this.result=t},itemSortFunction:function(t,e){if(!this.items.hasOwnProperty(t)||!this.items.hasOwnProperty(e)){return 0}return parseFloat(this.items[t].SORT)-parseFloat(this.items[e].SORT)},getChangedSimilarOffers:function(){var t=[];var e,i;var s=this.getHashMap();for(var a in s){if(s.hasOwnProperty(a)){if(s[a].length>1){for(var n=0;n<s[a].length;n++){e=0;i=0;for(var r=0;r<s[a].length;r++){if(s[a][r]!=s[a][n]){e+=parseFloat(this.items[s[a][r]].QUANTITY)}i+=parseFloat(this.items[s[a][r]].QUANTITY)}if(!this.items[s[a][n]].HAS_SIMILAR_ITEMS||this.items[s[a][n]].SIMILAR_ITEMS_QUANTITY!=e||this.items[s[a][n]].TOTAL_SIMILAR_ITEMS_QUANTITY!=i){t.push(s[a][n]);this.items[s[a][n]].HAS_SIMILAR_ITEMS=true;this.items[s[a][n]].SIMILAR_ITEMS_QUANTITY=e;this.items[s[a][n]].TOTAL_SIMILAR_ITEMS_QUANTITY=i;this.items[s[a][n]].ALL_AVAILABLE_QUANTITY=this.items[s[a][n]].AVAILABLE_QUANTITY;this.items[s[a][n]].AVAILABLE_QUANTITY=this.items[s[a][n]].ALL_AVAILABLE_QUANTITY-e}}}else if(s[a][0]&&this.items[s[a][0]].HAS_SIMILAR_ITEMS){t.push(s[a][0]);delete this.items[s[a][0]].HAS_SIMILAR_ITEMS;delete this.items[s[a][0]].SIMILAR_ITEMS_QUANTITY;delete this.items[s[a][0]].TOTAL_SIMILAR_ITEMS_QUANTITY;this.items[s[a][0]].AVAILABLE_QUANTITY=this.items[s[a][0]].ALL_AVAILABLE_QUANTITY;delete this.items[s[a][0]].ALL_AVAILABLE_QUANTITY}}}return t},getHashMap:function(){var t={};for(var e in this.items){if(this.items.hasOwnProperty(e)&&this.isItemAvailable(e)){if(!t.hasOwnProperty(this.items[e].HASH)){t[this.items[e].HASH]=[]}t[this.items[e].HASH].push(e)}}return t},isItemAvailable:function(t){var e=this.filter.isActive()?this.filter.realSortedItems:this.sortedItems;return!this.items[t].NOT_AVAILABLE&&!this.items[t].SHOW_RESTORE&&BX.util.in_array(t,e)},checkTotalAnimation:function(t){if(this.result&&this.result.TOTAL_RENDER_DATA&&parseFloat(this.result.TOTAL_RENDER_DATA.PRICE)>parseFloat(t.PRICE)){t.PRICE_NEW=t.PRICE;t.PRICE=this.result.TOTAL_RENDER_DATA.PRICE;t.PRICE_FORMATED_NEW=t.PRICE_FORMATED;t.PRICE_FORMATED=this.result.TOTAL_RENDER_DATA.PRICE_FORMATED;this.addPriceAnimationData(this.ids.total,t.PRICE,t.PRICE_NEW,t.CURRENCY)}return t},checkBasketItemsAnimation:function(t){var e=t.ID;if(this.items[e]){var i=BX(this.ids.quantity+e);if(BX.type.isDomNode(i)&&!this.actionPool.isItemInPool(e)&&parseFloat(i.value)!==parseFloat(t.QUANTITY)){t.QUANTITY_ANIMATION=true;this.actionPool.clearLastActualQuantityPool(e)}if(parseFloat(this.items[e].PRICE)>parseFloat(t.PRICE)){t.PRICE_NEW=t.PRICE;t.PRICE=this.items[e].PRICE;t.PRICE_FORMATED_NEW=t.PRICE_FORMATED;t.PRICE_FORMATED=this.items[e].PRICE_FORMATED;this.addPriceAnimationData(this.ids.price+e,t.PRICE,t.PRICE_NEW,t.CURRENCY)}if(BX.util.in_array("SUM",this.params.COLUMNS_LIST)&&parseFloat(this.items[e].SUM_PRICE)>parseFloat(t.SUM_PRICE)&&parseFloat(this.items[e].QUANTITY)===parseFloat(t.QUANTITY)){t.SUM_PRICE_NEW=t.SUM_PRICE;t.SUM_PRICE=this.items[e].SUM_PRICE;t.SUM_PRICE_FORMATED_NEW=t.SUM_PRICE_FORMATED;t.SUM_PRICE_FORMATED=this.items[e].SUM_PRICE_FORMATED;this.addPriceAnimationData(this.ids.sumPrice+e,t.SUM_PRICE,t.SUM_PRICE_NEW,t.CURRENCY)}}return t},getData:function(t){t=t||{};t[this.params.ACTION_VARIABLE]=this.lastAction;t.via_ajax="Y";t.site_id=this.siteId;t.sessid=BX.bitrix_sessid();t.template=this.template;t.signedParamsString=this.signedParamsString;return t},startLoader:function(){},endLoader:function(){},editWarnings:function(){this.editGeneralWarnings();this.editBasketItemWarnings();this.toggleWarningBlock();this.showWarningItemsCount()},editGeneralWarnings:function(){var t=this.getEntity(this.getCacheNode(this.ids.warning),"basket-general-warnings");if(BX.type.isDomNode(t)){var e=t.innerHTML;if(this.result.WARNING_MESSAGE_WITH_CODE){for(var i in this.result.WARNING_MESSAGE_WITH_CODE){if(this.result.WARNING_MESSAGE_WITH_CODE.hasOwnProperty(i)){if(!this.items[i]&&e.indexOf(this.result.WARNING_MESSAGE_WITH_CODE[i])===-1){e+=this.result.WARNING_MESSAGE_WITH_CODE[i]+"<br/>"}}}}if(e){t.innerHTML=e;t.style.display=""}else{t.style.display="none";t.innerHTML=""}}},editBasketItemWarnings:function(){var t=this.getEntity(this.getCacheNode(this.ids.warning),"basket-item-warnings");if(BX.type.isDomNode(t)){if(this.warningItems.length){var e=this.getEntity(t,"basket-items-warning-count");if(BX.type.isDomNode(e)){e.innerHTML=this.warningItems.length+" "+this.getGoodsMessage(this.warningItems.length)}t.style.display=""}else if(t.style.display!=="none"){t.style.display="none";if(this.filter.isActive()){this.toggleFilter("all")}}}},toggleWarningBlock:function(){var t=this.getCacheNode(this.ids.warning);if(BX.type.isDomNode(t)){var e=this.getEntity(t,"basket-general-warnings");var i=this.getEntity(t,"basket-item-warnings");if((!BX.type.isDomNode(e)||e.style.display==="none")&&(!BX.type.isDomNode(i)||i.style.display==="none")){t.style.display="none"}else{t.style.display=""}}},checkBasketItemWarnings:function(t,e){if(!t)return;var i;if(this.items[t.ID]&&this.lastAction==="refreshAjax"){i=this.items[t.ID].WARNINGS}else{i=[]}if(BX.type.isArray(e[t.ID])&&e[t.ID].length){for(var s in e[t.ID]){if(e[t.ID].hasOwnProperty(s)&&!BX.util.in_array(e[t.ID][s],i)){i.push(e[t.ID][s])}}}if(i.length){if(!BX.util.in_array(t.ID,this.warningItems)){this.warningItems.push(t.ID)}}else if(BX.util.in_array(t.ID,this.warningItems)){this.warningItems.splice(BX.util.array_search(t.ID,this.warningItems),1)}return i},removeAllWarnings:function(t){this.clearGeneralWarnings();this.clearBasketItemsWarnings();this.editWarnings();t&&t.preventDefault()},clearGeneralWarnings:function(){this.result.WARNING_MESSAGE_WITH_CODE={};var t=this.getEntity(this.getCacheNode(this.ids.warning),"basket-general-warnings");if(BX.type.isDomNode(t)){t.innerHTML=""}},clearBasketItemsWarnings:function(){var t=[];for(var e in this.warningItems){if(this.warningItems.hasOwnProperty(e)){this.items[this.warningItems[e]].WARNINGS=[];if(this.isItemShown(this.warningItems[e])){t.push(this.warningItems[e])}}}this.warningItems=[];this.editBasketItems(t)},isItemShown:function(t){return BX.util.in_array(t,this.shownItems)},initializeBasketItems:function(){if(Object.keys(this.items).length===0)return;for(var t=0;t<this.sortedItems.length;t++){if(this.useDynamicScroll&&this.shownItems.length>=this.maxItemsShowCount){break}this.createBasketItem(this.sortedItems[t])}},createBasketItem:function(t){if(!this.items[t]){return}var e=this.getTemplate("basket-item-template");if(e){var i=this.renderBasketItem(e,this.items[t]);var s=BX.util.array_search(t,this.sortedItems);if(this.shownItems.length&&s>=0){if(s<BX.util.array_search(this.shownItems[0],this.sortedItems)){BX(this.ids.item+this.shownItems[0]).insertAdjacentHTML("beforebegin",i);this.shownItems.unshift(t)}else if(s>BX.util.array_search(this.shownItems[this.shownItems.length-1],this.sortedItems)){BX(this.ids.item+this.shownItems[this.shownItems.length-1]).insertAdjacentHTML("afterend",i);this.shownItems.push(t)}else{BX(this.ids.item+this.sortedItems[s+1]).insertAdjacentHTML("beforebegin",i);this.shownItems.splice(s+1,0,t)}}else{this.getCacheNode(this.ids.itemListTable).insertAdjacentHTML("beforeend",i);this.shownItems.push(t)}this.bindBasketItemEvents(this.items[t]);if(this.filter.isActive()){this.filter.highlightSearchMatch(this.items[t])}}},getItemsToEdit:function(){var t=[];if(this.isBasketChanged()){for(var e in this.changedItems){if(this.changedItems.hasOwnProperty(e)&&this.isItemShown(this.changedItems[e])){t.push(this.changedItems[e])}}}return t},getItemsAfter:function(){var t=[];if(this.useDynamicScroll){var e=this.shownItems[this.shownItems.length-1]||false;if(e){var i=0;var s=BX.util.array_search(e,this.sortedItems);while(this.sortedItems[++s]&&i++<this.maxItemsShowCount){t.push(this.sortedItems[s])}}}return t},editBasketItems:function(t){if(!t||t.length===0){return}var e,i;for(e in t){if(!t.hasOwnProperty(e)||!BX.type.isPlainObject(this.items[t[e]])){continue}i=this.items[t[e]];if(this.actionPool.isItemInPool(i.ID)){if(!BX.util.in_array(i.ID,this.postponedItems)){this.postponedItems.push(i.ID)}continue}if(BX.type.isDomNode(BX(this.ids.item+i.ID))){this.redrawBasketItemNode(i.ID);this.applyQuantityAnimation(i.ID)}else{this.createBasketItem(i.ID)}}},editPostponedBasketItems:function(){if(!this.postponedItems.length)return;var t=[];for(var e in this.postponedItems){if(this.postponedItems.hasOwnProperty(e)&&this.isItemShown(this.postponedItems[e])){t.push(this.postponedItems[e])}}this.postponedItems=[];this.editBasketItems(t)},applyQuantityAnimation:function(t){var e=BX(this.ids.item+t);if(BX.type.isDomNode(e)&&this.items[t]){if(this.items[t].QUANTITY_ANIMATION){BX.addClass(BX(this.ids.quantity+t),"basket-updated")}}},applyPriceAnimation:function(){if(!this.priceAnimationData||Object.keys(this.priceAnimationData.start).length===0)return;var t=this.priceAnimationData,e={};new BX.easing({duration:this.params.USE_PRICE_ANIMATION==="Y"?this.duration.priceAnimation:1,start:t.start,finish:t.finish,transition:BX.easing.makeEaseOut(BX.easing.transitions.quad),step:BX.delegate(function(i){for(var s in t.start){if(t.start.hasOwnProperty(s)){if(!e[s]){if(s===this.ids.total){e[s]=this.getEntities(this.getCacheNode(this.ids.basketRoot),this.ids.total)}else{var a=BX(s);e[s]=a?[a]:[]}}if(!t.int[s]){i[s]=(i[s]+i[s]%1e3/1e3).toFixed(5)}for(var n=0;n<e[s].length;n++){e[s][n].innerHTML=this.getFormatPrice(i[s],t.currency[s])}}}},this),complete:BX.delegate(function(){var i,s,a,n;for(i in t.start){if(t.start.hasOwnProperty(i)){s=this.getFormatPrice(t.finish[i],t.currency[i]);for(var r=0;r<e[i].length;r++){e[i][r].innerHTML=s}if(i.indexOf(this.ids.sumPrice)!==-1){n="SUM_PRICE";a=i.substr(this.ids.sumPrice.length)}else if(i.indexOf(this.ids.price)!==-1){n="PRICE";a=i.substr(this.ids.price.length)}else if(i.indexOf(this.ids.total)!==-1){n="TOTAL";a=""}else{a="";n=""}if(BX.type.isNotEmptyString(n)){if(a){this.items[a][n]=t.finish[i];delete this.items[a][n+"_NEW"];this.items[a][n+"_FORMATED"]=s;delete this.items[a][n+"_FORMATED_NEW"]}else if(n==="TOTAL"){this.result.TOTAL_RENDER_DATA.PRICE=t.finish[i];delete this.result.TOTAL_RENDER_DATA.PRICE_NEW;this.result.TOTAL_RENDER_DATA.PRICE_FORMATED=s;delete this.result.TOTAL_RENDER_DATA.PRICE_FORMATED_NEW}}}}this.filter.highlightFoundItems()},this)}).animate()},getFormatPrice:function(t,e){return BX.Currency.currencyFormat(t,e,true)},deleteBasketItems:function(t,e,i){if(!t||!t.length){return}for(var s in t){if(t.hasOwnProperty(s)){this.deleteBasketItem(t[s],e,i)}}},deleteBasketItem:function(t,e,i){if(this.items[t].NOT_AVAILABLE&&e){e=false;i=true}if(e){this.items[t].SHOW_RESTORE=true;this.items[t].SHOW_LOADING=false;this.redrawBasketItemNode(t)}else{this.changeShownItem(t);BX.remove(BX(this.ids.item+t))}if(i){this.changeSortedItem(t,false,true);this.changeShownItem(t,false,true)}},addSortedItem:function(t,e){this.sortedItems.push(t.toString());if(e&&this.filter.isActive()){this.filter.realSortedItems.push(t.toString())}},changeSortedItem:function(t,e,i){var s=BX.util.array_search(t,this.sortedItems);if(s>=0){if(e){this.sortedItems.splice(s,1,e.toString())}else{this.sortedItems.splice(s,1)}}if(i&&this.filter.isActive()){s=BX.util.array_search(t,this.filter.realSortedItems);if(s>=0){if(e){this.filter.realSortedItems.splice(s,1,e.toString())}else{this.filter.realSortedItems.splice(s,1)}}}},sortSortedItems:function(t){this.sortedItems.sort(BX.proxy(this.itemSortFunction,this));if(t&&this.filter.isActive()){this.filter.realSortedItems.sort(BX.proxy(this.itemSortFunction,this))}},changeShownItem:function(t,e,i){var s=BX.util.array_search(t,this.shownItems);if(s>=0){if(e){this.shownItems.splice(s,1,e.toString())}else{this.shownItems.splice(s,1)}}if(i&&this.filter.isActive()){s=BX.util.array_search(t,this.filter.realShownItems);if(s>=0){if(e){this.filter.realShownItems.splice(s,1,e.toString())}else{this.filter.realShownItems.splice(s,1)}}}},redrawBasketItemNode:function(t){var e=BX(this.ids.item+t);if(!this.items[t]||!BX.type.isDomNode(e))return;var i=this.getTemplate("basket-item-template");if(i){var s=BX(this.ids.itemHeightAligner+t),a;if(BX.type.isDomNode(s)){a=s.clientHeight}var n=this.renderBasketItem(i,this.items[t]);e.insertAdjacentHTML("beforebegin",n);BX.remove(e);if(a){s=BX(this.ids.itemHeightAligner+t);if(BX.type.isDomNode(s)&&s.clientHeight<a){s.style.minHeight=a+"px";setTimeout(function(){s.style.minHeight="0px"},1)}}this.bindBasketItemEvents(this.items[t]);if(this.filter.isActive()){this.filter.highlightSearchMatch(this.items[t])}}},restoreBasketItems:function(t){if(!t||Object.keys(t).length===0){return}var e,i,s;for(e in t){if(t.hasOwnProperty(e)){i=t[e];if(this.isItemShown(e)){this.changeShownItem(e,i,true);s=BX(this.ids.item+e);if(BX.type.isDomNode(s)){s.id=this.ids.item+i;s.setAttribute("data-id",i)}}this.changeSortedItem(e,false,true)}}},bindBasketItemEvents:function(t){if(!t)return;var e=BX(this.ids.item+t.ID);if(BX.type.isDomNode(e)){this.bindQuantityEvents(e,t);this.bindSkuEvents(e,t);this.bindImageEvents(e,t);this.bindActionEvents(e,t);this.bindRestoreAction(e,t);this.bindItemWarningEvents(e,t)}},bindQuantityEvents:function(t,e){if(!t||!e||!this.isItemAvailable(e.ID))return;var i;var s=this.getEntity(t,"basket-item-quantity-block");if(s){var a=this.isTouch?"touchstart":"mousedown";var n=this.isTouch?"touchend":"mouseup";i=this.getEntity(s,"basket-item-quantity-minus");BX.bind(i,a,BX.proxy(this.startQuantityInterval,this));BX.bind(i,n,BX.proxy(this.clearQuantityInterval,this));BX.bind(i,"mouseout",BX.proxy(this.clearQuantityInterval,this));BX.bind(i,"click",BX.proxy(this.quantityMinus,this));i=this.getEntity(s,"basket-item-quantity-plus");BX.bind(i,a,BX.proxy(this.startQuantityInterval,this));BX.bind(i,n,BX.proxy(this.clearQuantityInterval,this));BX.bind(i,"mouseout",BX.proxy(this.clearQuantityInterval,this));BX.bind(i,"click",BX.proxy(this.quantityPlus,this));i=this.getEntity(s,"basket-item-quantity-field");BX.bind(i,"change",BX.proxy(this.quantityChange,this))}},startQuantityInterval:function(){var t=BX.proxy_context;var e=t.getAttribute("data-entity")==="basket-item-quantity-minus"?BX.proxy(this.quantityMinus,this):BX.proxy(this.quantityPlus,this);this.quantityDelay=setTimeout(BX.delegate(function(){this.quantityTimer=setInterval(function(){e(t)},150)},this),300)},clearQuantityInterval:function(){clearTimeout(this.quantityDelay);clearInterval(this.quantityTimer)},quantityPlus:function(t){if(!BX.type.isDomNode(t)){t=BX.proxy_context;this.clearQuantityInterval()}var e=this.getItemDataByTarget(t);if(e){var i=BX(this.ids.quantity+e.ID);var s=this.isQuantityFloat(e);var a=s?parseFloat(i.value):Math.round(i.value);var n=s?parseFloat(e.MEASURE_RATIO):parseInt(e.MEASURE_RATIO);var r=parseFloat((a+n).toFixed(5));r=this.getCorrectQuantity(e,r);this.setQuantity(e,r)}},quantityMinus:function(t){t=BX.type.isDomNode(t)?t:BX.proxy_context;var e=this.getItemDataByTarget(t);if(e){var i=BX(this.ids.quantity+e.ID);var s=this.isQuantityFloat(e);var a=s?parseFloat(i.value):Math.round(i.value);var n=s?parseFloat(e.MEASURE_RATIO):parseInt(e.MEASURE_RATIO);var r=parseFloat((a-n).toFixed(5));r=this.getCorrectQuantity(e,r);this.setQuantity(e,r)}},quantityChange:function(){var t=this.getItemDataByTarget(BX.proxy_context);if(t){var e,i;e=BX(this.ids.quantity+t.ID);i=this.getCorrectQuantity(t,e.value);this.setQuantity(t,i)}},isQuantityFloat:function(t){return this.params.QUANTITY_FLOAT==="Y"||parseInt(t.MEASURE_RATIO)!==parseFloat(t.MEASURE_RATIO)},getCorrectQuantity:function(t,e){var i=this.isQuantityFloat(t),s=i?parseFloat(t.MEASURE_RATIO):parseInt(t.MEASURE_RATIO),a=0;e=(i?parseFloat(e):parseInt(e,10))||0;if(e<0){e=0}if(s>0&&e<s){e=s}if(t.CHECK_MAX_QUANTITY==="Y"){a=i?parseFloat(t.AVAILABLE_QUANTITY):parseInt(t.AVAILABLE_QUANTITY);if(a>0&&e>a){e=a}}var n=(e/s-(e/s).toFixed(0)).toFixed(5),r;if(parseFloat(n)===0){return e}if(s!==0&&s!==1){r=e*this.precisionFactor%(s*this.precisionFactor)/this.precisionFactor;if(s>0&&r>0){if(r>=s/2&&(a===0||e+s-r<=a)){e+=s-r}else{e-=r}}}e=i?parseFloat(e):parseInt(e,10);return e},setQuantity:function(t,e){var i=BX(this.ids.quantity+t.ID),s;if(i){e=parseFloat(e);s=parseFloat(i.getAttribute("data-value"));i.value=e;if(parseFloat(t.QUANTITY)!==parseFloat(e)){this.animatePriceByQuantity(t,e);this.actionPool.changeQuantity(t.ID,e,s)}}},animatePriceByQuantity:function(t,e){var i=BX(this.ids.sumPrice+t.ID);if(!BX.type.isDomNode(i))return;var s=e/parseFloat(t.MEASURE_RATIO);var a=parseFloat(t.SUM_PRICE),n=parseFloat(t.PRICE)*s,r=parseInt(a)===parseFloat(a)&&parseInt(n)===parseFloat(n);if(a!==n){this.items[t.ID].QUANTITY=e;this.items[t.ID].SUM_PRICE=n;new BX.easing({duration:this.params.USE_PRICE_ANIMATION==="Y"?this.duration.priceAnimation:1,start:{price:a},finish:{price:n},transition:BX.easing.makeEaseOut(BX.easing.transitions.quad),step:BX.delegate(function(e){if(!r){e.price=(e.price+e.price%1e3/1e3).toFixed(5)}i.innerHTML=this.getFormatPrice(e.price,t.CURRENCY)},this),complete:BX.delegate(function(){var e,a;i.innerHTML=this.getFormatPrice(n,t.CURRENCY);e=BX(this.ids.sumPriceOld+t.ID);if(BX.type.isDomNode(e)){a=parseFloat(t.FULL_PRICE)*s;e.innerHTML=this.getFormatPrice(a,t.CURRENCY)}e=BX(this.ids.sumPriceDiff+t.ID);if(BX.type.isDomNode(e)){a=parseFloat(t.DISCOUNT_PRICE)*s;e.innerHTML=this.getFormatPrice(a,t.CURRENCY)}},this)}).animate()}},getItemDataByTarget:function(t){var e=false;var i;var s=BX.findParent(t,{attrs:{"data-entity":"basket-item"}});if(s){i=s.getAttribute("data-id");e=this.items[i]}return e},bindSkuEvents:function(t,e){if(!t||!e)return;var i=this.getEntities(t,"basket-item-sku-block");var s,a,n,r,o;for(a=0,n=i.length;a<n;a++){s=this.getEntities(i[a],"basket-item-sku-field");for(r=0,o=s.length;r<o;r++){BX.bind(s[r],"click",BX.proxy(this.changeSku,this))}}},changeSku:function(){var t,e;var i=BX.proxy_context;if(BX.hasClass(i,"selected"))return;var s=this.getItemDataByTarget(i);if(s){var a=BX(this.ids.item+s.ID);if(a){var n=this.getEntities(i.parentNode,"basket-item-sku-field");for(t=0,e=n.length;t<e;t++){if(n[t].isEqualNode(i)){BX.addClass(n[t],"selected")}else{BX.removeClass(n[t],"selected")}}this.actionPool.changeSku(s.ID,this.getSkuPropertyValues(a),this.getInitialSkuPropertyValues(a))}}},getSkuPropertyValues:function(t){var e={};var i=this.getEntities(t,"basket-item-sku-field",".selected");for(var s=0,a=i.length;s<a;s++){e[i[s].getAttribute("data-property")]=BX.util.htmlspecialcharsback(i[s].getAttribute("data-value-id"))}return e},getInitialSkuPropertyValues:function(t){var e={};var i=this.getEntities(t,"basket-item-sku-field",'[data-initial="true"]');for(var s=0,a=i.length;s<a;s++){e[i[s].getAttribute("data-property")]=BX.util.htmlspecialcharsback(i[s].getAttribute("data-value-id"))}return e},bindImageEvents:function(t,e){if(!t||!e)return;var i=t.querySelectorAll(".basket-item-custom-block-photo-item");for(var s=0,a=i.length;s<a;s++){BX.bind(i[s],"click",BX.proxy(this.showPropertyImagePopup,this))}},showPropertyImagePopup:function(){var t,e,i,s,a,n;t=BX.proxy_context;s=this.getItemDataByTarget(t);e=t.getAttribute("data-column-property-code");i=t.getAttribute("data-image-index");if(s&&s.COLUMN_LIST){for(n in s.COLUMN_LIST){if(s.COLUMN_LIST.hasOwnProperty(n)&&s.COLUMN_LIST[n].CODE===e&&s.COLUMN_LIST[n].VALUE[i]){a=s.COLUMN_LIST[n].VALUE[i].IMAGE_SRC_ORIGINAL;break}}}if(!a){return}if(this.imagePopup){this.imagePopup.destroy()}var r="bx-soa-image-popup-content";var o=this;this.imagePopup=new BX.PopupWindow("bx-soa-image-popup",null,{lightShadow:true,offsetTop:0,offsetLeft:0,closeIcon:{top:"3px",right:"10px"},autoHide:true,bindOptions:{position:"bottom"},closeByEsc:true,zIndex:100,events:{onPopupShow:function(){BX.create("IMG",{props:{src:a},events:{load:function(){var t=BX(r);if(t){var e=BX.GetWindowInnerSize(),i=o.isMobile?.5:.9,s,a;BX.cleanNode(t);t.appendChild(this);s=t.offsetHeight;a=t.offsetWidth;if(s>e.innerHeight*i){t.style.height=e.innerHeight*i+"px";t.style.width=a*(e.innerHeight*i/s)+"px";s=t.offsetHeight;a=t.offsetWidth}if(a>e.innerWidth*i){t.style.width=e.innerWidth*i+"px";t.style.height=s*(e.innerWidth*i/a)+"px"}t.style.height=t.offsetHeight+"px";t.style.width=t.offsetWidth+"px";o.imagePopup.adjustPosition()}}}})},onPopupClose:function(){this.destroy()}},content:BX.create("DIV",{props:{id:r}})});this.imagePopup.show()},bindActionEvents:function(t,e){if(!t||!e)return;var i;if(BX.util.in_array("DELETE",this.params.COLUMNS_LIST)){i=this.getEntities(t,"basket-item-delete");for(var s=0,a=i.length;s<a;s++){BX.bind(i[s],"click",BX.proxy(this.deleteAction,this))}}if(BX.util.in_array("DELAY",this.params.COLUMNS_LIST)){i=this.getEntity(t,"basket-item-add-delayed");BX.bind(i,"click",BX.proxy(this.addDelayedAction,this))}i=this.getEntity(t,"basket-item-remove-delayed");BX.bind(i,"click",BX.proxy(this.removeDelayedAction,this));i=this.getEntity(t,"basket-item-merge-sku-link");BX.bind(i,"click",BX.proxy(this.mergeAction,this));i=this.getEntity(t,"basket-item-show-similar-link");BX.bind(i,"click",BX.delegate(function(){this.toggleFilter("similar")},this))},deleteAction:function(){var t=this.getItemDataByTarget(BX.proxy_context);if(t){this.actionPool.deleteItem(t.ID);this.items[t.ID].SHOW_LOADING=true;if(this.params.SHOW_RESTORE==="Y"&&this.isItemAvailable(t.ID)){this.items[t.ID].SHOW_RESTORE=true}this.redrawBasketItemNode(t.ID)}},addDelayedAction:function(){var t=this.getItemDataByTarget(BX.proxy_context);if(t){this.actionPool.addDelayed(t.ID);this.items[t.ID].SHOW_LOADING=true;this.redrawBasketItemNode(t.ID)}},removeDelayedAction:function(){var t=this.getItemDataByTarget(BX.proxy_context);if(t){this.actionPool.removeDelayed(t.ID);this.items[t.ID].SHOW_LOADING=true;this.redrawBasketItemNode(t.ID)}},mergeAction:function(){var t=this.getItemDataByTarget(BX.proxy_context);if(t){this.actionPool.mergeSku(t.ID)}},bindRestoreAction:function(t,e){if(!t||!e||this.params.SHOW_RESTORE!=="Y")return;BX.bind(this.getEntity(t,"basket-item-restore-button"),"click",BX.delegate(function(){this.actionPool.restoreItem(e.ID,{PRODUCT_ID:e.PRODUCT_ID,QUANTITY:e.QUANTITY,PROPS:e.PROPS_ALL,SORT:e.SORT,MODULE:e.MODULE,PRODUCT_PROVIDER_CLASS:e.PRODUCT_PROVIDER_CLASS});this.items[e.ID].SHOW_RESTORE=false;this.items[e.ID].SHOW_LOADING=true;this.redrawBasketItemNode(e.ID)},this));BX.bind(this.getEntity(t,"basket-item-close-restore-button"),"click",BX.delegate(function(){this.deleteBasketItem(e.ID,false,true)},this))},bindItemWarningEvents:function(t,e){if(!t||!e)return;BX.bind(this.getEntity(BX(this.ids.item+e.ID),"basket-item-warning-close"),"click",BX.proxy(this.closeItemWarnings,this))},closeItemWarnings:function(){var t=BX.proxy_context;if(BX.type.isDomNode(t)){var e=this.getItemDataByTarget(t);this.items[e.ID].WARNINGS=[];this.warningItems.splice(BX.util.array_search(e.ID,this.warningItems),1);this.redrawBasketItemNode(e.ID);this.editWarnings()}},renderBasketItem:function(t,e){var i=BX.clone(e);if(BX.type.isPlainObject(i)){i.USE_FILTER=this.useItemsFilter&&!this.filter.currentFilter.similarHash.length}return Mustache.render(t,i)},render:function(t,e){return Mustache.render(t,e)},checkAnalytics:function(t){if(!t||!t.basket)return;var e,i={};for(var s in t.basket){if(t.basket.hasOwnProperty(s)){if(s.indexOf("QUANTITY_")>=0){e=s.substr(9);if(this.items[e]){i[e]=parseFloat(t.basket[s])-parseFloat(BX(this.ids.quantity+e).getAttribute("data-value"))}}else if(s.indexOf("DELETE_")>=0){e=s.substr(7);if(this.items[e]){i[e]=-parseFloat(this.items[e].QUANTITY)}}else if(s.indexOf("RESTORE_")>=0){e=s.substr(8);if(this.items[e]){i[e]=parseFloat(this.items[e].QUANTITY)}}}}this.setAnalyticsDataLayer(i)},setAnalyticsDataLayer:function(t){if(!t||Object.keys(t).length===0)return;window[this.params.DATA_LAYER_NAME]=window[this.params.DATA_LAYER_NAME]||[];var e=[],i=[];for(var s in t){if(t.hasOwnProperty(s)){if(t[s]>0){e.push(this.getItemAnalyticsInfo(s,t[s]))}else if(t[s]<0){i.push(this.getItemAnalyticsInfo(s,t[s]))}}}if(e.length){window[this.params.DATA_LAYER_NAME].push({event:"addToCart",ecommerce:{currencyCode:this.items[s].CURRENCY||"",add:{products:e}}})}if(i.length){window[this.params.DATA_LAYER_NAME].push({event:"removeFromCart",ecommerce:{currencyCode:this.items[s].CURRENCY||"",remove:{products:i}}})}},getItemAnalyticsInfo:function(t,e){if(!this.items[t])return{};var i=(this.items[t].BRAND||"").split(", ").join("/");var s=[];var a=this.getEntities(BX(this.ids.item+t),"basket-item-sku-field",".selected");for(var n=0,r=a.length;n<r;n++){s.push(a[n].getAttribute("data-sku-name"))}return{name:this.items[t].NAME||"",id:this.items[t].ID||"",price:this.items[t].PRICE||0,brand:i,variant:s.join("/"),quantity:Math.abs(e)}}}})(); //# sourceMappingURL=component.map.js