PageSourceSearch

https://www.satomura.net/libscript/ElZip-2.1.js

js satomura.net collected 2026-10-07 14:23:59 UTC 8,865 bytes, 258 lines download raw bytes

1/* ================================================================ *
2    ajaxzip2.js ---- AjaxZip2 郵便番号→住所変換ライブラリ
3
4    Copyright (c) 2006-2007 Kawasaki Yusuke <u-suke [at] kawa.net>
5    http://www.kawa.net/works/ajax/ajaxzip2/ajaxzip2.html
6
7    Permission is hereby granted, free of charge, to any person
8    obtaining a copy of this software and associated documentation
9    files (the "Software"), to deal in the Software without
10    restriction, including without limitation the rights to use,
11    copy, modify, merge, publish, distribute, sublicense, and/or sell
12    copies of the Software, and to permit persons to whom the
13    Software is furnished to do so, subject to the following
14    conditions:
15
16    The above copyright notice and this permission notice shall be
17    included in all copies or substantial portions of the Software.
18
19    THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
20    EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
21    OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
22    NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
23    HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
24    WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
25    FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
26    OTHER DEALINGS IN THE SOFTWARE.
27* ================================================================ */
28/* ================================================================ *
29    ElZip-2.1.js
30    ElZip.js へ改変 ---- <takashi-kanno [at] e-life.co.jp>
31	2023.01.12 Ver2.0作成
32	2023.12.21 Ver2.0.2仮定
33/	2026.04.23 Verアップデートに伴うファイル名の更新
34* ================================================================ */
35
36ElZip = function () {};
37ElZip.VERSION = '0.1';
38ElZip.JSONDATA = '/ajaxzip/data/';
39
40ElZip.REQ_URL = 'https://www.e-life.jp/bin/ajax/get_ajaxzip.cgi';
41
42ElZip.PREFMAP = [
43    null,       '北海道',   '青森県',   '岩手県',   '宮城県',
44    '秋田県',   '山形県',   '福島県',   '茨城県',   '栃木県',
45    '群馬県',   '埼玉県',   '千葉県',   '東京都',   '神奈川県',
46    '新潟県',   '富山県',   '石川県',   '福井県',   '山梨県',
47    '長野県',   '岐阜県',   '静岡県',   '愛知県',   '三重県',
48    '滋賀県',   '京都府',   '大阪府',   '兵庫県',   '奈良県',
49    '和歌山県', '鳥取県',   '島根県',   '岡山県',   '広島県',
50    '山口県',   '徳島県',   '香川県',   '愛媛県',   '高知県',
51    '福岡県',   '佐賀県',   '長崎県',   '熊本県',   '大分県',
52    '宮崎県',   '鹿児島県', '沖縄県'
53];
54
55// ---------------------------------------------------------------- //
56//  GetZipToAddr(JSONファイル受信)
57//  m = 1 は他ドメイン時のみとする
58// ---------------------------------------------------------------- //
59ElZip.GetZipToAddr = function (m, f_zip1, f_zip2, f_addr1, f_addr2, f_addr3) {
60	ElZip.fzip1  = ElZip.getElementByName(f_zip1);
61	ElZip.fzip2  = ElZip.getElementByName(f_zip2,f_zip1);
62	ElZip.faddr1 = ElZip.getElementByName(f_addr1,f_zip1);
63	ElZip.faddr2 = ElZip.getElementByName(f_addr2,f_zip1);
64	ElZip.faddr3 = ElZip.getElementByName(f_addr3,f_zip1);
65
66	if (m > 0) {
67		// 「検索」押下
68		// 値がセットされていない場合は通信しない
69		if ( (isset(ElZip.fzip1) && ElZip.fzip1.value == '') || !isset(ElZip.fzip1) ) {
70//			alert('郵便番号が入力されていません。');
71//			ElZip.fzip1.focus();
72			return false;
73		}
74	}
75	var cb = (m == 0 || m == 2) ? 1 : 0;
76	var vzip = ElZip.fzip1.value;
77	if(f_zip2!=''){
78		if (ElZip.fzip2.value != '') vzip += ElZip.fzip2.value;
79	}
80	var nzip = '';
81	for(var i=0; i<vzip.length; i++) {
82		var chr = vzip.charCodeAt(i);
83		if (chr < 48) continue;
84		if (chr > 57) continue;
85		nzip += vzip.charAt(i);
86	}
87	if (nzip.length < 7) return;
88
89	var zip3 = nzip.substr(0,3);
90	url = ElZip.JSONDATA+'zip-'+zip3+'.json';
91
92	// JSON取得後のコールバック関数
93	var func1 = function (data) {
94		var array = data[nzip];
95		// Opera バグ対策:0x00800000 を超える添字は +0xff000000 されてしまう
96		var opera = (nzip-0+0xff000000)+"";
97		if (!array && data[opera]) array = data[opera];
98		if (!array) return;
99		var pref_id = array[0];		// 都道府県ID
100		if (!pref_id) return;
101		var jpref = ElZip.PREFMAP[pref_id];	// 都道府県名
102		if (!jpref) return;
103		var jcity = array[1];
104		if (!jcity) jcity = '';		// 市区町村名
105		var jarea = array[2];
106		if (!jarea) jarea = '';		// 町域名
107		var jstrt = array[3];
108		if (!jstrt) jstrt = '';		// 番地
109
110		var jaddr = jcity + jarea + jstrt;
111		if (jaddr == '') return false;
112
113		// 住所をセットしてフォーカスをあてる。
114		if (isset(ElZip.faddr1) != '' && isset(ElZip.faddr2) != '' && isset(ElZip.faddr3) != '') {
115			// 都道府県・市区町村・町名
116			//ElZip.faddr1.value = jpref;
117			ElZip.faddr3.focus();
118			ElZip.SetAddr1(pref_id, jpref);
119			ElZip.faddr2.value = jcity;
120			ElZip.faddr3.value = jarea + jstrt;
121			ElZip.faddr3.focus();
122		} else if (isset(ElZip.faddr1) != '' && isset(ElZip.faddr2) != '') {
123			// 都道府県・市区町村+町名
124			ElZip.faddr2.focus();
125			ElZip.SetAddr1(pref_id, jpref);
126			ElZip.faddr2.value = jaddr;
127			ElZip.faddr2.focus();
128		} else {
129			// 都道府県+市区町村+町名
130			ElZip.faddr1.focus();
131			ElZip.faddr1.value = jpref + jaddr;
132			ElZip.faddr1.focus();
133		}
134		return true;
135	};
136
137	if (cb == 1 && window.Ajax && Ajax.Request) {
138		// JSONファイル受信後のコールバック関数(Prototype.JS用)
139		var func2 = function (req) {
140			if (!req) return;
141			if (!req.responseText) return;
142			var json = ElZip.getResponseText(req);
143			func1(data);
144		};
145		new Ajax.Request( url, {
146			method: "get",
147			asynchronous: true,
148			onComplete: func2
149		});
150	} else if (cb == 1 && window.jQuery) {
151		// JSONファイル受信後のコールバック関数(Jquery.js用)
152		$.getJSON(url,
153			function (data) {
154				func1(data);
155		});
156	} else  {
157		// クロスドメイン時callbackを使用
158		url = ElZip.REQ_URL + '?zip=' +nzip;
159
160		var sc = document.createElement("script");
161		sc.type = "text/javascript";
162		sc.charset = 'UTF-8';
163		sc.src = url;
164		document.body.appendChild(sc);
165	}
166
167	return true;
168}
169
170// クロスドメイン時のcallback
171ElZip.CallBack = function (data, nzip) {
172	var array = data[nzip];
173	// Opera バグ対策:0x00800000 を超える添字は +0xff000000 されてしまう
174	var opera = (nzip-0+0xff000000)+"";
175	if (!array && data[opera]) array = data[opera];
176	if (!array) return;
177	var pref_id = array[0];		// 都道府県ID
178	if (!pref_id) return;
179	var jpref = ElZip.PREFMAP[pref_id];	// 都道府県名
180	if (!jpref) return;
181	var jcity = array[1];
182	if (!jcity) jcity = '';		// 市区町村名
183	var jarea = array[2];
184	if (!jarea) jarea = '';		// 町域名
185	var jstrt = array[3];
186	if (!jstrt) jstrt = '';		// 番地
187
188	var jaddr = jcity + jarea + jstrt;
189	if (isset(ElZip.faddr1) != '' && isset(ElZip.faddr2) != '' && isset(ElZip.faddr3) != '') {
190		// 都道府県・市区町村・町名
191		//ElZip.faddr1.value = jpref;
192		ElZip.faddr3.focus();
193		ElZip.SetAddr1(pref_id, jpref);
194		ElZip.faddr2.value = jcity;
195		ElZip.faddr3.value = jarea + jstrt;
196		ElZip.faddr3.focus();
197	} else if (isset(ElZip.faddr1) != '' && isset(ElZip.faddr2) != '') {
198		// 都道府県・市区町村+町名
199		ElZip.faddr2.focus();
200		ElZip.SetAddr1(pref_id, jpref);
201		ElZip.faddr2.value = jaddr;
202		ElZip.faddr2.focus();
203	} else {
204		// 都道府県+市区町村+町名
205		ElZip.faddr1.focus();
206		ElZip.faddr1.value = jpref + jaddr;
207		ElZip.faddr1.focus();
208	}
209}
210
211// Safari 文字化け対応
212ElZip.getResponseText = function (req) {
213	var text = req.responseText;
214	if (navigator.appVersion.indexOf('KHTML') > -1) {
215		var esc = escape( text );
216		if (esc.indexOf('%u') < 0 && esc.indexOf('%') > -1) {
217			text = decodeURIComponent(esc);
218		}
219	}
220	return text;
221}
222
223// フォームnameから要素を取り出す
224ElZip.getElementByName = function (elem, sibling) {
225	if (typeof(elem) == 'string') {
226		var list = document.getElementsByName(elem);
227		if (!list) return null;
228		if (list.length > 1 && sibling && sibling.form) {
229			var form = sibling.form.elements;
230			for(var i=0; i<form.length; i++) {
231				if (form[i].name == elem) {
232					return form[i];
233				}
234			}
235		} else {
236			return list[0];
237		}
238	}
239	return elem;
240}
241
242ElZip.SetAddr1 = function (pref_id, jpref) {
243	if (ElZip.faddr1.type == 'select-one' || ElZip.faddr1.type == 'select-multiple' ) {
244		var opts = ElZip.faddr1.options;
245		for(var i=0; i<opts.length; i++) {
246			var vpref = opts[i].value;
247			var tpref = opts[i].text;
248			opts[i].selected = (vpref == pref_id || vpref == jpref || tpref == jpref);
249		}
250	} else {
251		ElZip.faddr1.value = jpref;
252	}
253}
254
255isset = function (val) {
256	if(typeof(val)!='undefined') return true;
257	return false;
vendor: 1 bytes, line 258
258}

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.