(function(){'use strict';$.widget('SwatchRendererTooltip',{options:{delay:200,tooltipClass:'swatch-option-tooltip'},_init:function(){var $widget=this,$this=this.element,$element=$('.'+$widget.options.tooltipClass),timer,type=parseInt($this.data('option-type'),10),label=$this.data('option-label'),thumb=$this.data('option-tooltip-thumb'),value=$this.data('option-tooltip-value'),width=$this.data('thumb-width'),height=$this.data('thumb-height'),$image,$title,$corner;if(!$element.length){$element=$('
');$('body').append($element);} $image=$element.find('.image');$title=$element.find('.title');$corner=$element.find('.corner');$this.hover(function(){if($this.hasClass('disabled')){return;} timer=setTimeout(function(){var leftOpt=null,leftCorner=0,left,$window;if(type===2){$image.css({'background':'url("'+thumb+'") no-repeat center','background-size':'initial','width':width+'px','height':height+'px'});$image.show();}else if(type===1){$image.css({background:value});$image.show();}else if(type===0||type===3){$image.hide();} $title.text(label);$element.hide();$element.show();leftOpt=$this.offset().left;left=leftOpt+$this.width()/ 2-$element.width()/ 2;$window=$(window);if(left<0){left=5;}else if(left+$element.width()>$window.width()){left=$window.width()-$element.width()-5;} leftCorner=0;if($element.width()<$this.width()){leftCorner=$element.width()/ 2-3;}else{leftCorner=(leftOpt>left?leftOpt-left:left-leftOpt)+$this.width()/ 2-6;} $corner.css({left:leftCorner});$element.css({left:left,top:$this.offset().top-$element.height()-$corner.height()-18}).show();},$widget.options.delay);},function(){$element.hide();clearTimeout(timer);});$(document).on('tap.SwatchRendererTooltip',function(){$element.hide();clearTimeout(timer);});$this.on('tap',function(event){event.stopPropagation();});},destroy:function(){$(document).off('tap.SwatchRendererTooltip');this._super();}});$.widget('SwatchRenderer',{component:'Magento_Swatches/js/swatch-renderer',options:{classes:{attributeClass:'swatch-attribute',attributeLabelClass:'swatch-attribute-label',attributeSelectedOptionLabelClass:'swatch-attribute-selected-option',attributeOptionsWrapper:'swatch-attribute-options',attributeInput:'swatch-input',optionClass:'swatch-option',selectClass:'swatch-select',moreButton:'swatch-more',loader:'swatch-option-loading'},jsonConfig:{},jsonSwatchConfig:{},selectorProduct:'.product-info-main',selectorProductPrice:'[data-role=priceBox]',mediaGallerySelector:'[data-gallery-role=gallery-placeholder]',selectorProductTile:'.product-item',numberToShow:false,onlySwatches:false,enableControlLabel:true,controlLabelId:'',moreButtonText:$.__('More'),mediaCallback:'',mediaCache:{},mediaGalleryInitial:[{}],useAjax:false,gallerySwitchStrategy:'replace',inProductList:false,slyOldPriceSelector:'.sly-old-price',slyOldPricepercent:'.discount-percent',tierPriceTemplateSelector:'#tier-prices-template',tierPriceBlockSelector:'[data-role="tier-price-block"]',tierPriceTemplate:'',normalPriceLabelSelector:'.product-info-main .normal-price .price-label'},getProduct:function(){var products=this._CalcProducts();return _.isArray(products)?products[0]:null;},getProductId:function(){var products=this._CalcProducts();return _.isArray(products)&&products.length===1?products[0]:null;},_init:function(){if($(this.element).attr('data-rendered')){return;} this._markup=this.element.html();$(this.element).attr('data-rendered',true);if(_.isEmpty(this.options.jsonConfig.images)){this.options.useAjax=true;this._debouncedLoadProductMedia=_.debounce(this._LoadProductMedia.bind(this),500);} this.options.tierPriceTemplate=$(this.options.tierPriceTemplateSelector).html();if(this.options.jsonConfig!==''&&this.options.jsonSwatchConfig!==''){this.options.jsonConfig.mappedAttributes=_.clone(this.options.jsonConfig.attributes);this._sortAttributes();this._RenderControls();this._setPreSelectedGallery();$(this.element).trigger('swatch.initialized');}else{console.log('SwatchRenderer: No input data received');}},destroy:function(){$(this.element).removeAttr('data-rendered').html(this._markup);this._super();},_sortAttributes:function(){this.options.jsonConfig.attributes=_.sortBy(this.options.jsonConfig.attributes,function(attribute){return parseInt(attribute.position,10);});},_create:function(){var options=this.options,gallery=$('.column.main').find('[data-gallery-role="gallery-placeholder"]'),productData=this._determineProductData(),$main=productData.isInProductView?this.element.parents('.column.main'):this.element.parents('.product-item-info');if(productData.isInProductView){gallery.gallery('instance')?this._onGalleryLoaded(gallery):gallery.on('gallery:loaded',this._onGalleryLoaded.bind(this,gallery));}else{options.mediaGalleryInitial=[{'img':$main.find('.product-image-photo').attr('src')}];} this.productForm=this.element.parents(this.options.selectorProductTile).find('form').first('first');this.inProductList=this.productForm.length>0;},_determineProductData:function(){var productId,isInProductView=false;productId=this.element.parents('.product-item-info').find('.price-box.price-final_price').attr('data-product-id');if(!productId){productId=$('[name=product]').val();isInProductView=productId>0;} return{productId:productId,isInProductView:isInProductView};},_RenderControls:function(){var $widget=this,container=this.element,classes=this.options.classes,chooseText=this.options.jsonConfig.chooseText,showTooltip=this.options.showTooltip;$widget.optionsMap={};$.each(this.options.jsonConfig.attributes,function(){var item=this,controlLabelId='option-label-'+item.code+'-'+item.id,options=$widget._RenderSwatchOptions(item,controlLabelId),select=$widget._RenderSwatchSelect(item,chooseText),input=$widget._RenderFormInput(item),listLabel='',label='';if($widget.options.onlySwatches&&!$widget.options.jsonSwatchConfig.hasOwnProperty(item.id)){return;} if($widget.options.enableControlLabel){label+=''+ $('').text(item.label).html()+' : '+'';} if($widget.inProductList){$widget.productForm.append(input);input='';listLabel='aria-label="'+$('').text(item.label).html()+'"';}else{listLabel='aria-labelledby="'+controlLabelId+'"';} container.append('
'+ label+'
'+ options+select+'
'+input+'
');if(!$('body').hasClass('catalog-product-view')){$('.swatch-attribute.size').hide()} $widget.optionsMap[item.id]={};$.each(item.options,function(){if(this.products.length>0){$widget.optionsMap[item.id][this.id]={price:parseInt($widget.options.jsonConfig.optionPrices[this.products[0]].finalPrice.amount,10),products:this.products};}});});if(showTooltip===1){container.find('[data-option-type="1"], [data-option-type="2"],'+' [data-option-type="0"], [data-option-type="3"]').SwatchRendererTooltip();} $('.'+classes.moreButton).nextAll().hide();$widget._EventListener();$widget._Rewind(container);setTimeout(function(){$widget._EmulateSelected($.parseQuery());$widget._EmulateSelected($widget._getSelectedAttributes());},80);},_RenderSwatchOptions:function(config,controlId){var optionConfig=this.options.jsonSwatchConfig[config.id],optionClass=this.options.classes.optionClass,sizeConfig=this.options.jsonSwatchImageSizeConfig,moreLimit=parseInt(this.options.numberToShow,10),moreClass=this.options.classes.moreButton,moreText=this.options.moreButtonText,countAttributes=0,html='';if(!this.options.jsonSwatchConfig.hasOwnProperty(config.id)){return'';} $.each(config.options,function(index){var id,type,value,thumb,label,width,height,attr,swatchImageWidth,swatchImageHeight;if(!optionConfig.hasOwnProperty(this.id)){return'';} if(moreLimit===countAttributes++){html+=''+moreText+'';} id=this.id;type=parseInt(optionConfig[id].type,10);value=optionConfig[id].hasOwnProperty('value')?$('').text(optionConfig[id].value).html():'';thumb=optionConfig[id].hasOwnProperty('thumb')?optionConfig[id].thumb:'';width=_.has(sizeConfig,'swatchThumb')?sizeConfig.swatchThumb.width:110;height=_.has(sizeConfig,'swatchThumb')?sizeConfig.swatchThumb.height:90;label=this.label?$('').text(this.label).html():'';attr=' index="'+index+'"'+' aria-checked="false"'+' aria-describedby="'+controlId+'"'+' tabindex="0"'+' data-option-type="'+type+'"'+' data-option-id="'+id+'"'+' data-option-label="'+label+'"'+' aria-label="'+label+'"'+' role="option"'+' data-thumb-width="'+width+'"'+' data-thumb-height="'+height+'"';attr+=thumb!==''?' data-option-tooltip-thumb="'+thumb+'"':'';attr+=value!==''?' data-option-tooltip-value="'+value+'"':'';swatchImageWidth=_.has(sizeConfig,'swatchImage')?sizeConfig.swatchImage.width:30;swatchImageHeight=_.has(sizeConfig,'swatchImage')?sizeConfig.swatchImage.height:17;if(!this.hasOwnProperty('products')||this.products.length<=0){attr+=' data-option-empty="true"';} if(type===0){html+='
'+(value?value:label)+'
';}else if(type===1){html+='
'+''+'
';}else if(type===2){html+='
'+''+'
';}else if(type===3){html+='
';}else{html+='
'+label+'
';}});return html;},_RenderSwatchSelect:function(config,chooseText){var html;if(this.options.jsonSwatchConfig.hasOwnProperty(config.id)){return'';} html='';return html;},_RenderFormInput:function(config){return'';},_EventListener:function(){var $widget=this,options=this.options.classes,target;$widget.element.on('click','.'+options.optionClass,function(){return $widget._OnClick($(this),$widget);});$widget.element.on('change','.'+options.selectClass,function(){return $widget._OnChange($(this),$widget);});$widget.element.on('click','.'+options.moreButton,function(e){e.preventDefault();return $widget._OnMoreClick($(this));});$widget.element.on('keydown',function(e){if(e.which===13){target=$(e.target);if(target.is('.'+options.optionClass)){return $widget._OnClick(target,$widget);}else if(target.is('.'+options.selectClass)){return $widget._OnChange(target,$widget);}else if(target.is('.'+options.moreButton)){e.preventDefault();return $widget._OnMoreClick(target);}}});},_loadMedia:function(){var $main=this.inProductList?this.element.parents('.product-item-info'):this.element.parents('.column.main'),images;if(this.options.useAjax){this._debouncedLoadProductMedia();}else{images=this.options.jsonConfig.images[this.getProduct()];if(!images){images=this.options.mediaGalleryInitial;} this.updateBaseImage(this._sortImages(images),$main,!this.inProductList);}},_sortImages:function(images){return _.sortBy(images,function(image){return parseInt(image.position,10);});},_OnClick:function($this,$widget){var $parent=$this.parents('.'+$widget.options.classes.attributeClass),$wrapper=$this.parents('.'+$widget.options.classes.attributeOptionsWrapper),$label=$parent.find('.'+$widget.options.classes.attributeSelectedOptionLabelClass),attributeId=$parent.data('attribute-id'),$input=$parent.find('.'+$widget.options.classes.attributeInput),checkAdditionalData=JSON.parse(this.options.jsonSwatchConfig[attributeId]['additional_data']),$priceBox=$widget._getProductWrapper().find(this.options.selectorProductPrice);if($widget.inProductList){$input=$widget.productForm.find('.'+$widget.options.classes.attributeInput+'[name="super_attribute['+attributeId+']"]');} if($this.hasClass('disabled')){return;} if($this.hasClass('selected')){$parent.removeAttr('data-option-selected').find('.selected').removeClass('selected');$input.val('');$label.text('');$this.attr('aria-checked',false);}else{$parent.attr('data-option-selected',$this.data('option-id')).find('.selected').removeClass('selected');$label.text($this.data('option-label'));$input.val($this.data('option-id'));$input.attr('data-attr-name',this._getAttributeCodeById(attributeId));$this.addClass('selected');$widget._toggleCheckedAttributes($this,$wrapper);} $widget._Rebuild();if($priceBox.priceBox('instance')){$widget._UpdatePrice();} $(document).trigger('updateMsrpPriceBlock',[this._getSelectedOptionPriceIndex(),$widget.options.jsonConfig.optionPrices,$priceBox]);if(parseInt(checkAdditionalData['update_product_preview_image'],10)===1){$widget._loadMedia();} $input.trigger('change');},_getSelectedOptionPriceIndex:function(){var allowedProduct=this._getAllowedProductWithMinPrice(this._CalcProducts());if(_.isEmpty(allowedProduct)){return undefined;} return allowedProduct;},_getAttributeCodeById:function(attributeId){var attribute=this.options.jsonConfig.mappedAttributes[attributeId];return attribute?attribute.code:attributeId;},_toggleCheckedAttributes:function($this,$wrapper){$wrapper.attr('aria-activedescendant',$this.attr('id')).find('.'+this.options.classes.optionClass).attr('aria-checked',false);$this.attr('aria-checked',true);},_OnChange:function($this,$widget){var $parent=$this.parents('.'+$widget.options.classes.attributeClass),attributeId=$parent.data('attribute-id'),$input=$parent.find('.'+$widget.options.classes.attributeInput);if($widget.productForm.length>0){$input=$widget.productForm.find('.'+$widget.options.classes.attributeInput+'[name="super_attribute['+attributeId+']"]');} if($this.val()>0){$parent.attr('data-option-selected',$this.val());$input.val($this.val());}else{$parent.removeAttr('data-option-selected');$input.val('');} $widget._Rebuild();$widget._UpdatePrice();$widget._loadMedia();$input.trigger('change');},_OnMoreClick:function($this){$this.nextAll().show();$this.blur().remove();},_Rewind:function(controls){controls.find('div[data-option-id], option[data-option-id]').removeClass('disabled').removeAttr('disabled');controls.find('div[data-option-empty], option[data-option-empty]').attr('disabled',true).addClass('disabled').attr('tabindex','-1');},_Rebuild:function(){var $widget=this,controls=$widget.element.find('.'+$widget.options.classes.attributeClass+'[data-attribute-id]'),selected=controls.filter('[data-option-selected]');$widget._Rewind(controls);if(selected.length<=0){return;} controls.each(function(){var $this=$(this),id=$this.data('attribute-id'),products=$widget._CalcProducts(id);if(selected.length===1&&selected.first().data('attribute-id')===id){return;} $this.find('[data-option-id]').each(function(){var $element=$(this),option=$element.data('option-id');if(!$widget.optionsMap.hasOwnProperty(id)||!$widget.optionsMap[id].hasOwnProperty(option)||$element.hasClass('selected')||$element.is(':selected')){return;} if(_.intersection(products,$widget.optionsMap[id][option].products).length<=0){$element.attr('disabled',true).addClass('disabled');}});});},_CalcProducts:function($skipAttributeId){var $widget=this,selectedOptions='.'+$widget.options.classes.attributeClass+'[data-option-selected]',products=[];$widget.element.find(selectedOptions).each(function(){var id=$(this).data('attribute-id'),option=$(this).attr('data-option-selected');if($skipAttributeId!==undefined&&$skipAttributeId===id){return;} if(!$widget.optionsMap.hasOwnProperty(id)||!$widget.optionsMap[id].hasOwnProperty(option)){return;} if(products.length===0){products=$widget.optionsMap[id][option].products;}else{products=_.intersection(products,$widget.optionsMap[id][option].products);}});return products;},_UpdatePrice:function(){var $widget=this,$product=$widget._getProductWrapper(),$productPrice=$product.find(this.options.selectorProductPrice),result=$widget._getNewPrices(),tierPriceHtml,isShow;$productPrice.trigger('updatePrice',{'prices':$widget._getPrices(result,$productPrice.priceBox('option').prices)});isShow=typeof result!='undefined'&&result.oldPrice.amount!==result.finalPrice.amount;$productPrice.find('span').first().toggleClass('special-price',isShow);$product.find(this.options.slyOldPricepercent)[isShow?'show':'hide']();$product.find(this.options.slyOldPriceSelector)[isShow?'show':'hide']();if(typeof result!='undefined'&&result.tierPrices&&result.tierPrices.length){if(this.options.tierPriceTemplate){tierPriceHtml=_.template(this.options.tierPriceTemplate)({'tierPrices':result.tierPrices,'$t':$.__,'currencyFormat':this.options.jsonConfig.currencyFormat,'priceUtils':$.catalog.priceUtils});$(this.options.tierPriceBlockSelector).html(tierPriceHtml).show();}}else{$(this.options.tierPriceBlockSelector).hide();} $(this.options.normalPriceLabelSelector).hide();_.each($('.'+this.options.classes.attributeOptionsWrapper),function(attribute){if($(attribute).find('.'+this.options.classes.optionClass+'.selected').length===0){if($(attribute).find('.'+this.options.classes.selectClass).length>0){_.each($(attribute).find('.'+this.options.classes.selectClass),function(dropdown){if($(dropdown).val()==='0'){$(this.options.normalPriceLabelSelector).show();}}.bind(this));}else{$(this.options.normalPriceLabelSelector).show();}}}.bind(this));},_getProductWrapper:function(){var selector=this.options.selectorProduct.replace('.product-item-details','.product-item-details'),wrapper=this.element.closest(selector);if(!wrapper.length){wrapper=this.element.closest('.column.main').find(selector);} return wrapper;},_getNewPrices:function(){var $widget=this,newPrices=$widget.options.jsonConfig.prices,allowedProduct=this._getAllowedProductWithMinPrice(this._CalcProducts());if(!_.isEmpty(allowedProduct)){newPrices=this.options.jsonConfig.optionPrices[allowedProduct];} var discountPer=Math.round((1-(newPrices.finalPrice.amount / newPrices.baseOldPrice.amount))*100);if(discountPer<5){$('[data-product-id="'+$widget.options.jsonConfig.productId+'"]').find('.discount-percent').hide();}else{$('[data-product-id="'+$widget.options.jsonConfig.productId+'"]').find('.discount-percent').text(discountPer+'% off');} return newPrices;},_getPrices:function(newPrices,displayPrices){var $widget=this;if(_.isEmpty(newPrices)){newPrices=$widget._getNewPrices();} _.each(displayPrices,function(price,code){if(newPrices[code]){displayPrices[code].amount=newPrices[code].amount-displayPrices[code].amount;}});return displayPrices;},_getAllowedProductWithMinPrice:function(allowedProducts){var optionPrices=this.options.jsonConfig.optionPrices,product={},optionFinalPrice,optionMinPrice;_.each(allowedProducts,function(allowedProduct){optionFinalPrice=parseFloat(optionPrices[allowedProduct].finalPrice.amount);if(_.isEmpty(product)||optionFinalPrice