PageSourceSearch

https://melive.co.jp/st/wp-content/themes/melive/js/ajaxzip3-source.js

js melive.co.jp collected 2026-10-07 03:18:48 UTC 9,316 bytes, 237 lines download raw bytes

1/* ================================================================ *
2    ajaxzip3.js ---- AjaxZip3 郵便番号→住所変換ライブラリ
3
4    Copyright (c) 2008-2015 Ninkigumi Co.,Ltd.
5    http://ajaxzip3.github.io/
6
7    Copyright (c) 2006-2007 Kawasaki Yusuke <u-suke [at] kawa.net>
8    http://www.kawa.net/works/ajax/AjaxZip2/AjaxZip2.html
9
10    Permission is hereby granted, free of charge, to any person
11    obtaining a copy of this software and associated documentation
12    files (the "Software"), to deal in the Software without
13    restriction, including without limitation the rights to use,
14    copy, modify, merge, publish, distribute, sublicense, and/or sell
15    copies of the Software, and to permit persons to whom the
16    Software is furnished to do so, subject to the following
17    conditions:
18
19    The above copyright notice and this permission notice shall be
20    included in all copies or substantial portions of the Software.
21
22    THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
23    EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
24    OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
25    NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
26    HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
27    WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
28    FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
29    OTHER DEALINGS IN THE SOFTWARE.
30* ================================================================ */
31
32AjaxZip3 = function(){};
33AjaxZip3.VERSION = '0.51';
34AjaxZip3.JSONDATA = 'https://yubinbango.github.io/yubinbango-data/data';
35AjaxZip3.CACHE = [];
36AjaxZip3.prev = '';
37AjaxZip3.nzip = '';
38AjaxZip3.fzip1 = '';
39AjaxZip3.fzip2 = '';
40AjaxZip3.fpref = '';
41AjaxZip3.addr = '';
42AjaxZip3.fstrt = '';
43AjaxZip3.farea = '';
44AjaxZip3.ffocus = true;
45AjaxZip3.onSuccess = null;
46AjaxZip3.onFailure = null;
47
48AjaxZip3.PREFMAP = [
49    null,       '北海道',   '青森県',   '岩手県',   '宮城県',
50    '秋田県',   '山形県',   '福島県',   '茨城県',   '栃木県',
51    '群馬県',   '埼玉県',   '千葉県',   '東京都',   '神奈川県',
52    '新潟県',   '富山県',   '石川県',   '福井県',   '山梨県',
53    '長野県',   '岐阜県',   '静岡県',   '愛知県',   '三重県',
54    '滋賀県',   '京都府',   '大阪府',   '兵庫県',   '奈良県',
55    '和歌山県', '鳥取県',   '島根県',   '岡山県',   '広島県',
56    '山口県',   '徳島県',   '香川県',   '愛媛県',   '高知県',
57    '福岡県',   '佐賀県',   '長崎県',   '熊本県',   '大分県',
58    '宮崎県',   '鹿児島県', '沖縄県'
59];
60AjaxZip3.zip2addr = function ( azip1, azip2, apref, aaddr, aarea, astrt, afocus ) {
61    AjaxZip3.fzip1 = AjaxZip3.getElementByName(azip1);
62    AjaxZip3.fzip2 = AjaxZip3.getElementByName(azip2,AjaxZip3.fzip1);
63    AjaxZip3.fpref = AjaxZip3.getElementByName(apref,AjaxZip3.fzip1);
64    AjaxZip3.faddr = AjaxZip3.getElementByName(aaddr,AjaxZip3.fzip1);
65    AjaxZip3.fstrt = AjaxZip3.getElementByName(astrt,AjaxZip3.fzip1);
66    AjaxZip3.farea = AjaxZip3.getElementByName(aarea,AjaxZip3.fzip1);
67    AjaxZip3.ffocus = afocus === undefined ? true : afocus;
68    if ( ! AjaxZip3.fzip1 ) return;
69    if ( ! AjaxZip3.fpref ) return;
70    if ( ! AjaxZip3.faddr ) return;
71
72    // 郵便番号を数字のみ7桁取り出す
73//    var zipoptimize = function(AjaxZip3.fzip1, AjaxZip3.fzip2){
74        var vzip = AjaxZip3.fzip1.value;
75        if ( AjaxZip3.fzip2 && AjaxZip3.fzip2.value ) vzip += AjaxZip3.fzip2.value;
76        if ( ! vzip ) return;
77        AjaxZip3.nzip = '';
78        for( var i=0; i<vzip.length; i++ ) {
79            var chr = vzip.charCodeAt(i);
80            if ( chr < 48 ) continue;
81            if ( chr > 57 ) continue;
82            AjaxZip3.nzip += vzip.charAt(i);
83        }
84        if ( AjaxZip3.nzip.length < 7 ) return;
85//    };
86
87    // 前回と同じ値&フォームならキャンセル
88    var uniqcheck = function(){
89        var uniq = AjaxZip3.nzip+AjaxZip3.fzip1.name+AjaxZip3.fpref.name+AjaxZip3.faddr.name;
90        if ( AjaxZip3.fzip1.form ) uniq += AjaxZip3.fzip1.form.id+AjaxZip3.fzip1.form.name+AjaxZip3.fzip1.form.action;
91        if ( AjaxZip3.fzip2 ) uniq += AjaxZip3.fzip2.name;
92        if ( AjaxZip3.fstrt ) uniq += AjaxZip3.fstrt.name;
93        if ( uniq == AjaxZip3.prev ) return;
94        AjaxZip3.prev = uniq;
95    };
96
97
98    // 郵便番号上位3桁でキャッシュデータを確認
99    var zip3 = AjaxZip3.nzip.substr(0,3);
100    var data = AjaxZip3.CACHE[zip3];
101    if ( data ) return AjaxZip3.callback( data );
102
103    AjaxZip3.zipjsonpquery();
104
105};
106
107AjaxZip3.callback = function(data){
108        function onFailure( ){
109            if( typeof AjaxZip3.onFailure === 'function' ) AjaxZip3.onFailure();
110        }
111        var array = data[AjaxZip3.nzip];
112        // Opera バグ対策:0x00800000 を超える添字は +0xff000000 されてしまう
113        var opera = (AjaxZip3.nzip-0+0xff000000)+"";
114        if ( ! array && data[opera] ) array = data[opera];
115        if ( ! array ) {
116            onFailure();
117            return;
118        }
119        var pref_id = array[0];                 // 都道府県ID
120        if ( ! pref_id ) {
121            onFailure();
122            return;
123        }
124        var jpref = AjaxZip3.PREFMAP[pref_id];  // 都道府県名
125        if ( ! jpref ) {
126            onFailure();
127            return;
128        }
129
130        var jcity = array[1];
131        if ( ! jcity ) jcity = '';              // 市区町村名
132        var jarea = array[2];
133        if ( ! jarea ) jarea = '';              // 町域名
134        var jstrt = array[3];
135        if ( ! jstrt ) jstrt = '';              // 番地
136
137        var cursor = AjaxZip3.faddr;
138        var jaddr = jcity;                      // 市区町村名
139
140        if ( AjaxZip3.fpref.type == 'select-one' || AjaxZip3.fpref.type == 'select-multiple' ) {
141            // 都道府県プルダウンの場合
142            var opts = AjaxZip3.fpref.options;
143            for( var i=0; i<opts.length; i++ ) {
144                var vpref = opts[i].value;
145                var tpref = opts[i].text;
146                opts[i].selected = ( vpref == pref_id || vpref == jpref || tpref == jpref );
147            }
148        } else {
149            if ( AjaxZip3.fpref.name == AjaxZip3.faddr.name ) {
150                // 都道府県名+市区町村名+町域名合体の場合
151                jaddr = jpref + jaddr;
152            } else {
153                // 都道府県名テキスト入力の場合
154                AjaxZip3.fpref.value = jpref;
155            }
156        }
157        if ( AjaxZip3.farea ) {
158            cursor = AjaxZip3.farea;
159            AjaxZip3.farea.value = jarea;
160        } else {
161            jaddr += jarea;
162        }
163        if ( AjaxZip3.fstrt ) {
164            cursor = AjaxZip3.fstrt;
165            if ( AjaxZip3.faddr.name == AjaxZip3.fstrt.name ) {
166                // 市区町村名+町域名+番地合体の場合
167                jaddr = jaddr + jstrt;
168            } else if ( jstrt ) {
169                // 番地テキスト入力欄がある場合
170                AjaxZip3.fstrt.value = jstrt;
171            }
172        }
173        AjaxZip3.faddr.value = jaddr;
174
175        if( typeof AjaxZip3.onSuccess === 'function' ) AjaxZip3.onSuccess();
176
177        // patch from http://iwa-ya.sakura.ne.jp/blog/2006/10/20/050037
178        // update http://www.kawa.net/works/ajax/AjaxZip2/AjaxZip2.html#com-2006-12-15T04:41:22Z
179        if ( !AjaxZip3.ffocus ) return;
180        if ( ! cursor ) return;
181        if ( ! cursor.value ) return;
182        var len = cursor.value.length;
183        cursor.focus();
184        if ( cursor.createTextRange ) {
185            var range = cursor.createTextRange();
186            range.move('character', len);
187            range.select();
188        } else if (cursor.setSelectionRange) {
189            cursor.setSelectionRange(len,len);
190        }
191
192};
193
194// Safari 文字化け対応
195// http://kawa.at.webry.info/200511/article_9.html
196AjaxZip3.getResponseText = function ( req ) {
197    var text = req.responseText;
198    if ( navigator.appVersion.indexOf('KHTML') > -1 ) {
199        var esc = escape( text );
200        if ( esc.indexOf('%u') < 0 && esc.indexOf('%') > -1 ) {
201            text = decodeURIComponent( esc );
202        }
203    }
204    return text;
205}
206
207// フォームnameから要素を取り出す
208AjaxZip3.getElementByName = function ( elem, sibling ) {
209    if ( typeof(elem) == 'string' ) {
210        var list = document.getElementsByName(elem);
211        if ( ! list ) return null;
212        if ( list.length > 1 && sibling && sibling.form ) {
213            var form = sibling.form.elements;
214            for( var i=0; i<form.length; i++ ) {
215                if ( form[i].name == elem ) {
216                    return form[i];
217                }
218            }
219        } else {
220            return list[0];
221        }
222    }
223    return elem;
224}
225
226AjaxZip3.zipjsonpquery = function(){
227    var url = AjaxZip3.JSONDATA+'/'+AjaxZip3.nzip.substr(0,3)+'.js';
228    var scriptTag = document.createElement("script");
229    scriptTag.setAttribute("type", "text/javascript");
230    scriptTag.setAttribute("charset", "UTF-8");
231    scriptTag.setAttribute("src", url);
232    document.getElementsByTagName("head").item(0).appendChild(scriptTag);
233   };
234
235function $yubin(data){
236    AjaxZip3.callback(data);
237};

Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.