From e0269eaa9174ebfbbb337ba8993ef054c952d7bf Mon Sep 17 00:00:00 2001 From: xescoder Date: Thu, 30 Oct 2014 17:44:02 +0400 Subject: [PATCH] edit fixName function --- jquery.kladr.min.js | 2 +- kladr/js/kladr.js | 20 ++------------------ 2 files changed, 3 insertions(+), 19 deletions(-) diff --git a/jquery.kladr.min.js b/jquery.kladr.min.js index 7f7979c..665515e 100644 --- a/jquery.kladr.min.js +++ b/jquery.kladr.min.js @@ -1 +1 @@ -!function(e){function t(e){var t={},r={token:"token",key:"key",type:"contentType",typeCode:"typeCode",name:"query",zip:"zip",withParents:"withParent",oneString:"oneString",limit:"limit"};e.parentType&&e.parentId&&(t[e.parentType+"Id"]=e.parentId);for(var a in e)n(e,a)&&n(r,a)&&e[a]&&(t[r[a]]=e[a]);return t}function n(e,t){return e.hasOwnProperty(t)}function r(e){window.console&&window.console.error&&window.console.error(e)}e.kladr={},e.kladr.url="http://kladr-api.ru/api.php",e.kladr.type={region:"region",district:"district",city:"city",street:"street",building:"building"},e.kladr.typeCode={city:1,settlement:2,village:4},e.kladr.validate=function(t){switch(t.type){case e.kladr.type.region:case e.kladr.type.district:case e.kladr.type.city:if(t.parentType&&!t.parentId)return r("parentId undefined"),!1;break;case e.kladr.type.street:if(t.parentType!=e.kladr.type.city)return r('parentType must equal "city"'),!1;if(!t.parentId)return r("parentId undefined"),!1;break;case e.kladr.type.building:if(!t.zip){if(t.parentType!=e.kladr.type.street)return r('parentType must equal "street"'),!1;if(!t.parentId)return r("parentId undefined"),!1}break;default:if(!t.oneString)return r("type incorrect"),!1}return t.oneString&&t.parentType&&!t.parentId?(r("parentId undefined"),!1):t.typeCode&&t.type!=e.kladr.type.city?(r('type must equal "city"'),!1):t.limit<1?(r("limit must greater than 0"),!1):!0},e.kladr.api=function(n,a){if(!a)return void r("Callback undefined");if(!e.kladr.validate(n))return void a([]);var i=e.Deferred();i.done(a),i.fail(function(e){r(e),a([])}),e.getJSON(e.kladr.url+"?callback=?",t(n),function(e){i.resolve(e.result||[])}),setTimeout(function(){i.reject("Request error")},3e3)},e.kladr.check=function(t,n){return n?(t.withParents=!1,t.limit=1,void e.kladr.api(t,function(e){n(e&&e.length?e[0]:!1)})):void r("Callback undefined")}}(jQuery),function(e,t){function n(t,n){function r(e,t){return e.isGet?d.get(e.str[0]):(d.set(e),void t())}var d=function(){var n=t.data("kladr-data");return n||(n=e.extend({},o,l),t.data("kladr-data",n)),{set:function(e){if(e.obj)for(var r in e.obj)i(e.obj,r)&&i(o,r)&&(n[r]=e.obj[r]);else e.str&&!e.isGet&&i(o,e.str[0])&&(n[e.str[0]]=e.str[1]);t.data("kladr-data",n)},get:function(e){return i(o,e)||i(l,e)?n[e]:void 0},_set:function(e,r){n[e]=r,t.data("kladr-data",n)},_get:function(e){return i(n,e)?n[e]:void 0}}}();return r(n,function(){function n(n){var r=e(document.getElementById("kladr_autocomplete"));r.length||(r=e('
').appendTo(document.body));var i=S("guid");i?(_=r.find(".autocomplete"+i),x=r.find(".spinner"+i),e(window).off(".kladr"),t.off(".kladr"),_.off(".kladr")):(i=a(),j("guid",i),t.attr("autocomplete","off"),_=e('').appendTo(r),x=e('').appendTo(r),y(),o(),k()),n()}function r(t,n){var r,a,o,l;_.empty();for(var u in t)i(t,u)&&(r=t[u],a=S("valueFormat")(r,n),o=S("labelFormat")(r,n),l=e(''+o+""),l.data("kladr-object",r),e("
  • ").append(l).appendTo(_))}function o(){var e=t.offset(),n=t.outerWidth(),r=t.outerHeight();if(o.top!=e.top||o.left!=e.left||o.width!=n||o.height!=r){o.top=e.top,o.left=e.left,o.width=n,o.height=r,_.css({top:e.top+r+"px",left:e.left});var a=_.outerWidth()-_.width();_.width(n-a);var i=x.width(),l=x.height();x.css({top:e.top+(r-l)/2-1,left:e.left+n-i-2})}}function l(n){if(!(n.which>8&&n.which<46)){if(!h("open_before"))return void s();I(null);var a=t.val();if(!e.trim(a))return T(!1),void s();var i=b(a);if(!h("send_before",i))return void s();g(),h("send"),S("source")(i,function(n){return h("receive"),t.is(":focus")?e.trim(t.val())&&n.length?(r(n,i),o(),m(),_.slideDown(50),void h("open")):(m(),I(null),void s()):(m(),void s())})}}function s(){h("close_before")&&(_.empty().hide(),h("close"))}function c(e){var t=_.find("li.active");switch(e.which){case u.up:t.length?(t.removeClass("active"),t.prev().length&&(t=t.prev())):t=_.find("li").last(),function(){var e=_.scrollTop(),n=_.offset(),r=t.outerHeight(),a=t.offset();a.top-n.top<0&&_.scrollTop(e-r)}(),t.addClass("active"),p();break;case u.down:t.length?(t.removeClass("active"),t.next().length&&(t=t.next())):t=_.find("li").first(),function(){var e=_.scrollTop(),n=_.height(),r=_.offset(),a=t.outerHeight(),i=t.offset();i.top-r.top+a>n&&_.scrollTop(e+a)}(),t.addClass("active"),p();break;case u.enter:s()}}function f(){var n=e(this);return n.is("a")&&(n=n.parents("li")),n.addClass("active"),p(),s(),t.focus(),!1}function p(){if(h("select_before")){var e=_.find(".active a");e.length&&(t.val(e.attr("data-val")),T(!1),I(e.data("kladr-object")),h("select",S("current")))}}function v(){function n(e,t){T(t),I(e)}if(S("verify")&&h("check_before")){var r=e.trim(t.val());if(!r)return n(null,!1),void h("check",null);if(S("current"))return void T(!1);var a=b(r);if(a.withParents=!1,a.limit=10,!h("send_before",a))return n(null,!1),void h("check",null);g(),h("send"),S("source")(a,function(r){function o(e,t){m(),n(e,t)}if(h("receive"),!e.trim(t.val()))return void o(null,!1);var l=a.name.toLowerCase(),u=null,d=null;for(var s in r)if(i(r,s)&&(u=r[s].name.toLowerCase(),l==u)){d=r[s];break}d&&t.val(S("valueFormat")(d,a)),o(d,!d),h("check",d)})}}function y(){function n(e,n){t.val(e?S("valueFormat")(e,n):""),I(e)}var r={setValue:function(t){return"object"===e.type(t)?r.setValueByObject(t):"number"===e.type(t)?r.setValueById(t):"string"===e.type(t)?r.setValueByName(t):t?r:r.clear()},setValueByName:function(t){if(t=e.trim(t+"")){var a=b("");if(a.name=C(t),a.withParents=!1,a.limit=10,!h("send_before",a))return n(null,a),r;h("send"),S("source")(a,function(e){h("receive");var t=a.name.toLowerCase(),r=null,o=null;for(var l in e)if(i(e,l)&&(r=e[l].name.toLowerCase(),t==r)){o=e[l];break}n(o,a)})}return r},setValueById:function(t){var a=b("");return a.parentType=a.type,a.parentId=t,a.limit=1,e.kladr.api(a,function(e){e.length&&n(e[0],a)}),r},setValueByObject:function(e){return n(e,b("")),r},clear:function(){return n(null,null),r}};j("controller",r)}function k(){function e(){return t.val()?(v(),!!S("current")):!1}var n=0,r=e()||setInterval(function(){(++n>5||e())&&clearInterval(r)},100)}function h(n,r){if(!n)return!0;var a=n.replace(/_([a-z])/gi,function(e,t){return t.toUpperCase()});return t.trigger("kladr_"+n,r),"function"===e.type(S(a))?S(a).call(t.get(0),r)!==!1:!0}function g(){S("spinner")&&S("showSpinner")(x)}function m(){S("spinner")&&S("hideSpinner")(x)}function b(e){var t,n={token:S("token"),key:S("key"),type:S("type"),typeCode:S("typeCode"),name:C(e),parentType:S("parentType"),parentId:S("parentId"),oneString:S("oneString"),withParents:S("withParents"),limit:S("limit")},r=S("parentInput");return n.oneString&&(n.withParents=!0),r&&(t=w(r,n.type),t&&(n.parentType=t.type,n.parentId=t.id)),n}function w(t,n){var r,a=e.kladr.getInputs(t),o=e.kladr.type,l={},u=null;a.each(function(){var t,n=e(this);(t=n.attr("data-kladr-id"))&&(l[n.attr("data-kladr-type")]=t)});for(r in o){if(r==n)return u;i(o,r)&&l[r]&&(u={type:r,id:l[r]})}return u}function C(e){for(var t,n,r="abcdefghijklmnopqrstuvwxyz",a="Ёё",i="Ее",o=e.toLowerCase(),l="",u=0;u"+a.substr(l,o.length)+"",u+=a.substr(l+o.length)):u+=""+a+"",u},valueFormat:function(t,n){var r;return n.oneString?t.parents?(r=e.extend(!0,[],t.parents),r.push(t),e.kladr.buildAddress(r)):(t.typeShort?t.typeShort+". ":"")+t.name:t.name},showSpinner:function(e){var t=-.2,n=setInterval(function(){return e.is(":visible")?(e.css("background-position","0% "+t+"%"),t+=5.555556,void(t>95&&(t=-.2))):(clearInterval(n),void(n=null))},30);e.show()},hideSpinner:function(e){e.hide()}},l={current:null,controller:null},u={up:38,down:40,enter:13};e.kladr=e.extend(e.kladr,{setDefault:function(e,t){var n=r(e,t);if(n.obj)for(var a in n.obj)i(o,a)&&(o[a]=n.obj[a]);else n.str&&!n.isGet&&i(o,n.str[0])&&(o[n.str[0]]=n.str[1])},getDefault:function(e){return i(o,e)?o[e]:void 0},getInputs:function(t){var n=e(t||document.body),r="[data-kladr-type]";return n.filter(r).add(n.find(r))},getAddress:function(t,n){var r,a=e.kladr.getInputs(t),o=e.kladr.type,l={},u={};a.each(function(){var t,n,r,a=e(this);if(a.attr("data-kladr-id"))if(t=a.kladr("current"),a.attr("data-kladr-one-string")&&t.parents){n=e.extend(!0,[],t.parents),n.push(t);for(r in n)i(n,r)&&(l[n[r].contentType]=n[r])}else l[a.attr("data-kladr-type")]=t;else l[a.attr("data-kladr-type")]=a.val()});for(r in o)i(o,r)&&l[r]&&(u[r]=l[r]);return(n||e.kladr.buildAddress)(u)},buildAddress:function(t){var n,r,a=[],o=!1,l="",u="",d="",s="";for(n in t)if(i(t,n)){if("object"===e.type(t[n])){for(o=!1,r=0;r=35&&40>=n||n>=96&&105>=n;return e(this).val().length>=6?r:r||n>=48&&57>=n}),this.keyup(function(){function t(e){e?r.addClass("kladr-error"):r.removeClass("kladr-error")}var r=e(this),a=r.val();return a?void e.kladr.api({type:e.kladr.type.building,zip:a,withParents:!0,limit:1},function(r){var a,i,o=r.length&&r[0];if(r=[],o){t(!1),o.parents&&(r=e.extend(!0,[],o.parents)),r.push(o);for(a in r)r.hasOwnProperty(a)&&(i=n.find('[data-kladr-type="'+r[a].contentType+'"]'),i.kladr("controller").setValueByObject(r[a]))}else t(!0)}):void t(!1)}),this}}(jQuery); \ No newline at end of file +!function(e){function t(e){var t={},r={token:"token",key:"key",type:"contentType",typeCode:"typeCode",name:"query",zip:"zip",withParents:"withParent",oneString:"oneString",limit:"limit"};e.parentType&&e.parentId&&(t[e.parentType+"Id"]=e.parentId);for(var a in e)n(e,a)&&n(r,a)&&e[a]&&(t[r[a]]=e[a]);return t}function n(e,t){return e.hasOwnProperty(t)}function r(e){window.console&&window.console.error&&window.console.error(e)}e.kladr={},e.kladr.url="http://kladr-api.ru/api.php",e.kladr.type={region:"region",district:"district",city:"city",street:"street",building:"building"},e.kladr.typeCode={city:1,settlement:2,village:4},e.kladr.validate=function(t){switch(t.type){case e.kladr.type.region:case e.kladr.type.district:case e.kladr.type.city:if(t.parentType&&!t.parentId)return r("parentId undefined"),!1;break;case e.kladr.type.street:if(t.parentType!=e.kladr.type.city)return r('parentType must equal "city"'),!1;if(!t.parentId)return r("parentId undefined"),!1;break;case e.kladr.type.building:if(!t.zip){if(t.parentType!=e.kladr.type.street)return r('parentType must equal "street"'),!1;if(!t.parentId)return r("parentId undefined"),!1}break;default:if(!t.oneString)return r("type incorrect"),!1}return t.oneString&&t.parentType&&!t.parentId?(r("parentId undefined"),!1):t.typeCode&&t.type!=e.kladr.type.city?(r('type must equal "city"'),!1):t.limit<1?(r("limit must greater than 0"),!1):!0},e.kladr.api=function(n,a){if(!a)return void r("Callback undefined");if(!e.kladr.validate(n))return void a([]);var i=e.Deferred();i.done(a),i.fail(function(e){r(e),a([])}),e.getJSON(e.kladr.url+"?callback=?",t(n),function(e){i.resolve(e.result||[])}),setTimeout(function(){i.reject("Request error")},3e3)},e.kladr.check=function(t,n){return n?(t.withParents=!1,t.limit=1,void e.kladr.api(t,function(e){n(e&&e.length?e[0]:!1)})):void r("Callback undefined")}}(jQuery),function(e,t){function n(t,n){function r(e,t){return e.isGet?d.get(e.str[0]):(d.set(e),void t())}var d=function(){var n=t.data("kladr-data");return n||(n=e.extend({},o,l),t.data("kladr-data",n)),{set:function(e){if(e.obj)for(var r in e.obj)i(e.obj,r)&&i(o,r)&&(n[r]=e.obj[r]);else e.str&&!e.isGet&&i(o,e.str[0])&&(n[e.str[0]]=e.str[1]);t.data("kladr-data",n)},get:function(e){return i(o,e)||i(l,e)?n[e]:void 0},_set:function(e,r){n[e]=r,t.data("kladr-data",n)},_get:function(e){return i(n,e)?n[e]:void 0}}}();return r(n,function(){function n(n){var r=e(document.getElementById("kladr_autocomplete"));r.length||(r=e('
    ').appendTo(document.body));var i=S("guid");i?(_=r.find(".autocomplete"+i),B=r.find(".spinner"+i),e(window).off(".kladr"),t.off(".kladr"),_.off(".kladr")):(i=a(),j("guid",i),t.attr("autocomplete","off"),_=e('').appendTo(r),B=e('').appendTo(r),y(),o(),k()),n()}function r(t,n){var r,a,o,l;_.empty();for(var u in t)i(t,u)&&(r=t[u],a=S("valueFormat")(r,n),o=S("labelFormat")(r,n),l=e(''+o+""),l.data("kladr-object",r),e("
  • ").append(l).appendTo(_))}function o(){var e=t.offset(),n=t.outerWidth(),r=t.outerHeight();if(o.top!=e.top||o.left!=e.left||o.width!=n||o.height!=r){o.top=e.top,o.left=e.left,o.width=n,o.height=r,_.css({top:e.top+r+"px",left:e.left});var a=_.outerWidth()-_.width();_.width(n-a);var i=B.width(),l=B.height();B.css({top:e.top+(r-l)/2-1,left:e.left+n-i-2})}}function l(n){if(!(n.which>8&&n.which<46)){if(!h("open_before"))return void s();I(null);var a=t.val();if(!e.trim(a))return T(!1),void s();var i=b(a);if(!h("send_before",i))return void s();g(),h("send"),S("source")(i,function(n){return h("receive"),t.is(":focus")?e.trim(t.val())&&n.length?(r(n,i),o(),m(),_.slideDown(50),void h("open")):(m(),I(null),void s()):(m(),void s())})}}function s(){h("close_before")&&(_.empty().hide(),h("close"))}function c(e){var t=_.find("li.active");switch(e.which){case u.up:t.length?(t.removeClass("active"),t.prev().length&&(t=t.prev())):t=_.find("li").last(),function(){var e=_.scrollTop(),n=_.offset(),r=t.outerHeight(),a=t.offset();a.top-n.top<0&&_.scrollTop(e-r)}(),t.addClass("active"),p();break;case u.down:t.length?(t.removeClass("active"),t.next().length&&(t=t.next())):t=_.find("li").first(),function(){var e=_.scrollTop(),n=_.height(),r=_.offset(),a=t.outerHeight(),i=t.offset();i.top-r.top+a>n&&_.scrollTop(e+a)}(),t.addClass("active"),p();break;case u.enter:s()}}function f(){var n=e(this);return n.is("a")&&(n=n.parents("li")),n.addClass("active"),p(),s(),t.focus(),!1}function p(){if(h("select_before")){var e=_.find(".active a");e.length&&(t.val(e.attr("data-val")),T(!1),I(e.data("kladr-object")),h("select",S("current")))}}function v(){function n(e,t){T(t),I(e)}if(S("verify")&&h("check_before")){var r=e.trim(t.val());if(!r)return n(null,!1),void h("check",null);if(S("current"))return void T(!1);var a=b(r);if(a.withParents=!1,a.limit=10,!h("send_before",a))return n(null,!1),void h("check",null);g(),h("send"),S("source")(a,function(r){function o(e,t){m(),n(e,t)}if(h("receive"),!e.trim(t.val()))return void o(null,!1);var l=a.name.toLowerCase(),u=null,d=null;for(var s in r)if(i(r,s)&&(u=r[s].name.toLowerCase(),l==u)){d=r[s];break}d&&t.val(S("valueFormat")(d,a)),o(d,!d),h("check",d)})}}function y(){function n(e,n){t.val(e?S("valueFormat")(e,n):""),I(e)}var r={setValue:function(t){return"object"===e.type(t)?r.setValueByObject(t):"number"===e.type(t)?r.setValueById(t):"string"===e.type(t)?r.setValueByName(t):t?r:r.clear()},setValueByName:function(t){if(t=e.trim(t+"")){var a=b("");if(a.name=C(t),a.withParents=!1,a.limit=10,!h("send_before",a))return n(null,a),r;h("send"),S("source")(a,function(e){h("receive");var t=a.name.toLowerCase(),r=null,o=null;for(var l in e)if(i(e,l)&&(r=e[l].name.toLowerCase(),t==r)){o=e[l];break}n(o,a)})}return r},setValueById:function(t){var a=b("");return a.parentType=a.type,a.parentId=t,a.limit=1,e.kladr.api(a,function(e){e.length&&n(e[0],a)}),r},setValueByObject:function(e){return n(e,b("")),r},clear:function(){return n(null,null),r}};j("controller",r)}function k(){function e(){return t.val()?(v(),!!S("current")):!1}var n=0,r=e()||setInterval(function(){(++n>5||e())&&clearInterval(r)},100)}function h(n,r){if(!n)return!0;var a=n.replace(/_([a-z])/gi,function(e,t){return t.toUpperCase()});return t.trigger("kladr_"+n,r),"function"===e.type(S(a))?S(a).call(t.get(0),r)!==!1:!0}function g(){S("spinner")&&S("showSpinner")(B)}function m(){S("spinner")&&S("hideSpinner")(B)}function b(e){var t,n={token:S("token"),key:S("key"),type:S("type"),typeCode:S("typeCode"),name:C(e),parentType:S("parentType"),parentId:S("parentId"),oneString:S("oneString"),withParents:S("withParents"),limit:S("limit")},r=S("parentInput");return n.oneString&&(n.withParents=!0),r&&(t=w(r,n.type),t&&(n.parentType=t.type,n.parentId=t.id)),n}function w(t,n){var r,a=e.kladr.getInputs(t),o=e.kladr.type,l={},u=null;a.each(function(){var t,n=e(this);(t=n.attr("data-kladr-id"))&&(l[n.attr("data-kladr-type")]=t)});for(r in o){if(r==n)return u;i(o,r)&&l[r]&&(u={type:r,id:l[r]})}return u}function C(e){for(var t="abcdefghijklmnopqrstuvwxyz",n=e.toLowerCase(),r=0;r"+a.substr(l,o.length)+"",u+=a.substr(l+o.length)):u+=""+a+"",u},valueFormat:function(t,n){var r;return n.oneString?t.parents?(r=e.extend(!0,[],t.parents),r.push(t),e.kladr.buildAddress(r)):(t.typeShort?t.typeShort+". ":"")+t.name:t.name},showSpinner:function(e){var t=-.2,n=setInterval(function(){return e.is(":visible")?(e.css("background-position","0% "+t+"%"),t+=5.555556,void(t>95&&(t=-.2))):(clearInterval(n),void(n=null))},30);e.show()},hideSpinner:function(e){e.hide()}},l={current:null,controller:null},u={up:38,down:40,enter:13};e.kladr=e.extend(e.kladr,{setDefault:function(e,t){var n=r(e,t);if(n.obj)for(var a in n.obj)i(o,a)&&(o[a]=n.obj[a]);else n.str&&!n.isGet&&i(o,n.str[0])&&(o[n.str[0]]=n.str[1])},getDefault:function(e){return i(o,e)?o[e]:void 0},getInputs:function(t){var n=e(t||document.body),r="[data-kladr-type]";return n.filter(r).add(n.find(r))},getAddress:function(t,n){var r,a=e.kladr.getInputs(t),o=e.kladr.type,l={},u={};a.each(function(){var t,n,r,a=e(this);if(a.attr("data-kladr-id"))if(t=a.kladr("current"),a.attr("data-kladr-one-string")&&t.parents){n=e.extend(!0,[],t.parents),n.push(t);for(r in n)i(n,r)&&(l[n[r].contentType]=n[r])}else l[a.attr("data-kladr-type")]=t;else l[a.attr("data-kladr-type")]=a.val()});for(r in o)i(o,r)&&l[r]&&(u[r]=l[r]);return(n||e.kladr.buildAddress)(u)},buildAddress:function(t){var n,r,a=[],o=!1,l="",u="",d="",s="";for(n in t)if(i(t,n)){if("object"===e.type(t[n])){for(o=!1,r=0;r=35&&40>=n||n>=96&&105>=n;return e(this).val().length>=6?r:r||n>=48&&57>=n}),this.keyup(function(){function t(e){e?r.addClass("kladr-error"):r.removeClass("kladr-error")}var r=e(this),a=r.val();return a?void e.kladr.api({type:e.kladr.type.building,zip:a,withParents:!0,limit:1},function(r){var a,i,o=r.length&&r[0];if(r=[],o){t(!1),o.parents&&(r=e.extend(!0,[],o.parents)),r.push(o);for(a in r)r.hasOwnProperty(a)&&(i=n.find('[data-kladr-type="'+r[a].contentType+'"]'),i.kladr("controller").setValueByObject(r[a]))}else t(!0)}):void t(!1)}),this}}(jQuery); \ No newline at end of file diff --git a/kladr/js/kladr.js b/kladr/js/kladr.js index d8bb6d1..d4ccf12 100644 --- a/kladr/js/kladr.js +++ b/kladr/js/kladr.js @@ -901,33 +901,17 @@ function fixName (name) { var noCorrect = 'abcdefghijklmnopqrstuvwxyz', - pattern = 'Ёё', - replace = 'Ее'; - - var testName = name.toLowerCase(), - result = '', - ch, - index; + testName = name.toLowerCase(); for (var i = 0; i < testName.length; i++) { if (~noCorrect.indexOf(testName[i])) { error(true); return name; } - - ch = name[i]; - index = pattern.indexOf(ch); - - if (~index) { - result += replace[index]; - continue; - } - - result += ch; } error(false); - return result; + return name; } function setCurrent (obj) {