-
-
Notifications
You must be signed in to change notification settings - Fork 4
/
ajaxzip3.js
2 lines (2 loc) · 4.01 KB
/
ajaxzip3.js
1
2
var CACHE=[],YubinBango;!function(e){var t=function(){function e(e,t){if(void 0===e&&(e=""),this.URL="https://yubinbango.github.io/yubinbango-data/data",this.REGION=[null,"北海道","青森県","岩手県","宮城県","秋田県","山形県","福島県","茨城県","栃木県","群馬県","埼玉県","千葉県","東京都","神奈川県","新潟県","富山県","石川県","福井県","山梨県","長野県","岐阜県","静岡県","愛知県","三重県","滋賀県","京都府","大阪府","兵庫県","奈良県","和歌山県","鳥取県","島根県","岡山県","広島県","山口県","徳島県","香川県","愛媛県","高知県","福岡県","佐賀県","長崎県","熊本県","大分県","宮崎県","鹿児島県","沖縄県"],e){var n=e.replace(/[0-9]/g,function(e){return String.fromCharCode(e.charCodeAt(0)-65248)}),i=n.match(/\d/g),r=i.join(""),o=this.chk7(r);o?this.getAddr(o,t):t(this.addrDic())}}return e.prototype.chk7=function(e){return 7===e.length?e:void 0},e.prototype.addrDic=function(e,t,o,n,i){return void 0===e&&(e=""),void 0===t&&(t=""),void 0===o&&(o=""),void 0===n&&(n=""),void 0===i&&(i=""),{region_id:e,region:t,locality:o,street:n,extended:i}},e.prototype.selectAddr=function(e){return e&&e[0]&&e[1]?this.addrDic(e[0],this.REGION[e[0]],e[1],e[2],e[3]):this.addrDic()},e.prototype.jsonp=function(t,o){window.$yubin=function(e){return o(e)};var e=document.createElement("script");e.setAttribute("type","text/javascript"),e.setAttribute("charset","UTF-8"),e.setAttribute("src",t),document.head.appendChild(e)},e.prototype.getAddr=function(t,o){var n=this,e=t.substr(0,3);return e in CACHE&&t in CACHE[e]?o(this.selectAddr(CACHE[e][t])):void this.jsonp(this.URL+"/"+e+".js",function(i){return CACHE[e]=i,o(n.selectAddr(i[t]))})},e}();e.Core=t}(YubinBango||(YubinBango={}));var YubinBango;!function(e){var t=function(){function t(){this.prev=""}return t.prototype.getAddr=function(t,o){return(new e.Core).getAddr(t,o)},t.prototype.zip2addr=function(c,a,o,n,i,r,t){var d=this,e={};if(e.postalcode01=c?this.getElementByName(c):void 0,e.postalcode02=a?this.getElementByName(a,e.postalcode01):void 0,e.region=o?this.getElementByName(o,e.postalcode01):void 0,e.locality=n?this.getElementByName(n,e.postalcode01):void 0,e.street=i?this.getElementByName(i,e.postalcode01):void 0,e.extended=r?this.getElementByName(r,e.postalcode01):void 0,e.ffocus=void 0===t?!0:t,e.postalcode01&&e.region){var s=e.postalcode01?e.postalcode01.value:"",u=e.postalcode02?e.postalcode02.value:"",l=s+u;l&&this.getAddr(l,function(t){d.apply(e,t)})}},t.prototype.apply=function(t,e){e.extended||(e.extended="");var o=t.locality;if("select-one"==t.region.type||"select-multiple"==t.region.type)for(var i=t.region.options,n=0;n<i.length;n++){var a=i[n].value,l=i[n].text;i[n].selected=a==e.region_id||a==e.region||l==e.region}else t.region.name==t.locality.name?e.locality=e.region+e.locality:t.region.value=e.region;switch(this.getFormsType(t)){case 2:t.locality.value=e.locality+e.street+e.extended;break;case 1:t.locality.value=e.locality,t.street.value=e.street+e.extended;break;case 0:t.locality.value=e.locality,t.street.value=e.street,t.extended.value=e.extended;break;default:t.locality.value=e.locality,t.street.value=e.street,t.extended.value=e.extended}if("function"==typeof this.onSuccess&&this.onSuccess(),t.ffocus&&o&&o.value){var r=o.value.length;if(o.focus(),o.createTextRange){var c=o.createTextRange();c.move("character",r),c.select()}else o.setSelectionRange&&o.setSelectionRange(r,r)}},t.prototype.getElementByName=function(e,o){if("string"==typeof e){var n=document.getElementsByName(e);if(!n)return null;if(!(n.length>1&&o&&o.form))return n[0];for(var i=o.form.elements,t=0;t<i.length;t++)if(i[t].name==e)return i[t]}return e},t.prototype.ckFormsType=function(e,t){return e[t]?0:1},t.prototype.getFormsType=function(e){var t=this;return["extended","street","locality"].map(function(o){return t.ckFormsType(e,o)}).reduce(function(e,t){return e+t})},t}();e.OldFunction=t}(YubinBango||(YubinBango={}));var AjaxZip3=new YubinBango.OldFunction;
//# sourceMappingURL=./ajaxzip3.js.map