Joywork/js/jquery.fias.min.js

1 line
12 KiB
JavaScript
Raw Permalink Normal View History

2026-05-22 20:21:54 +02:00
!function(t,e){function n(t){var e={},n={type:"contentType",name:"query",withParents:"withParent"};t.parentType&&t.parentId&&(e[t.parentType+"Id"]=t.parentId);for(var a in t)r(t,a)&&t[a]&&(e[r(n,a)?n[a]:a]=t[a]);return e}function r(t,e){return t.hasOwnProperty(e)}function a(t){var n=e.console;n&&n.error&&n.error(t)}t.fias={},function(){var e="https:";t.fias.url=e+"//kladr-api.ru/api.php",t.fias.timeout=3e3}();var i=[],o=function(){for(;i.length>5;){var t=i.shift();t.abort()}};t.fias.type={region:"region",district:"district",city:"city",street:"street",building:"building"},t.fias.typeCode={city:1,settlement:2,village:4},t.fias.validate=function(e){var n=t.fias.type;switch(e.type){case n.region:case n.district:case n.city:if(e.parentType&&!e.parentId)return a("parentId undefined"),!1;break;case n.street:if(e.parentType!=n.city&&e.parentType!=n.street)return a('parentType must equal "city" or "street"'),!1;if(!e.parentId)return a("parentId undefined"),!1;break;case n.building:if(!e.zip){if(!~t.inArray(e.parentType,[n.street,n.city]))return a('parentType must equal "street" or "city"'),!1;if(!e.parentId)return a("parentId undefined"),!1}break;default:if(!e.oneString)return a("type incorrect"),!1}return e.oneString&&e.parentType&&!e.parentId?(a("parentId undefined"),!1):e.typeCode&&e.type!=n.city?(a('type must equal "city"'),!1):!(e.limit<1)||(a("limit must greater than 0"),!1)},t.fias.api=function(e,r){if(!r)return void a("Callback undefined");if(!t.fias.validate(e))return void r([]);var l=setTimeout(function(){r([]),l=null},t.fias.timeout);!e.token&&t.fias.token&&(e.token=t.fias.token),o();var u=t.ajax({url:t.fias.url+"?callback=?",type:"get",data:n(e),dataType:"jsonp"});i.push(u),u.done(function(t){l&&(r(t.result||[]),clearTimeout(l))})},t.fias.check=function(e,n){return n?(e.withParents=!1,e.limit=1,void t.fias.api(e,function(t){n(t&&t.length?t[0]:!1)})):void a("Callback undefined")}}(jQuery,window),function(t,e,n,r){function a(r,a){function i(t,e){return t.isGet?c.get(t.str[0]):(c.set(t),void e())}var c=function(){var e="kladr-data",n=r.data(e);return n||(n=t.extend({},u,s),r.data(e,n)),{set:function(t){if(t.obj)for(var a in t.obj)l(t.obj,a)&&l(u,a)&&(n[a]=t.obj[a]);else t.str&&!t.isGet&&l(u,t.str[0])&&(n[t.str[0]]=t.str[1]);r.data(e,n)},get:function(t){if(l(u,t)||l(s,t))return n[t]},_set:function(t,a){n[t]=a,r.data(e,n)},_get:function(t){if(l(n,t))return n[t]}}}();return i(a,function(){function a(a){var i=t(n.getElementById("kladr_autocomplete"));i.length||(i=t('<div id="kladr_autocomplete"></div>').appendTo(n.body));var l=B("guid");l?(V=i.find(".autocomplete"+l),A=i.find(".spinner"+l),t(e).off(z),r.off(z),V.off(z)):(l=o(),P("guid",l),r.attr("autocomplete","off"),V=t('<ul class="autocomplete'+l+' autocomplete" style="display: none;"></ul>').appendTo(i),A=t('<div class="spinner'+l+' spinner" style="display: none;"></div>').appendTo(i),k(),d(),b()),a()}function i(e,n){var r,a,i,o;V.empty();for(var l=0;l<e.length;l++){r=e[l],a=B("valueFormat")(r,n),i=B("labelFormat")(r,n);var u=a.replace(/(["])/g,"\\$1"),s=t("<div>"+i+"</div>").text().replace(/(["])/g,"\\$1");o=t('<a data-val="'+u+'">'+i+"</a>"),o.data("kladr-object",r),t('<li title="'+s+'"></li>').append(o).appendTo(V)}}function s(){var e,n,r;V.empty(),e="",n=u.noResultText,null!=n&&""!=n&&(r=t('<a data-val="'+e+'">'+n+"</a>"),r.data("kladr-object",{}),t("<li></li>").append(r).appendTo(V))}function d(){var t=r.offset(),e=r.outerWidth(),n=r.outerHeight();if(t&&(d.top!=t.top||d.left!=t.left||d.width!=e||d.height!=n)){d.top=t.top,d.left=t.left,d.width=e,d.height=n,V.css({top:t.top-1+n+"px",left:t.left});var a=V.outerWidth()-V.width();V.width(e-a);var i=A.width(),o=A.height();A.css({top:t.top+(n-o)/2-1,left:t.left+e-i-2})}}function p(e){if(!(e.which>8&&e.which<46)){if(r.data(F,!1),!w("open_before"))return void v();_(null);var n=r.val();if(!t.trim(n))return x(!1),void v();var a=j(n);if(!w("send_before",a))return void v();T(),w("send"),B("source")(a,function(e){return w("receive",e),r.is(":focus")?t.trim(r.val())&&e.length?(G=!0,i(e,a),d(),I(),V.slideDown(50),void w("open")):(