1 line
12 KiB
JavaScript
1 line
12 KiB
JavaScript
|
|
!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.kladr={},function(){var n="https:"==e.location.protocol?"https:":"http:";t.kladr.url=n+"//kladr-api.ru/api.php"}(),t.kladr.type={region:"region",district:"district",city:"city",street:"street",building:"building"},t.kladr.typeCode={city:1,settlement:2,village:4},t.kladr.validate=function(e){var n=t.kladr.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):!0},t.kladr.api=function(e,r){if(!r)return void a("Callback undefined");if(!t.kladr.validate(e))return void r([]);var i=setTimeout(function(){r([]),i=null},3e3);t.ajax({url:t.kladr.url+"?callback=?",type:"get",data:n(e),dataType:"jsonp"}).done(function(t){i&&(r(t.result||[]),clearTimeout(i))})},t.kladr.check=function(e,n){return n?(e.withParents=!1,e.limit=1,void t.kladr.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?s.get(t.str[0]):(s.set(t),void e())}var s=function(){var e="kladr-data",n=r.data(e);return n||(n=t.extend({},u,d),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){return l(u,t)||l(d,t)?n[t]:void 0},_set:function(t,a){n[t]=a,r.data(e,n)},_get:function(t){return l(n,t)?n[t]:void 0}}}();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=x("guid");l?(V=i.find(".autocomplete"+l),A=i.find(".spinner"+l),t(e).off(L),r.off(L),V.off(L)):(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),m(),f(),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=x("valueFormat")(r,n),i=x("labelFormat")(r,n),o=t('<a data-val="'+a+'">'+i+"</a>"),o.data("kladr-object",r),t("<li></li>").append(o).appendTo(V)}function d(){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 f(){var t=r.offset(),e=r.outerWidth(),n=r.outerHeight();if(t&&(f.top!=t.top||f.left!=t.left||f.width!=e||f.height!=n)){f.top=t.top,f.left=t.left,f.width=e,f.height=n,V.css({top:t.top+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(z,!1),!w("open_before"))return void v();_(null);var n=r.val();if(!t.trim(n))return B(!1),void v();var a=C(n);if(!w("send_before",a))return void v();T(),w("send"),x("source")(a,function(e){return w("receive",e),r.is(":focus")?t.trim(r.val())&&e.length?(G=!0,i(e,a),f(),I(),V.slideDown(50),void w("open")):(I(),_(null),d(),f(),V.slideDown(50),w("open"),void(G=!1)):(I(),void v())})}}function v(){w("close_before")&&(V.empty().hide(),w("close"))}function y(t){var e=V.find("li.active");switch(t.which){case c.up:e.length?(e.re
|