$(document).ready(function() { let url = 'https://partnermap.surgaz.ru/'; let yandexKey = 'c0b867b6-9b65-4d9c-a44b-c54f2e8914a2'; let brand = 'ARTSIMPLE'; let info = 'Оптовые поставки обоев'; let domain = 'artsimple.ru'; let icons = [[], [41, 50], [20, 50]]; $("script[id='partners']").after('
'+brand+'
'+info+'
Карта партнеров
розничные продажи
оптовые продажи
колеровка на месте
'),$.ajax({url:url+"?domain="+domain+"&ajax=",dataType:"json",success:function(t){partners=t.partners,region=t.region,city=t.city,ymaps.ready((function(){init()}))}}),$.ajax({url:"https://api-maps.yandex.com/2.1/?lang=ru_RU&apikey="+yandexKey,async:!1});let myLocation,searchCity,actionend=!1,p_partners=$("div#p-partners"),p_search_input=p_partners.find("#p-search-input"),p_filter=p_partners.find("#p-filter div"),p_sales0=p_partners.find("#p-sales0"),p_sales1=p_partners.find("#p-sales1"),p_color=p_partners.find("#p-color"),p_map=p_partners.find("#p-map"),p_list=p_partners.find("#p-list"),p_mode_map=p_partners.find("#p-mode-map"),p_mode_list=p_partners.find("#p-mode-list"),p_mobile=!1;function init(){let t={type:"FeatureCollection",features:[]};partners.forEach((function(e){let i='
',s="";void 0!==region[e.region]?e.region=region[e.region]:e.region="",void 0!==city[e.city]?e.city=city[e.city]:e.city="",""!=e.region&&e.region!=e.city&&(s+=e.region+", "),""!=e.city&&(s+=e.city+", "),s+=e.address;let a=e.phone;a=a.split("\n"),a.forEach((function(t,e){t=t.split(" (доб"),a[e]=''+t[0]+"",t.length>1&&(a[e]+=" (доб"+t[1])})),a=a.join("
");let o=e.schedule.replace(/\n/g,"
");i+=s+"
",""!=e.phone&&(i+="
"+a+"
"),""!=o&&(i+="
"+o+"
"),""!=e.website&&(i+='
Перейти на сайт
'),i+="
",t.features.push({type:"Feature",geometry:{type:"Point",coordinates:[e.lon,e.lat]},properties:{id:e.id,central:e.central,sales:e.sales,color:e.color,balloonContentHeader:e.name,balloonContentBody:i,hintContent:"Побробнее >>"},options:{hideIconOnBalloonOpen:!1,balloonOffset:[5,-icons[e.brand][1]/1.5],iconLayout:"default#image",iconImageHref:url+"media/icon/"+e.brand+".png",iconImageSize:icons[e.brand]}});let l="no_image.jpg";""!=e.image&&(l=e.image);let n='
';1==e.central&&(n+='
'),n+='',""!=e.website&&(n+='
'),n+='
'+e.name+"
"+s+"
",""!=a&&(n+='
'+a+"
"),n+='
',""!=e.website&&(n+='
'),""!=o&&(n+='
Режим работы
'+o+"
"),""==e.whatsapp&&""==e.telegram&&""==e.vk&&""==e.youtube||(n+='
',""!=e.whatsapp&&(n+=''),""!=e.telegram&&(n+=''),""!=e.vk&&(n+=''),""!=e.youtube&&(n+=''),n+="
"),n+="
",p_list.append(n)})),p_card=p_list.find("> .p-card"),p_card.find("button").on("click",(function(){p_mobile&&p_mode_map.trigger("click"),p_card.removeClass("active");let t=objects.search("properties.id = "+$(this).parents(".p-card").addClass("active").attr("data-id")).get(0);myMap.setCenter(t.geometry.getCoordinates(),14),t.balloon.open()})),objects=ymaps.geoQuery(t).addToMap(myMap),myMap.events.fire("actionend")}function scroll(t,e){void 0===e&&(e=t.offset().top,t=$("html")),t.animate({scrollTop:e},300)}function scrollList(){"block"==p_list.css("display")&&setTimeout((function(){p_list[0].scrollHeight>p_list.height()?p_list.addClass("scroll"):p_list.removeClass("scroll")}),500)}p_partners.find("#p-mode:visible").length&&(p_mobile=!0),ymaps.ready((function(){myMap=new ymaps.Map("p-map",{center:[55.76,37.64],zoom:10,controls:["typeSelector","zoomControl"]}),p_filter.on("click",(function(){let t=[];$(this).toggleClass("active"),p_filter.hasClass("active")||(t=objects),p_color.hasClass("active")?(t=objects.search("properties.color = 1"),p_sales0.hasClass("active")&&!p_sales1.hasClass("active")?t=t.search("properties.sales = 0"):!p_sales0.hasClass("active")&&p_sales1.hasClass("active")&&(t=t.search("properties.sales = 1"))):(p_sales0.hasClass("active")&&(t=objects.search("properties.sales = 0")),p_sales1.hasClass("active")&&(t=objects.search("properties.sales = 1").add(t))),objects.setOptions("visible",!1),t.setOptions("visible",!0),myMap.events.fire("actionend")})),p_partners.find("#p-central").on("click",(function(){p_mobile&&p_mode_map.trigger("click");let t=objects.search("properties.central = 1").get(0);t&&(myMap.setCenter(t.geometry.getCoordinates(),12),t.balloon.open())})),p_partners.find("#p-location").on("click",(function(){p_mobile&&p_mode_map.trigger("click"),ymaps.geolocation.get().then((function(t){t.geoObjects.options.set("preset","Point"),t.geoObjects.get(0).properties.set({zoom:10,hintContent:"Мое местоположение"}),myLocation!={}&&myMap.geoObjects.remove(myLocation),myLocation=t.geoObjects.get(0);let e=myLocation.properties.get("zoom");for(myMap.geoObjects.add(myLocation),myMap.setCenter(myLocation.geometry.getCoordinates(),e);e>0&&0==visibleID.length;)e--,myLocation.properties.set({zoom:e,zoom:e}),myMap.setZoom(e)}))})),p_mode_map.on("click",(function(){p_map.add(p_mode_map).addClass("active"),p_list.add(p_mode_list).removeClass("active"),myMap.container.fitToViewport()})),p_mode_list.on("click",(function(){p_list.add(p_mode_list).addClass("active"),p_map.add(p_mode_map).removeClass("active"),scrollList();let t=p_card.filter(".active:visible");t.length?p_list.scrollTop(t.position().top+p_list.scrollTop()):actionend&&(p_list.scrollTop(0),actionend=!1)})),myMap.geoObjects.events.add("balloonopen",(function(t){p_card.removeClass("active");let e=t.get("target").properties.get("id");if(e){let t=p_card.filter("[data-id="+e+"]").addClass("active");setTimeout((function(){p_list.animate({scrollTop:t.position().top+p_list.scrollTop()})}),500)}})).add("balloonclose",(function(){p_card.removeClass("active")})),myMap.events.add(["actionend"],(function(){visibleID=[],objects.searchIntersect(myMap).each((function(t){let e=!1;p_filter.hasClass("active")||(e=!0),p_sales0.hasClass("active")&&0==t.properties.get("sales")&&(e=!0),p_sales1.hasClass("active")&&1==t.properties.get("sales")&&(e=!0),p_color.hasClass("active")&&(e=!1,1==t.properties.get("color")&&(p_sales0.hasClass("active")&&!p_sales1.hasClass("active")?0==t.properties.get("sales")&&(e=!0):!p_sales0.hasClass("active")&&p_sales1.hasClass("active")?1==t.properties.get("sales")&&(e=!0):e=!0)),e&&visibleID.push(t.properties.get("id"))}));let t="Партнеры не найдены";visibleID.length&&(t="Найдено ",searchCity&&(t+="ближайших "),t+=" - "+visibleID.length),p_partners.find("#p-all").text(t),p_card.each((function(){-1!=$.inArray($(this).attr("data-id"),visibleID)?$(this).show(500,(function(){$(this).addClass("show")})):$(this).hide(500,(function(){$(this).removeClass("show")}))})),actionend=!0,scrollList(),setTimeout((function(){let t=p_card.filter(".active:visible");t.length?scroll(p_list,t.position().top+p_list.scrollTop()):scroll(p_list,0)}),500)})),p_search_input.autocomplete({source:function(t,e){let i=$.trim(p_search_input.val());""!=i?(i=new RegExp("^"+i,"i"),e($.map(city,(function(t){if(-1!=t.search(i))return{label:t,value:t}})))):e([])},select:function(t){let e=t.value;$(this).val(t.value),ymaps.geocode(e).then((function(t){let e=10;for(searchCity!={}&&myMap.geoObjects.remove(searchCity),searchCity=t.geoObjects.get(0),myMap.geoObjects.add(searchCity),myMap.setCenter(searchCity.geometry.getCoordinates(),e);e>0&&0==visibleID.length;)e--,myMap.setZoom(e)}))}})})),function(t){t.fn.autocomplete=function(e){return this.each((function(){this.timer=null,this.items=new Array,t.extend(this,e),t(this).attr("autocomplete","off"),t(this).on("focus",(function(){this.request()})),t(this).on("blur",(function(){setTimeout((function(t){t.hide()}),200,this)})),t(this).on("keydown",(function(t){if(27===t.keyCode)this.hide();else this.request()})),this.click=function(e){e.preventDefault(),value=t(e.target).parent().attr("data-value"),value&&this.items[value]&&this.select(this.items[value])},this.show=function(){var e=t(this).position();t(this).siblings("ul.dropdown-menu").css({top:e.top+t(this).outerHeight(),left:e.left}),t(this).siblings("ul.dropdown-menu").show()},this.hide=function(){t(this).siblings("ul.dropdown-menu").hide()},this.request=function(){clearTimeout(this.timer),this.timer=setTimeout((function(e){e.source(t(e).val(),t.proxy(e.response,e))}),200,this)},this.response=function(e){if(html="",e.length){for(i=0;i'+e[i].label+"");var s=new Array;for(i=0;i",j=0;j   '+s[i].item[j].label+""}html?this.show():this.hide(),t(this).siblings("ul.dropdown-menu").html(html)},t(this).after(''),t(this).siblings("ul.dropdown-menu").delegate("a","click",t.proxy(this.click,this))}))}}(window.jQuery);});