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.