1/** 2 * æ¬èä½ä¿ä¾æåµç¨ å§åæ¨ç¤º-ç¸åæ¹å¼å享 3.0 Unported (CC BY-SA 3.0) ææ¬æ¢æ¬¾é²è¡ææ¬ã 3 * 妿¬²çè¦½æ¬ææ¬æ¢æ¬¾ä¹å¯æ¬ï¼è«é 訪 http://creativecommons.org/licenses/by-sa/3.0/deed.zh_TW 4 * 5 * This work is licensed under the Creative Commons Attribution-ShareAlike 3.0 Unported (CC BY-SA 3.0). 6 * To view a copy of this license, visit http://creativecommons.org/licenses/by-sa/3.0/deed.en 7 * 8 * jQuery TWzipcode å°ç£éµéåè jQuery æ´å å¥ä»¶ 9 * è¼é¬å°å»ºç«å¤çµå°ç£éµéåèä¸ææ¸ å®ï¼è®åå¿«éãå®å ¨ä¸é使ç¨è³æåº«ã 10 * http://app.essoduke.org/twzipcode/ 11 * 12 * @author: Essoduke Chang 13 * @version: 1.6.0 14 * 15 * [Changelog] 16 * ç¨å¼ç¢¼éæ§ï¼å¢å å¯è®æ§ã 17 * å¢å data æ¹æ³å¯åå¾ç®åé¸åç縣å¸éµéåèè³æï¼è¥ç¡é¸ååè¿åå ¨é¨è³æï¼ã 18 * æ«æç§»é¤ detect 使ç¨ç Geolocation APIã 19 * æ¡ç¨ Closure Compiler è£½ä½ production çæ¬ã 20 * 21 * Last Modify: Tue, 27 August 2013 10:23:56 GMT 22 */ 23;(function ($, window, document, undefined) { 24 25 'use strict'; 26 27 // Zipcode JSON data 28 var data = { 29 'åºéå¸': {'仿å': '200', '信義å': '201', '䏿£å': '202', 'ä¸å±±å': '203', '宿¨å': '204', 'ææå': '205', 'ä¸å µå': '206'}, 30 'å°åå¸': {'䏿£å': '100', '大åå': '103', 'ä¸å±±å': '104', 'æ¾å±±å': '105', '大å®å': '106', 'è¬è¯å': '108', '信義å': '110', '士æå': '111', 'åæå': '112', 'å §æ¹å': '114', '忏¯å': '115', 'æå±±å': '116'}, 31 'æ°åå¸': { 32 'è¬éå': '207', 'éå±±å': '208', 'æ¿æ©å': '220', 'æ±æ¢å': '221', 'æ·±åå': '222', 'ç³ç¢å': '223', 33 'çè³å': '224', '平溪å': '226', 'éæºªå': '227', '貢寮å': '228', 'æ°åºå': '231', 'åªæå': '232', 34 'çä¾å': '233', 'æ°¸åå': '234', 'ä¸åå': '235', 'ååå': '236', 'ä¸å³½å': '237', '樹æå': '238', 35 '鶯æå': '239', 'ä¸éå': '241', 'æ°èå': '242', 'æ³°å±±å': '243', 'æå£å': '244', 'èæ´²å': '247', 36 'äºè¡å': '248', 'å «éå': '249', 'æ·¡æ°´å': '251', 'ä¸èå': '252', 'ç³éå': '253' 37 }, 38 'å®è縣': { 39 'å®èå¸': '260', 'é åé®': '261', 'ç¤æºªé': '262', '壯åé': '263', 'å¡å±±é': '264', 'ç¾ æ±é®': '265', 40 '䏿é': '266', '大åé': '267', 'äºçµé': '268', 'å¬å±±é': '269', 'èæ¾³é®': '270', 'åæ¾³é': '272', 41 'é£éå°åå¶¼': '290' 42 }, 43 'æ°ç«¹å¸': {'æ±å': '300', 'åå': '300', 'é¦å±±å': '300'}, 44 'æ°ç«¹ç¸£': { 45 '竹åå¸': '302', 'æ¹å£é': '303', 'æ°è±é': '304', 'æ°åé®': '305', 'é西é®': '306', 'èæé': '307', 46 '寶山é': '308', '竹æ±é®': '310', 'äºå³°é': '311', 'æ©«å±±é': '312', 'å°ç³é': '313', 'ååé': '314', 47 '峨åµé': '315' 48 }, 49 'æ¡å縣': { 50 'ä¸å£¢å¸': '320', 'å¹³é®å¸': '324', '龿½é': '325', 'æ¥æ¢ é®': '326', 'æ°å±é': '327', 'è§é³é': '328', 51 'æ¡åå¸': '330', 'é¾å±±é': '333', 'å «å¾·å¸': '334', '大溪é®': '335', '復èé': '336', '大åé': '337', 52 'è竹é': '338' 53 }, 54 'èæ ç¸£': { 55 '竹åé®': '350', 'é 份é®': '351', 'ä¸ç£é': '352', 'ååºé': '353', 'ç æ½é': '354', 'å¾é¾é®': '356', 56 'ééé®': '357', 'è裡é®': '358', 'èæ å¸': '360', 'é æ©é': '361', 'é å±é': '362', 'å ¬é¤¨é': '363', 57 '大æ¹é': '364', 'æ³°å®é': '365', 'é é¼é': '366', 'ä¸ç¾©é': '367', '西æ¹é': '368', 'åèé®': '369' 58 }, 59 'å°ä¸å¸': { 60 'ä¸å': '400', 'æ±å': '401', 'åå': '402', '西å': '403', 'åå': '404', 'å屯å': '406', '西屯å': '407', 'å屯å': '408', 61 '太平å': '411', '大éå': '412', 'é§å³°å': '413', 'çæ¥å': '414', 'è±åå': '420', 'åéå': '421', 62 'ç³å²¡å': '422', 'æ±å¢å': '423', 'åå¹³å': '424', 'æ°ç¤¾å': '426', 'æ½åå': '427', '大é å': '428', 63 'ç¥å²¡å': '429', '大èå': '432', 'æ²é¹¿å': '433', 'é¾äºå': '434', '梧棲å': '435', 'æ¸ æ°´å': '436', 64 '大ç²å': '437', 'å¤åå': '438', '大å®å': '439' 65 }, 66 'å½°å縣': { 67 'å½°åå¸': '500', 'è¬åé': '502', 'è±å£é': '503', 'ç§æ°´é': '504', '鹿港é®': '505', 'ç¦èé': '506', 68 'ç·è¥¿é': '507', 'åç¾é®': '508', '伸港é': '509', '塿é®': '510', '社é é': '511', 'æ°¸éé': '512', 69 'åå¿é': '513', '溪æ¹é®': '514', '大æé': '515', 'åé¹½é': '516', 'ç°ä¸é®': '520', 'åæé®': '521', 70 'ç°å°¾é': '522', 'å¤é é': '523', '溪å·é': '524', '竹å¡é': '525', 'äºæé®': '526', '大åé': '527', 71 'è³èé': '528', 'äºæ°´é': '530' 72 }, 73 'åæç¸£': { 74 'åæå¸': '540', 'ä¸å¯®é': '541', 'è屯é®': '542', 'åå§é': '544', 'åéé®': '545', '仿é': '546', 75 'åéé': '551', 'ééé®': '552', 'æ°´éé': '553', 'éæ± é': '555', '信義é': '556', '竹山é®': '557', 76 '鹿谷é': '558' 77 }, 78 'å義å¸': {'æ±å': '600', '西å': '600'}, 79 'å義縣': { 80 'çªè·¯é': '602', 'æ¢ å±±é': '603', '竹å´é': '604', 'é¿éå±±': '605', 'ä¸åé': '606', '大åé': '607', 81 'æ°´ä¸é': '608', '鹿èé': '611', '太ä¿å¸': '612', 'æ´åå¸': '613', 'æ±ç³é': '614', 'å è ³é': '615', 82 'æ°æ¸¯é': '616', 'æ°éé': '621', '大æé®': '622', '溪å£é': '623', '義竹é': '624', 'å¸è¢é®': '625' 83 }, 84 'é²æç¸£': { 85 'æåé®': '630', '大å¤é': '631', 'èå°¾é®': '632', 'å庫é®': '633', 'è¤å¿ é': '634', 'æ±å¢é': '635', 86 'èºè¥¿é': '636', 'å´èé': '637', '麥寮é': '638', 'æå å¸': '640', 'æå §é': '643', 'å¤åé': '646', 87 'è¿æ¡é': '647', '西èºé®': '648', 'äºå´é': '649', '忏¯é®': '651', 'æ°´æé': '652', '壿¹é': '653', 88 'åæ¹é': '654', 'å é·é': '655' 89 }, 90 'å°åå¸': { 91 'ä¸è¥¿å': '700', 'æ±å': '701', 'åå': '702', 'åå': '704', 'å®å¹
91³å': '708', 'å®åå': '709', 92 '永康å': '710', 'æ¸ä»å': '711', 'æ°åå': '712', 'å·¦é®å': '713', 'çäºå': '714', 'æ¥ è¥¿å': '715', 93 'ååå': '716', 'ä»å¾·å': '717', 'éå»å': '718', 'é¾å´å': '719', 'å®ç°å': '720', '麻è±å': '721', 94 'ä½³éå': '722', '西港å': '723', 'ä¸è¡å': '724', 'å°è»å': '725', 'å¸ç²å': '726', 'åéå': '727', 95 'æ°çå': '730', 'å¾å£å': '731', 'ç½æ²³å': '732', 'æ±å±±å': '733', 'å ç²å': '734', 'ä¸çå': '735', 96 'æ³çå': '736', '鹽水å': '737', 'ååå': '741', 'å¤§å §å': '742', 'å±±ä¸å': '743', 'æ°å¸å': '744', 97 'å®å®å': '745' 98 }, 99 'é«éå¸': { 100 'æ°èå': '800', 'åéå': '801', 'èé å': '802', 'é¹½åå': '803', 'é¼å±±å': '804', 'ææ´¥å': '805', 101 'åé®å': '806', '䏿°å': '807', 'æ¥ æ¢å': '811', 'å°æ¸¯å': '812', 'å·¦çå': '813', 102 '仿¦å': '814', '大社å': '815', '岡山å': '820', '路竹å': '821', 'é¿è®å': '822', 'ç°å¯®é': '823', 103 'çå·¢å': '824', 'æ©é å': '825', 'æ¢å®å': '826', 'å½éå': '827', 'æ°¸å®å': '828', 'æ¹å §é': '829', 104 '鳳山å': '830', '大寮å': '831', 'æåå': '832', 'é³¥æ¾å': '833', '大樹å': '840', 'æå±±å': '842', 105 'ç¾æ¿å': '843', 'å é¾å': '844', 'å §éå': '845', 'ææå': '846', 'ç²ä»å': '847', 'æ¡æºå': '848', 106 'é£çªå¤å': '849', 'èæå': '851', 'èè£å': '852' 107 }, 108 '屿±ç¸£': { 109 '屿±å¸': '900', 'ä¸å°é': '901', 'é§èºé': '902', 'çªå®¶é': '903', 'ä¹å¦é': '904', '鿏¯é': '905', 110 '髿¨¹é': '906', 'é¹½åé': '907', 'é·æ²»é': '908', 'éºæ´é': '909', '竹ç°é': '911', 'å §åé': '912', 111 'è¬ä¸¹é': '913', 'æ½®å·é®': '920', 'æ³°æ¦é': '921', 'ä¾ç¾©é': '922', 'è¬å·é': '923', 'å´é é': '924', 112 'æ°å¤é': '925', 'åå·é': '926', 'æéé': '927', 'æ±æ¸¯é®': '928', 'ççé': '929', 'ä½³å¬é': '931', 113 'æ°åé': '932', 'æå¯®é': '940', 'æå±±é': '941', 'æ¥æ¥é': '942', 'ç åé': '943', 'è»åé': '944', 114 'ç¡ä¸¹é': '945', 'ææ¥é®': '946', '滿å·é': '947' 115 }, 116 'å°æ±ç¸£': { 117 'èºæ±å¸': '950', 'ç¶ å³¶é': '951', 'èå¶¼é': '952', 'å»¶å¹³é': '953', 'ååé': '954', '鹿éé': '955', 118 'éå±±é®': '956', '海端é': '957', 'æ± ä¸é': '958', 'æ±æ²³é': '959', 'æåé®': '961', 'é·æ¿±é': '962', 119 '太麻éé': '963', 'éå³°é': '964', '大æ¦é': '965', 'éä»é': '966' 120 }, 121 'è±è®ç¸£': { 122 'è±è®å¸': '970', 'æ°åé': '971', 'ç§æé': '972', 'åå®é': '973', '壽è±é': '974', 'é³³æé®': '975', 123 'å 復é': '976', 'è±æ¿±é': '977', 'çç©é': '978', 'è¬æ¦®é': '979', 'çéé®': '981', 'åæºªé': '982', 124 'å¯éé': '983' 125 }, 126 'éé縣': {'éæ²é®': '890', 'éæ¹é®': '891', 'é寧é': '892', 'éåé®': '893', 'çå¶¼é': '894', 'çåµé': '896'}, 127 '飿±ç¸£': {'åç«¿é': '209', 'åç«¿é': '210', 'èå é': '211', 'æ±å¼é': '212'}, 128 'æ¾æ¹ç¸£': {'é¦¬å ¬å¸': '880', '西嶼é': '881', 'æå®é': '882', 'ä¸ç¾é': '883', 'ç½æ²é': '884', 'æ¹è¥¿é': '885'}, 129 'åæµ·è«¸å³¶': {'æ±æ²': '817', 'åæ²': '819'} 130 }; 131 /** 132 * _hasOwnProperty for compatibility IE 133 * @param {Object} obj Object 134 * @param {string} property Property name 135 * @return {bool} 136 * @version 2.4.3 137 */ 138 function _hasOwnProperty(obj, property) { 139 try { 140 return (!window.hasOwnProperty) ? Object.prototype.hasOwnProperty.call(obj, property.toString()) : obj.hasOwnProperty(property.toString()); 141 } catch (ignore) { 142 } 143 } 144 /** 145 * twzipcode Constructor 146 * @param {Object} container HTML element 147 * @param {(Object|string)} options User settings 148 * @constructor 149 */ 150 function twzipcode (container, options) { 151 /** 152 * Default settings 153 * @type {Object} 154 */ 155 var defaults = { 156 detect: false, //v1.4 157 countyName: 'county', 158 districtName: 'district', 159 zipcodeName: 'zipcode', 160 countySel: '', 161 districtSel: '', 162 zipcodeSel: '', 163 readonly: false, 164 onCountySelect: null, //v1.5 165 onDistrictSelect: null, //v1.5 166 onZipcodeKeyUp: null, //v1.5 167 css: [] 168 }; 169 /** 170 * DOM of selector 171 * @type {Object} 172 */ 173 this.container = $(container); 174 /** 175 * Merge the options 176 * @type {Object} 177 */ 178 this.options = $.extend({}, defaults, options); 179 // initialize 180 this.init(); 181 } 182 /** 183 * tinyMap prototype 184 */ 185 twzipcode.prototype = { 186 VERSION: '1.6.0', 187 /** 188 * Method: Get all post data 189 * @return {Object} 190 */ 191 data: function () { 192 var wrap = this.wrap; 193 return _hasOwnProperty(data, wrap.county.val()) ? data[wrap.county.val()] : data; 194 }, 195 /** 196 * Method: Serialize the data 197 * @return {string} 198 */ 199 serialize: function () { 200 var result = [], obj = {}, s = {}, ele = {}; 201 obj = this.container.find('select,input'); 202 if (obj.length) { 203 obj.each(function () { 204 ele = $(this); 205 result.push(ele.attr('name') + '=' + ele.val()); 206 }); 207 } else { 208 $(this).children().each(function () { 209 s = $(this); 210 result.push(s.attr('name') + '=' + s.val()); 211 }); 212 } 213 return result.join('&'); 214 }, 215 216 /** 217 * Method: Destroy the container. 218 * @this {twzipcode} 219 */ 220 destroy: function () { 221 $.data(this.container, 'twzipcode', null); 222 if (this.container.length) { 223 this.container.empty().off('change keyup blur').remove(); 224 } 225 }, 226 227 /** 228 * Method: Reset the selected items to default. 229 * @this {twzipcode} 230 */ 231 reset: function (container, obj) { 232 var wrap = this.wrap, 233 def = ['<option value="">縣å¸</option>', '<option value="">éé®å¸å</option>'], 234 tpl = [], 235 county; 236 switch (obj) { 237 case 'district': 238 wrap.district.empty().html(def[1]); 239 break; 240 default: 241 wrap.county.empty().html(def[0]); 242 wrap.district.empty().html(def[1]); 243 for (county in data) { 244 if (_hasOwnProperty(data, county)) { 245 tpl.push('<option value="'); 246 tpl.push(county); 247 tpl.push('">'); 248 tpl.push(county); 249 tpl.push('</option>'); 250 } 251 }
252 $(tpl.join('')).appendTo(wrap.county); 253 break; 254 } 255 wrap.zipcode.val(''); 256 }, 257 /** 258 * Binding the event of the elements 259 * @this {twzipcode} 260 */ 261 bindings: function () { 262 263 var self = this, 264 opts = self.options, 265 wrap = self.wrap; 266 267 // county 268 wrap.county.on('change', function () { 269 var val = $(this).val(), 270 tpl = [], 271 district; 272 wrap.district.empty(); 273 if (val) { 274 for (district in data[val]) { 275 if (_hasOwnProperty(data[val], district)) { 276 tpl.push('<option value="'); 277 tpl.push(district); 278 tpl.push('">'); 279 tpl.push(district); 280 tpl.push('</option>'); 281 } 282 } 283 wrap.district.append(tpl.join('')).trigger('change'); 284 } else { 285 wrap.county.find('option:first').prop('selected', true); 286 self.reset('district'); 287 288 } 289 // callback binding 290 if ('function' === typeof opts.onCountySelect) { 291 opts.onCountySelect.call(this, wrap.county); 292 } 293 }); 294 // district 295 wrap.district.on('change', function () { 296 var val = $(this).val(); 297 if (wrap.county.val()) { 298 wrap.zipcode.val(data[wrap.county.val()][val]); 299 } 300 // callback binding 301 if ('function' === typeof opts.onDistrictSelect) { 302 opts.onDistrictSelect.call(this, wrap.district); 303 } 304 }); 305 // zipcode 306 wrap.zipcode.on('keyup blur', function () { 307 var obj = $(this), val = '', i, j; 308 obj.val(obj.val().replace(/[^0-9]/g, '')); 309 val = obj.val().toString(); 310 if (3 === val.length) { 311 for (i in data) { 312 if (_hasOwnProperty(data, i)) { 313 for (j in data[i]) { 314 if (_hasOwnProperty(data[i], j)) { 315 if (val === data[i][j]) { 316 wrap.county.val(i).trigger('change'); 317 wrap.district.val(j).trigger('change'); 318 break; 319 } 320 } 321 } 322 } 323 } 324 } 325 // callback binding 326 if ('function' === typeof opts.onZipcodeKeyUp) { 327 opts.onZipcodeKeyUp.call(this, wrap.zipcode); 328 } 329 }); 330 // if pass the default value 331 if (_hasOwnProperty(data, opts.countySel)) { 332 this.wrap.county.val(opts.countySel).trigger('change'); 333 if (_hasOwnProperty(data[opts.countySel], opts.districtSel)) { 334 this.wrap.district.val(opts.districtSel).trigger('change'); 335 } 336 } 337 if (opts.zipcodeSel) { 338 if (3 === (opts.zipcodeSel.toString()).length) { 339 this.wrap.zipcode.val(opts.zipcodeSel).trigger('blur'); 340 } 341 } 342 }, 343 /** 344 * Geolocation detect 345 * @declare 346 * @this {twzipcode} 347 */ 348 geolocation: function () { 349 }, 350 /** 351 * twzipcode Initialize 352 * @this {twzipcode} 353 */ 354 init: function () { 355 356 var self = this, 357 container = self.container, 358 opts = self.options, 359 role = { 360 county: container.find('[data-role="county"]:first'), 361 district: container.find('[data-role="district"]:first'), 362 zipcode: container.find('[data-role="zipcode"]:first') 363 }; 364 365 // Elements create 366 $('<select/>') 367 .attr('name', opts.countyName) 368 .addClass(role.county.data('style') || (undefined !== opts.css[0] ? opts.css[0] : '')) 369 .appendTo(role.county.length ? role.county : container); 370 371 $('<select/>') 372 .attr('name', opts.districtName) 373 .addClass(role.district.data('style') || (undefined !== opts.css[1] ? opts.css[1] : '')) 374 .appendTo(role.district.length ? role.district : container); 375 376 $('<input/>') 377 .attr({'type': 'text', 'name': opts.zipcodeName}) 378 .prop('readonly', opts.readonly) 379 .addClass(role.zipcode.data('style') || (undefined !== opts.css[2] ? opts.css[2] : '')) 380 .appendTo(role.zipcode.length ? role.zipcode : container); 381 382 this.wrap = {
383 county: container.find('select[name="' + opts.countyName + '"]:first'), 384 district: container.find('select[name="' + opts.districtName + '"]:first'), 385 zipcode: container.find('input[type=text][name="' + opts.zipcodeName + '"]:first') 386 }; 387 388 // reset the elements 389 this.reset(); 390 // elements event bindings 391 this.bindings(); 392 // geolocation API (declare) 393 this.geolocation(); 394 } 395 }; 396 /** 397 * jQuery twzipcode instance 398 * @param {Object} options Plugin settings 399 * @public 400 */ 401 $.fn['twzipcode'] = function (options) { 402 if ('string' === typeof options) { 403 switch (options) { 404 case 'data': case 'destroy': case 'reset': case 'serialize': 405 var result, instance; 406 this.each(function () { 407 instance = $.data(this, 'twzipcode'); 408 if (instance instanceof twzipcode && 'function' === typeof instance[options]) { 409 result = instance[options].apply(instance, Array.prototype.slice.call(arguments, 1)); 410 } 411 }); 412 break; 413 } 414 return undefined !== result ? result : this; 415 } else { 416 return this.each(function () { 417 if (!$.data(this, 'twzipcode')) { 418 $.data(this, 'twzipcode', new twzipcode(this, options)); 419 } 420 }); 421 } 422 }; 423 424}(jQuery, window, document));
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.