var friendsSelected = 0; $(window).ready(function(){ runACCS(); $(".prodFriendsBlock .presentRow select").click(function(){ event.preventDefault(); return false; }); $(".prodFriendsBlock .presentRow select").change(function(){accsSELECT(this);}); /* $(".prodFriends .presentRow").click(function(){accsCLICK(this);}); */ }); function runACCS(){ // var items=''; $(".prodFriendsBlock").each(function(i,a){ e=0; link=''; // len = $(".prodFriendsBlock:eq("+i+") .presentRow.active").length; $(".prodFriendsBlock:eq("+i+") .presentRow.active").each(function(){ e=e+1; pName = $(this).attr('name'); salePrice = $(this).find('[name='+pName+']').attr('data-price'); listPrice = $(this).find('[name='+pName+']').attr('data-listprice'); Img = $(this).find('[name='+pName+']').attr('data-img'); $(this).find('.salePrice').html(salePrice+' р.'); link=link+'service[]='+$(this).find(".presentOpts [name="+pName+"]").val()+'&'; if(Img){ $(this).find('.imgContainer').html(''); } /* if($(this).find('[name='+pName+'] option:selected').attr('data-model')!=undefined){ items=items+' • '+$(this).find('[name='+pName+'] option:selected').attr('data-model'); } */ }); link = link+'service[]='+$("#nomID").val()+'&qty=1'; friendsSelected = e; if(e>0){ $(".accs_selected b").html('Выбрано дополнений: '+e+' шт.'); $(".prodFriendsBlock:eq("+i+") .accsCTA").removeClass('inactive').attr('href','/tiny/services.php?'+link); }else{ $(".accs_selected b").html('Дополнений не выбрано'); $(".prodFriendsBlock:eq("+i+") .accsCTA").addClass('inactive').attr('href','#'); } }); } function accsCLICK(that){ if($(that).hasClass('active')){ $(that).removeClass('active'); activateSelectOption(that,'false'); }else{ $(that).addClass('active'); activateSelectOption(that,'true'); } runACCS(); } function accsSELECT(that){ newPrice = $(that).find("option:selected").attr('data-price'); newListPrice = $(that).find("option:selected").attr('data-listprice'); newImg = $(that).find("option:selected").attr('data-img'); itemID = $(that).find("option:selected").val(); $(that).attr('data-price',newPrice).attr('data-listprice',newListPrice).attr('data-img',newImg); $(that).find("option").attr('data-userselected','0'); $(that).find("option[value!='']:selected").attr('data-userselected','1'); row = $(".prodFriendsBlock .presentRow[name="+$(that).attr('name')+"]"); if($(that).val()!='' && !$(row).hasClass('active')){ accsCLICK(row); }else if($(that).val()=='' && $(row).hasClass('active')){ accsCLICK(row); }else{ runACCS(); } } function activateSelectOption(that,state){ if($(that).find("select")){ if(state=='true'){ if($(that).find("select option:selected").val()==''){ $(that).find("select option").prop('selected',false); if($(that).find("select option[data-userselected=1]").length>0){ $(that).find("select option[data-userselected=1]").prop('selected',true); }else{ $(that).find("select option[data-default=1]").prop('selected',true); } } }else{ if($(that).find("select option:selected").val()!=''){ $(that).find("select option").prop('selected',false); $(that).find("select option[value='']").prop('selected',true); } } } }