tw_zipcode 1.7.1 → 1.7.7
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/tw_zipcode/version.rb +1 -1
- data/vendor/assets/javascripts/tw_zipcode.js +529 -823
- data/vendor/assets/javascripts/tw_zipcode.min.js +34 -32
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 419e6eb8754fbc6894e7ffa383ea67bd97157857
|
4
|
+
data.tar.gz: f4e95a07a5e44165ff4e5eb99497488196da8fd9
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 423c7458f7d64320cab99ee5a4b1fa61be99ad099ac1fd6bd17dda52aee198e273582811ec3780666960a0a0b25a991b18e054d7e3b0f140dd252842c28825c1
|
7
|
+
data.tar.gz: 4f1aaf3577ac9f3fbb9e0429a9eaabcde3c737ae6d51830886beb42894f617b52436fc4a5c726b376577282b4b312fa9587021edeeefabd52ff13dd68b939bc1
|
data/lib/tw_zipcode/version.rb
CHANGED
@@ -1,854 +1,560 @@
|
|
1
|
-
/*jshint unused:false */
|
2
1
|
/**
|
3
2
|
* jQuery TWzipcode plugin
|
4
|
-
*
|
3
|
+
* https://app.essoduke.org/twzipcode/
|
5
4
|
* Copyright 2015 essoduke.org, Licensed MIT.
|
6
5
|
*
|
7
6
|
* Changelog
|
8
7
|
* -------------------------------
|
9
|
-
*
|
8
|
+
* 修正 readonly 會造成 keyup, blur 無法被 detect 觸發的錯誤。
|
10
9
|
*
|
11
10
|
* @author essoduke.org
|
12
|
-
* @version 1.7.
|
11
|
+
* @version 1.7.7
|
13
12
|
* @license MIT License
|
14
|
-
* Last modified: 2015-08-12 16:22:13+08:00
|
15
13
|
*/
|
16
|
-
;
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
'復興區': '336',
|
124
|
-
'大園區': '337',
|
125
|
-
'蘆竹區': '338'
|
126
|
-
},
|
127
|
-
'苗栗縣': {
|
128
|
-
'竹南鎮': '350',
|
129
|
-
'頭份市': '351',
|
130
|
-
'三灣鄉': '352',
|
131
|
-
'南庄鄉': '353',
|
132
|
-
'獅潭鄉': '354',
|
133
|
-
'後龍鎮': '356',
|
134
|
-
'通霄鎮': '357',
|
135
|
-
'苑裡鎮': '358',
|
136
|
-
'苗栗市': '360',
|
137
|
-
'造橋鄉': '361',
|
138
|
-
'頭屋鄉': '362',
|
139
|
-
'公館鄉': '363',
|
140
|
-
'大湖鄉': '364',
|
141
|
-
'泰安鄉': '365',
|
142
|
-
'銅鑼鄉': '366',
|
143
|
-
'三義鄉': '367',
|
144
|
-
'西湖鄉': '368',
|
145
|
-
'卓蘭鎮': '369'
|
146
|
-
},
|
147
|
-
'台中市': {
|
148
|
-
'中區': '400',
|
149
|
-
'東區': '401',
|
150
|
-
'南區': '402',
|
151
|
-
'西區': '403',
|
152
|
-
'北區': '404',
|
153
|
-
'北屯區': '406',
|
154
|
-
'西屯區': '407',
|
155
|
-
'南屯區': '408',
|
156
|
-
'太平區': '411',
|
157
|
-
'大里區': '412',
|
158
|
-
'霧峰區': '413',
|
159
|
-
'烏日區': '414',
|
160
|
-
'豐原區': '420',
|
161
|
-
'后里區': '421',
|
162
|
-
'石岡區': '422',
|
163
|
-
'東勢區': '423',
|
164
|
-
'和平區': '424',
|
165
|
-
'新社區': '426',
|
166
|
-
'潭子區': '427',
|
167
|
-
'大雅區': '428',
|
168
|
-
'神岡區': '429',
|
169
|
-
'大肚區': '432',
|
170
|
-
'沙鹿區': '433',
|
171
|
-
'龍井區': '434',
|
172
|
-
'梧棲區': '435',
|
173
|
-
'清水區': '436',
|
174
|
-
'大甲區': '437',
|
175
|
-
'外埔區': '438',
|
176
|
-
'大安區': '439'
|
177
|
-
},
|
178
|
-
'彰化縣': {
|
179
|
-
'彰化市': '500',
|
180
|
-
'芬園鄉': '502',
|
181
|
-
'花壇鄉': '503',
|
182
|
-
'秀水鄉': '504',
|
183
|
-
'鹿港鎮': '505',
|
184
|
-
'福興鄉': '506',
|
185
|
-
'線西鄉': '507',
|
186
|
-
'和美鎮': '508',
|
187
|
-
'伸港鄉': '509',
|
188
|
-
'員林市': '510',
|
189
|
-
'社頭鄉': '511',
|
190
|
-
'永靖鄉': '512',
|
191
|
-
'埔心鄉': '513',
|
192
|
-
'溪湖鎮': '514',
|
193
|
-
'大村鄉': '515',
|
194
|
-
'埔鹽鄉': '516',
|
195
|
-
'田中鎮': '520',
|
196
|
-
'北斗鎮': '521',
|
197
|
-
'田尾鄉': '522',
|
198
|
-
'埤頭鄉': '523',
|
199
|
-
'溪州鄉': '524',
|
200
|
-
'竹塘鄉': '525',
|
201
|
-
'二林鎮': '526',
|
202
|
-
'大城鄉': '527',
|
203
|
-
'芳苑鄉': '528',
|
204
|
-
'二水鄉': '530'
|
205
|
-
},
|
206
|
-
'南投縣': {
|
207
|
-
'南投市': '540',
|
208
|
-
'中寮鄉': '541',
|
209
|
-
'草屯鎮': '542',
|
210
|
-
'國姓鄉': '544',
|
211
|
-
'埔里鎮': '545',
|
212
|
-
'仁愛鄉': '546',
|
213
|
-
'名間鄉': '551',
|
214
|
-
'集集鎮': '552',
|
215
|
-
'水里鄉': '553',
|
216
|
-
'魚池鄉': '555',
|
217
|
-
'信義鄉': '556',
|
218
|
-
'竹山鎮': '557',
|
219
|
-
'鹿谷鄉': '558'
|
220
|
-
},
|
221
|
-
'嘉義市': {
|
222
|
-
'東區': '600',
|
223
|
-
'西區': '600'
|
224
|
-
},
|
225
|
-
'嘉義縣': {
|
226
|
-
'番路鄉': '602',
|
227
|
-
'梅山鄉': '603',
|
228
|
-
'竹崎鄉': '604',
|
229
|
-
'阿里山': '605',
|
230
|
-
'中埔鄉': '606',
|
231
|
-
'大埔鄉': '607',
|
232
|
-
'水上鄉': '608',
|
233
|
-
'鹿草鄉': '611',
|
234
|
-
'太保市': '612',
|
235
|
-
'朴子市': '613',
|
236
|
-
'東石鄉': '614',
|
237
|
-
'六腳鄉': '615',
|
238
|
-
'新港鄉': '616',
|
239
|
-
'民雄鄉': '621',
|
240
|
-
'大林鎮': '622',
|
241
|
-
'溪口鄉': '623',
|
242
|
-
'義竹鄉': '624',
|
243
|
-
'布袋鎮': '625'
|
244
|
-
},
|
245
|
-
'雲林縣': {
|
246
|
-
'斗南鎮': '630',
|
247
|
-
'大埤鄉': '631',
|
248
|
-
'虎尾鎮': '632',
|
249
|
-
'土庫鎮': '633',
|
250
|
-
'褒忠鄉': '634',
|
251
|
-
'東勢鄉': '635',
|
252
|
-
'臺西鄉': '636',
|
253
|
-
'崙背鄉': '637',
|
254
|
-
'麥寮鄉': '638',
|
255
|
-
'斗六市': '640',
|
256
|
-
'林內鄉': '643',
|
257
|
-
'古坑鄉': '646',
|
258
|
-
'莿桐鄉': '647',
|
259
|
-
'西螺鎮': '648',
|
260
|
-
'二崙鄉': '649',
|
261
|
-
'北港鎮': '651',
|
262
|
-
'水林鄉': '652',
|
263
|
-
'口湖鄉': '653',
|
264
|
-
'四湖鄉': '654',
|
265
|
-
'元長鄉': '655'
|
266
|
-
},
|
267
|
-
'台南市': {
|
268
|
-
'中西區': '700',
|
269
|
-
'東區': '701',
|
270
|
-
'南區': '702',
|
271
|
-
'北區': '704',
|
272
|
-
'安平區': '708',
|
273
|
-
'安南區': '709',
|
274
|
-
'永康區': '710',
|
275
|
-
'歸仁區': '711',
|
276
|
-
'新化區': '712',
|
277
|
-
'左鎮區': '713',
|
278
|
-
'玉井區': '714',
|
279
|
-
'楠西區': '715',
|
280
|
-
'南化區': '716',
|
281
|
-
'仁德區': '717',
|
282
|
-
'關廟區': '718',
|
283
|
-
'龍崎區': '719',
|
284
|
-
'官田區': '720',
|
285
|
-
'麻豆區': '721',
|
286
|
-
'佳里區': '722',
|
287
|
-
'西港區': '723',
|
288
|
-
'七股區': '724',
|
289
|
-
'將軍區': '725',
|
290
|
-
'學甲區': '726',
|
291
|
-
'北門區': '727',
|
292
|
-
'新營區': '730',
|
293
|
-
'後壁區': '731',
|
294
|
-
'白河區': '732',
|
295
|
-
'東山區': '733',
|
296
|
-
'六甲區': '734',
|
297
|
-
'下營區': '735',
|
298
|
-
'柳營區': '736',
|
299
|
-
'鹽水區': '737',
|
300
|
-
'善化區': '741',
|
301
|
-
'大內區': '742',
|
302
|
-
'山上區': '743',
|
303
|
-
'新市區': '744',
|
304
|
-
'安定區': '745'
|
305
|
-
},
|
306
|
-
'高雄市': {
|
307
|
-
'新興區': '800',
|
308
|
-
'前金區': '801',
|
309
|
-
'苓雅區': '802',
|
310
|
-
'鹽埕區': '803',
|
311
|
-
'鼓山區': '804',
|
312
|
-
'旗津區': '805',
|
313
|
-
'前鎮區': '806',
|
314
|
-
'三民區': '807',
|
315
|
-
'楠梓區': '811',
|
316
|
-
'小港區': '812',
|
317
|
-
'左營區': '813',
|
318
|
-
'仁武區': '814',
|
319
|
-
'大社區': '815',
|
320
|
-
'岡山區': '820',
|
321
|
-
'路竹區': '821',
|
322
|
-
'阿蓮區': '822',
|
323
|
-
'田寮鄉': '823',
|
324
|
-
'燕巢區': '824',
|
325
|
-
'橋頭區': '825',
|
326
|
-
'梓官區': '826',
|
327
|
-
'彌陀區': '827',
|
328
|
-
'永安區': '828',
|
329
|
-
'湖內鄉': '829',
|
330
|
-
'鳳山區': '830',
|
331
|
-
'大寮區': '831',
|
332
|
-
'林園區': '832',
|
333
|
-
'鳥松區': '833',
|
334
|
-
'大樹區': '840',
|
335
|
-
'旗山區': '842',
|
336
|
-
'美濃區': '843',
|
337
|
-
'六龜區': '844',
|
338
|
-
'內門區': '845',
|
339
|
-
'杉林區': '846',
|
340
|
-
'甲仙區': '847',
|
341
|
-
'桃源區': '848',
|
342
|
-
'那瑪夏區': '849',
|
343
|
-
'茂林區': '851',
|
344
|
-
'茄萣區': '852'
|
345
|
-
},
|
346
|
-
'屏東縣': {
|
347
|
-
'屏東市': '900',
|
348
|
-
'三地門': '901',
|
349
|
-
'霧臺鄉': '902',
|
350
|
-
'瑪家鄉': '903',
|
351
|
-
'九如鄉': '904',
|
352
|
-
'里港鄉': '905',
|
353
|
-
'高樹鄉': '906',
|
354
|
-
'鹽埔鄉': '907',
|
355
|
-
'長治鄉': '908',
|
356
|
-
'麟洛鄉': '909',
|
357
|
-
'竹田鄉': '911',
|
358
|
-
'內埔鄉': '912',
|
359
|
-
'萬丹鄉': '913',
|
360
|
-
'潮州鎮': '920',
|
361
|
-
'泰武鄉': '921',
|
362
|
-
'來義鄉': '922',
|
363
|
-
'萬巒鄉': '923',
|
364
|
-
'崁頂鄉': '924',
|
365
|
-
'新埤鄉': '925',
|
366
|
-
'南州鄉': '926',
|
367
|
-
'林邊鄉': '927',
|
368
|
-
'東港鎮': '928',
|
369
|
-
'琉球鄉': '929',
|
370
|
-
'佳冬鄉': '931',
|
371
|
-
'新園鄉': '932',
|
372
|
-
'枋寮鄉': '940',
|
373
|
-
'枋山鄉': '941',
|
374
|
-
'春日鄉': '942',
|
375
|
-
'獅子鄉': '943',
|
376
|
-
'車城鄉': '944',
|
377
|
-
'牡丹鄉': '945',
|
378
|
-
'恆春鎮': '946',
|
379
|
-
'滿州鄉': '947'
|
380
|
-
},
|
381
|
-
'台東縣': {
|
382
|
-
'臺東市': '950',
|
383
|
-
'綠島鄉': '951',
|
384
|
-
'蘭嶼鄉': '952',
|
385
|
-
'延平鄉': '953',
|
386
|
-
'卑南鄉': '954',
|
387
|
-
'鹿野鄉': '955',
|
388
|
-
'關山鎮': '956',
|
389
|
-
'海端鄉': '957',
|
390
|
-
'池上鄉': '958',
|
391
|
-
'東河鄉': '959',
|
392
|
-
'成功鎮': '961',
|
393
|
-
'長濱鄉': '962',
|
394
|
-
'太麻里鄉': '963',
|
395
|
-
'金峰鄉': '964',
|
396
|
-
'大武鄉': '965',
|
397
|
-
'達仁鄉': '966'
|
398
|
-
},
|
399
|
-
'花蓮縣': {
|
400
|
-
'花蓮市': '970',
|
401
|
-
'新城鄉': '971',
|
402
|
-
'秀林鄉': '972',
|
403
|
-
'吉安鄉': '973',
|
404
|
-
'壽豐鄉': '974',
|
405
|
-
'鳳林鎮': '975',
|
406
|
-
'光復鄉': '976',
|
407
|
-
'豐濱鄉': '977',
|
408
|
-
'瑞穗鄉': '978',
|
409
|
-
'萬榮鄉': '979',
|
410
|
-
'玉里鎮': '981',
|
411
|
-
'卓溪鄉': '982',
|
412
|
-
'富里鄉': '983'
|
413
|
-
},
|
414
|
-
'金門縣': {
|
415
|
-
'金沙鎮': '890',
|
416
|
-
'金湖鎮': '891',
|
417
|
-
'金寧鄉': '892',
|
418
|
-
'金城鎮': '893',
|
419
|
-
'烈嶼鄉': '894',
|
420
|
-
'烏坵鄉': '896'
|
421
|
-
},
|
422
|
-
'連江縣': {
|
423
|
-
'南竿鄉': '209',
|
424
|
-
'北竿鄉': '210',
|
425
|
-
'莒光鄉': '211',
|
426
|
-
'東引鄉': '212'
|
427
|
-
},
|
428
|
-
'澎湖縣': {
|
429
|
-
'馬公市': '880',
|
430
|
-
'西嶼鄉': '881',
|
431
|
-
'望安鄉': '882',
|
432
|
-
'七美鄉': '883',
|
433
|
-
'白沙鄉': '884',
|
434
|
-
'湖西鄉': '885'
|
435
|
-
},
|
436
|
-
'南海諸島': {
|
437
|
-
'東沙': '817',
|
438
|
-
'南沙': '819'
|
439
|
-
}
|
440
|
-
};
|
441
|
-
|
442
|
-
/**
|
443
|
-
* _hasOwnProperty for compatibility IE
|
444
|
-
* @param {Object} obj Object
|
445
|
-
* @param {string} property Property name
|
446
|
-
* @return {bool}
|
447
|
-
* @version 2.4.3
|
448
|
-
*/
|
449
|
-
function _hasOwnProperty(obj, property) {
|
450
|
-
try {
|
451
|
-
return !window.hasOwnProperty ?
|
452
|
-
Object.prototype.hasOwnProperty.call(obj, property.toString()) :
|
453
|
-
obj.hasOwnProperty(property.toString());
|
454
|
-
} catch (ignore) {}
|
455
|
-
}
|
456
|
-
/**
|
457
|
-
* twzipcode Constructor
|
458
|
-
* @param {Object} container HTML element
|
459
|
-
* @param {(Object|string)} options User settings
|
460
|
-
* @constructor
|
461
|
-
*/
|
462
|
-
function TWzipcode(container, options) {
|
463
|
-
/**
|
464
|
-
* Default settings
|
465
|
-
* @type {Object}
|
466
|
-
*/
|
467
|
-
var defaults = {
|
468
|
-
'countyName': 'county',
|
469
|
-
'countySel': '',
|
470
|
-
'css': [],
|
471
|
-
'detect': false, // v1.6.7
|
472
|
-
'districtName': 'district',
|
473
|
-
'districtSel': '',
|
474
|
-
'onCountySelect': null, // v1.5
|
475
|
-
'onDistrictSelect': null, // v1.5
|
476
|
-
'onZipcodeKeyUp': null, // v1.5
|
477
|
-
'readonly': false,
|
478
|
-
'zipcodeName': 'zipcode',
|
479
|
-
'zipcodeSel': '',
|
480
|
-
'zipcodeIntoDistrict': false, // v1.6.6
|
481
|
-
'googleMapsKey': '' // v1.6.9
|
14
|
+
;(function ($, window, document, undefined) {
|
15
|
+
|
16
|
+
'use strict';
|
17
|
+
|
18
|
+
// Zipcode JSON data
|
19
|
+
var data = {
|
20
|
+
'基隆市': {'仁愛區': '200', '信義區': '201', '中正區': '202', '中山區': '203', '安樂區': '204', '暖暖區': '205', '七堵區': '206'},
|
21
|
+
'台北市': {'中正區': '100', '大同區': '103', '中山區': '104', '松山區': '105', '大安區': '106', '萬華區': '108', '信義區': '110', '士林區': '111', '北投區': '112', '內湖區': '114', '南港區': '115', '文山區': '116'},
|
22
|
+
'新北市': {
|
23
|
+
'萬里區': '207', '金山區': '208', '板橋區': '220', '汐止區': '221', '深坑區': '222', '石碇區': '223',
|
24
|
+
'瑞芳區': '224', '平溪區': '226', '雙溪區': '227', '貢寮區': '228', '新店區': '231', '坪林區': '232',
|
25
|
+
'烏來區': '233', '永和區': '234', '中和區': '235', '土城區': '236', '三峽區': '237', '樹林區': '238',
|
26
|
+
'鶯歌區': '239', '三重區': '241', '新莊區': '242', '泰山區': '243', '林口區': '244', '蘆洲區': '247',
|
27
|
+
'五股區': '248', '八里區': '249', '淡水區': '251', '三芝區': '252', '石門區': '253'
|
28
|
+
},
|
29
|
+
'宜蘭縣': {
|
30
|
+
'宜蘭市': '260', '頭城鎮': '261', '礁溪鄉': '262', '壯圍鄉': '263', '員山鄉': '264', '羅東鎮': '265',
|
31
|
+
'三星鄉': '266', '大同鄉': '267', '五結鄉': '268', '冬山鄉': '269', '蘇澳鎮': '270', '南澳鄉': '272',
|
32
|
+
'釣魚台列嶼': '290'
|
33
|
+
},
|
34
|
+
'新竹市': {'東區': '300', '北區': '300', '香山區': '300'},
|
35
|
+
'新竹縣': {
|
36
|
+
'竹北市': '302', '湖口鄉': '303', '新豐鄉': '304', '新埔鎮': '305', '關西鎮': '306', '芎林鄉': '307',
|
37
|
+
'寶山鄉': '308', '竹東鎮': '310', '五峰鄉': '311', '橫山鄉': '312', '尖石鄉': '313', '北埔鄉': '314',
|
38
|
+
'峨嵋鄉': '315'
|
39
|
+
},
|
40
|
+
'桃園市': {
|
41
|
+
'中壢區': '320', '平鎮區': '324', '龍潭區': '325', '楊梅區': '326', '新屋區': '327', '觀音區': '328',
|
42
|
+
'桃園區': '330', '龜山區': '333', '八德區': '334', '大溪區': '335', '復興區': '336', '大園區': '337',
|
43
|
+
'蘆竹區': '338'
|
44
|
+
},
|
45
|
+
'苗栗縣': {
|
46
|
+
'竹南鎮': '350', '頭份市': '351', '三灣鄉': '352', '南庄鄉': '353', '獅潭鄉': '354', '後龍鎮': '356',
|
47
|
+
'通霄鎮': '357', '苑裡鎮': '358', '苗栗市': '360', '造橋鄉': '361', '頭屋鄉': '362', '公館鄉': '363',
|
48
|
+
'大湖鄉': '364', '泰安鄉': '365', '銅鑼鄉': '366', '三義鄉': '367', '西湖鄉': '368', '卓蘭鎮': '369'
|
49
|
+
},
|
50
|
+
'台中市': {
|
51
|
+
'中區': '400', '東區': '401', '南區': '402', '西區': '403', '北區': '404', '北屯區': '406', '西屯區': '407', '南屯區': '408',
|
52
|
+
'太平區': '411', '大里區': '412', '霧峰區': '413', '烏日區': '414', '豐原區': '420', '后里區': '421',
|
53
|
+
'石岡區': '422', '東勢區': '423', '和平區': '424', '新社區': '426', '潭子區': '427', '大雅區': '428',
|
54
|
+
'神岡區': '429', '大肚區': '432', '沙鹿區': '433', '龍井區': '434', '梧棲區': '435', '清水區': '436',
|
55
|
+
'大甲區': '437', '外埔區': '438', '大安區': '439'
|
56
|
+
},
|
57
|
+
'彰化縣': {
|
58
|
+
'彰化市': '500', '芬園鄉': '502', '花壇鄉': '503', '秀水鄉': '504', '鹿港鎮': '505', '福興鄉': '506',
|
59
|
+
'線西鄉': '507', '和美鎮': '508', '伸港鄉': '509', '員林市': '510', '社頭鄉': '511', '永靖鄉': '512',
|
60
|
+
'埔心鄉': '513', '溪湖鎮': '514', '大村鄉': '515', '埔鹽鄉': '516', '田中鎮': '520', '北斗鎮': '521',
|
61
|
+
'田尾鄉': '522', '埤頭鄉': '523', '溪州鄉': '524', '竹塘鄉': '525', '二林鎮': '526', '大城鄉': '527',
|
62
|
+
'芳苑鄉': '528', '二水鄉': '530'
|
63
|
+
},
|
64
|
+
'南投縣': {
|
65
|
+
'南投市': '540', '中寮鄉': '541', '草屯鎮': '542', '國姓鄉': '544', '埔里鎮': '545', '仁愛鄉': '546',
|
66
|
+
'名間鄉': '551', '集集鎮': '552', '水里鄉': '553', '魚池鄉': '555', '信義鄉': '556', '竹山鎮': '557',
|
67
|
+
'鹿谷鄉': '558'
|
68
|
+
},
|
69
|
+
'嘉義市': {'東區': '600', '西區': '600'},
|
70
|
+
'嘉義縣': {
|
71
|
+
'番路鄉': '602', '梅山鄉': '603', '竹崎鄉': '604', '阿里山': '605', '中埔鄉': '606', '大埔鄉': '607',
|
72
|
+
'水上鄉': '608', '鹿草鄉': '611', '太保市': '612', '朴子市': '613', '東石鄉': '614', '六腳鄉': '615',
|
73
|
+
'新港鄉': '616', '民雄鄉': '621', '大林鎮': '622', '溪口鄉': '623', '義竹鄉': '624', '布袋鎮': '625'
|
74
|
+
},
|
75
|
+
'雲林縣': {
|
76
|
+
'斗南鎮': '630', '大埤鄉': '631', '虎尾鎮': '632', '土庫鎮': '633', '褒忠鄉': '634', '東勢鄉': '635',
|
77
|
+
'臺西鄉': '636', '崙背鄉': '637', '麥寮鄉': '638', '斗六市': '640', '林內鄉': '643', '古坑鄉': '646',
|
78
|
+
'莿桐鄉': '647', '西螺鎮': '648', '二崙鄉': '649', '北港鎮': '651', '水林鄉': '652', '口湖鄉': '653',
|
79
|
+
'四湖鄉': '654', '元長鄉': '655'
|
80
|
+
},
|
81
|
+
'台南市': {
|
82
|
+
'中西區': '700', '東區': '701', '南區': '702', '北區': '704', '安平區': '708', '安南區': '709',
|
83
|
+
'永康區': '710', '歸仁區': '711', '新化區': '712', '左鎮區': '713', '玉井區': '714', '楠西區': '715',
|
84
|
+
'南化區': '716', '仁德區': '717', '關廟區': '718', '龍崎區': '719', '官田區': '720', '麻豆區': '721',
|
85
|
+
'佳里區': '722', '西港區': '723', '七股區': '724', '將軍區': '725', '學甲區': '726', '北門區': '727',
|
86
|
+
'新營區': '730', '後壁區': '731', '白河區': '732', '東山區': '733', '六甲區': '734', '下營區': '735',
|
87
|
+
'柳營區': '736', '鹽水區': '737', '善化區': '741', '大內區': '742', '山上區': '743', '新市區': '744',
|
88
|
+
'安定區': '745'
|
89
|
+
},
|
90
|
+
'高雄市': {
|
91
|
+
'新興區': '800', '前金區': '801', '苓雅區': '802', '鹽埕區': '803', '鼓山區': '804', '旗津區': '805',
|
92
|
+
'前鎮區': '806', '三民區': '807', '楠梓區': '811', '小港區': '812', '左營區': '813',
|
93
|
+
'仁武區': '814', '大社區': '815', '東沙群島': '817', '南沙群島': '819', '岡山區': '820', '路竹區': '821',
|
94
|
+
'阿蓮區': '822', '田寮區': '823',
|
95
|
+
'燕巢區': '824', '橋頭區': '825', '梓官區': '826', '彌陀區': '827', '永安區': '828', '湖內區': '829',
|
96
|
+
'鳳山區': '830', '大寮區': '831', '林園區': '832', '鳥松區': '833', '大樹區': '840', '旗山區': '842',
|
97
|
+
'美濃區': '843', '六龜區': '844', '內門區': '845', '杉林區': '846', '甲仙區': '847', '桃源區': '848',
|
98
|
+
'那瑪夏區': '849', '茂林區': '851', '茄萣區': '852'
|
99
|
+
},
|
100
|
+
'屏東縣': {
|
101
|
+
'屏東市': '900', '三地門鄉': '901', '霧臺鄉': '902', '瑪家鄉': '903', '九如鄉': '904', '里港鄉': '905',
|
102
|
+
'高樹鄉': '906', '鹽埔鄉': '907', '長治鄉': '908', '麟洛鄉': '909', '竹田鄉': '911', '內埔鄉': '912',
|
103
|
+
'萬丹鄉': '913', '潮州鎮': '920', '泰武鄉': '921', '來義鄉': '922', '萬巒鄉': '923', '崁頂鄉': '924',
|
104
|
+
'新埤鄉': '925', '南州鄉': '926', '林邊鄉': '927', '東港鎮': '928', '琉球鄉': '929', '佳冬鄉': '931',
|
105
|
+
'新園鄉': '932', '枋寮鄉': '940', '枋山鄉': '941', '春日鄉': '942', '獅子鄉': '943', '車城鄉': '944',
|
106
|
+
'牡丹鄉': '945', '恆春鎮': '946', '滿州鄉': '947'
|
107
|
+
},
|
108
|
+
'台東縣': {
|
109
|
+
'臺東市': '950', '綠島鄉': '951', '蘭嶼鄉': '952', '延平鄉': '953', '卑南鄉': '954', '鹿野鄉': '955',
|
110
|
+
'關山鎮': '956', '海端鄉': '957', '池上鄉': '958', '東河鄉': '959', '成功鎮': '961', '長濱鄉': '962',
|
111
|
+
'太麻里鄉': '963', '金峰鄉': '964', '大武鄉': '965', '達仁鄉': '966'
|
112
|
+
},
|
113
|
+
'花蓮縣': {
|
114
|
+
'花蓮市': '970', '新城鄉': '971', '秀林鄉': '972', '吉安鄉': '973', '壽豐鄉': '974', '鳳林鎮': '975',
|
115
|
+
'光復鄉': '976', '豐濱鄉': '977', '瑞穗鄉': '978', '萬榮鄉': '979', '玉里鎮': '981', '卓溪鄉': '982',
|
116
|
+
'富里鄉': '983'
|
117
|
+
},
|
118
|
+
'金門縣': {'金沙鎮': '890', '金湖鎮': '891', '金寧鄉': '892', '金城鎮': '893', '烈嶼鄉': '894', '烏坵鄉': '896'},
|
119
|
+
'連江縣': {'南竿鄉': '209', '北竿鄉': '210', '莒光鄉': '211', '東引鄉': '212'},
|
120
|
+
'澎湖縣': {'馬公市': '880', '西嶼鄉': '881', '望安鄉': '882', '七美鄉': '883', '白沙鄉': '884', '湖西鄉': '885'}
|
482
121
|
};
|
483
122
|
/**
|
484
|
-
*
|
485
|
-
* @
|
486
|
-
|
487
|
-
|
488
|
-
/**
|
489
|
-
* Merge the options
|
490
|
-
* @type {Object}
|
491
|
-
*/
|
492
|
-
this.options = $.extend({}, defaults, options);
|
493
|
-
// initialize
|
494
|
-
this.init();
|
495
|
-
}
|
496
|
-
/**
|
497
|
-
* twzipcode prototype
|
498
|
-
*/
|
499
|
-
TWzipcode.prototype = {
|
500
|
-
|
501
|
-
VERSION: '1.7.1',
|
502
|
-
|
503
|
-
/**
|
504
|
-
* Method: Get all post data
|
505
|
-
* @return {Object}
|
506
|
-
*/
|
507
|
-
data: function() {
|
508
|
-
var wrap = this.wrap;
|
509
|
-
return _hasOwnProperty(data, wrap.county.val()) ? data[wrap.county.val()] : data;
|
510
|
-
},
|
511
|
-
|
512
|
-
/**
|
513
|
-
* Method: Serialize the data
|
514
|
-
* @return {string}
|
123
|
+
* twzipcode Constructor
|
124
|
+
* @param {Object} container HTML element
|
125
|
+
* @param {(Object|string)} options User settings
|
126
|
+
* @constructor
|
515
127
|
*/
|
516
|
-
|
517
|
-
|
518
|
-
|
519
|
-
|
520
|
-
|
521
|
-
|
522
|
-
|
523
|
-
|
524
|
-
|
525
|
-
|
526
|
-
|
527
|
-
|
528
|
-
|
529
|
-
|
530
|
-
|
531
|
-
|
532
|
-
|
533
|
-
|
534
|
-
|
535
|
-
|
536
|
-
|
537
|
-
|
538
|
-
|
539
|
-
|
540
|
-
|
541
|
-
|
542
|
-
|
543
|
-
|
544
|
-
|
545
|
-
|
546
|
-
|
128
|
+
function TWzipcode (container, options) {
|
129
|
+
/**
|
130
|
+
* Default settings
|
131
|
+
* @type {Object}
|
132
|
+
*/
|
133
|
+
var defaults = {
|
134
|
+
'countyName': 'county',
|
135
|
+
'countySel': '',
|
136
|
+
'css': [],
|
137
|
+
'detect': false, // v1.6.7
|
138
|
+
'districtName': 'district',
|
139
|
+
'districtSel': '',
|
140
|
+
'onCountySelect': null, // v1.5
|
141
|
+
'onDistrictSelect': null, // v1.5
|
142
|
+
'onZipcodeKeyUp': null, // v1.5
|
143
|
+
'readonly': false,
|
144
|
+
'zipcodeName': 'zipcode',
|
145
|
+
'zipcodePlaceholder': '郵遞區號',
|
146
|
+
'zipcodeSel': '',
|
147
|
+
'zipcodeIntoDistrict': false, // v1.6.6
|
148
|
+
'googleMapsKey': '' // v1.6.9
|
149
|
+
};
|
150
|
+
/**
|
151
|
+
* DOM of selector
|
152
|
+
* @type {Object}
|
153
|
+
*/
|
154
|
+
this.container = $(container);
|
155
|
+
/**
|
156
|
+
* Merge the options
|
157
|
+
* @type {Object}
|
158
|
+
*/
|
159
|
+
this.options = $.extend({}, defaults, options);
|
160
|
+
// initialize
|
161
|
+
this.init();
|
162
|
+
}
|
547
163
|
/**
|
548
|
-
*
|
549
|
-
* @this {twzipcode}
|
164
|
+
* TWzipcode prototype
|
550
165
|
*/
|
551
|
-
|
552
|
-
|
553
|
-
|
554
|
-
|
555
|
-
|
556
|
-
|
557
|
-
|
166
|
+
TWzipcode.prototype = {
|
167
|
+
|
168
|
+
VERSION: '1.7.7',
|
169
|
+
|
170
|
+
/**
|
171
|
+
* Method: Get all post data
|
172
|
+
* @return {Object}
|
173
|
+
*/
|
174
|
+
data: function () {
|
175
|
+
var wrap = this.wrap;
|
176
|
+
return 'undefined' !== typeof data[wrap.county.val()] ?
|
177
|
+
data[wrap.county.val()] :
|
178
|
+
data;
|
558
179
|
},
|
559
|
-
|
560
|
-
|
561
|
-
|
562
|
-
|
563
|
-
|
564
|
-
|
565
|
-
|
566
|
-
|
567
|
-
|
568
|
-
|
569
|
-
if (
|
570
|
-
|
180
|
+
/**
|
181
|
+
* Method: Serialize the data
|
182
|
+
* @return {string}
|
183
|
+
*/
|
184
|
+
serialize: function () {
|
185
|
+
var result = [],
|
186
|
+
obj = {},
|
187
|
+
ele = {},
|
188
|
+
s = {};
|
189
|
+
obj = this.container.find('select,input');
|
190
|
+
if (obj.length) {
|
191
|
+
obj.each(function () {
|
192
|
+
ele = $(this);
|
193
|
+
result.push(ele.attr('name') + '=' + ele.val());
|
194
|
+
});
|
195
|
+
} else {
|
196
|
+
$(this).children().each(function () {
|
197
|
+
s = $(this);
|
198
|
+
result.push(s.attr('name') + '=' + s.val());
|
199
|
+
});
|
571
200
|
}
|
572
|
-
|
573
|
-
|
574
|
-
|
575
|
-
|
576
|
-
|
577
|
-
|
578
|
-
|
579
|
-
|
580
|
-
|
581
|
-
|
582
|
-
*/
|
583
|
-
bindings: function() {
|
584
|
-
|
585
|
-
var self = this,
|
586
|
-
opts = self.options,
|
587
|
-
wrap = self.wrap,
|
588
|
-
dz = '',
|
589
|
-
dc = '',
|
590
|
-
dd = '';
|
591
|
-
|
592
|
-
// county
|
593
|
-
wrap.county.on('change', function() {
|
594
|
-
var val = $(this).val(),
|
595
|
-
district = {},
|
596
|
-
tpl = [];
|
597
|
-
|
598
|
-
wrap.district.empty();
|
599
|
-
|
600
|
-
if (val) {
|
601
|
-
if (true === opts.zipcodeIntoDistrict) {
|
602
|
-
for (district in data[val]) {
|
603
|
-
if (_hasOwnProperty(data[val], district)) {
|
604
|
-
tpl.push('<option value="' + district + '">');
|
605
|
-
tpl.push(data[val][district] + ' ' + district);
|
606
|
-
tpl.push('</option>');
|
607
|
-
}
|
201
|
+
return result.join('&');
|
202
|
+
},
|
203
|
+
/**
|
204
|
+
* Method: Destroy the container.
|
205
|
+
* @this {TWzipcode}
|
206
|
+
*/
|
207
|
+
destroy: function () {
|
208
|
+
$.data(this.container.get(0), 'twzipcode', null);
|
209
|
+
if (this.container.length) {
|
210
|
+
return this.container.empty().off('change.twzipcode keyup.twzipcode blur.twzipcode');
|
608
211
|
}
|
609
|
-
|
610
|
-
|
611
|
-
|
612
|
-
|
613
|
-
|
614
|
-
|
615
|
-
|
212
|
+
},
|
213
|
+
/**
|
214
|
+
* Method: Get elements of instance
|
215
|
+
* @param {(string|Array)} opts Type name
|
216
|
+
* @param {Function} callback Function callback
|
217
|
+
*/
|
218
|
+
get: function (callback) {
|
219
|
+
if ('function' === typeof callback) {
|
220
|
+
callback.call(this, this.wrap);
|
221
|
+
} else {
|
222
|
+
return this.wrap;
|
616
223
|
}
|
617
|
-
|
618
|
-
|
619
|
-
|
620
|
-
|
621
|
-
|
622
|
-
|
623
|
-
|
624
|
-
|
625
|
-
|
626
|
-
|
627
|
-
|
628
|
-
|
629
|
-
|
630
|
-
|
631
|
-
|
632
|
-
|
633
|
-
|
634
|
-
|
635
|
-
|
636
|
-
|
637
|
-
|
638
|
-
|
639
|
-
|
640
|
-
|
641
|
-
|
642
|
-
|
643
|
-
|
644
|
-
|
645
|
-
obj.val(obj.val().replace(/[^0-9]/g, ''));
|
646
|
-
val = obj.val().toString();
|
647
|
-
|
648
|
-
if (3 === val.length) {
|
649
|
-
for (i in data) {
|
650
|
-
if (_hasOwnProperty(data, i)) {
|
651
|
-
for (j in data[i]) {
|
652
|
-
if (_hasOwnProperty(data[i], j)) {
|
653
|
-
if (val === data[i][j]) {
|
654
|
-
wrap.county.val(i).trigger('change');
|
655
|
-
wrap.district.val(j).trigger('change');
|
656
|
-
break;
|
657
|
-
}
|
224
|
+
},
|
225
|
+
/**
|
226
|
+
* Method: Set value for elements.
|
227
|
+
* @param {(string|number|Object)} opts Input value
|
228
|
+
*/
|
229
|
+
set: function (opts) {
|
230
|
+
|
231
|
+
var self = this,
|
232
|
+
def = {
|
233
|
+
'county': '',
|
234
|
+
'district': '',
|
235
|
+
'zipcode': ''
|
236
|
+
},
|
237
|
+
opt = $.extend({}, def, opts);
|
238
|
+
|
239
|
+
try {
|
240
|
+
if ('string' === typeof opts || 'number' === typeof opts) {
|
241
|
+
self.wrap.zipcode.val(opts).trigger('blur.twzipcode');
|
242
|
+
} else {
|
243
|
+
if (opt.zipcode) {
|
244
|
+
self.wrap.zipcode.val(opt.zipcode).trigger('blur.twzipcode');
|
245
|
+
}
|
246
|
+
if (opt.county) {
|
247
|
+
self.wrap.county.val(opt.county).trigger('change.twzipcode');
|
248
|
+
}
|
249
|
+
if (opt.district) {
|
250
|
+
self.wrap.district.val(opt.district).trigger('change.twzipcode');
|
251
|
+
}
|
658
252
|
}
|
659
|
-
|
253
|
+
} catch (ignore) {
|
254
|
+
console.warn(ignore.message);
|
255
|
+
} finally {
|
256
|
+
return self.container;
|
660
257
|
}
|
661
|
-
}
|
662
|
-
}
|
663
|
-
// Zipcode callback binding
|
664
|
-
if ('function' === typeof opts.onZipcodeKeyUp) {
|
665
|
-
opts.onZipcodeKeyUp.call(this, wrap.zipcode);
|
666
|
-
}
|
667
|
-
});
|
668
|
-
|
669
|
-
dz = opts.zipcodeSel ?
|
670
|
-
opts.zipcodeSel :
|
671
|
-
(
|
672
|
-
undefined !== self.role.zipcode.data('value') ?
|
673
|
-
self.role.zipcode.data('value') :
|
674
|
-
opts.zipcodeSel
|
675
|
-
);
|
676
|
-
|
677
|
-
dc = opts.countySel ?
|
678
|
-
opts.countySel :
|
679
|
-
(
|
680
|
-
undefined !== self.role.county.data('value') ?
|
681
|
-
self.role.county.data('value') :
|
682
|
-
opts.countySel
|
683
|
-
);
|
684
|
-
|
685
|
-
dd = opts.districtSel ?
|
686
|
-
opts.districtSel :
|
687
|
-
(
|
688
|
-
undefined !== self.role.district.data('value') ?
|
689
|
-
self.role.district.data('value') :
|
690
|
-
opts.districtSel
|
691
|
-
);
|
692
|
-
|
693
|
-
// Default value
|
694
|
-
if (dc) {
|
695
|
-
self.wrap.county.val(dc).trigger('change');
|
696
|
-
if (_hasOwnProperty(data[dc], dd)) {
|
697
|
-
self.wrap.district.val(dd).trigger('change');
|
698
|
-
}
|
699
|
-
}
|
700
|
-
if (dz && 3 === dz.toString().length) {
|
701
|
-
self.wrap.zipcode.val(dz).trigger('blur');
|
702
|
-
}
|
703
|
-
},
|
704
|
-
|
705
|
-
/**
|
706
|
-
* Geolocation detect
|
707
|
-
* @this {twzipcode}
|
708
|
-
*/
|
709
|
-
geoLocation: function() {
|
710
|
-
var self = this,
|
711
|
-
geolocation = navigator.geolocation,
|
712
|
-
options = {
|
713
|
-
'maximumAge': 600000,
|
714
|
-
'timeout': 3000,
|
715
|
-
'enableHighAccuracy': false
|
716
258
|
},
|
717
|
-
|
718
|
-
|
719
|
-
|
720
|
-
|
721
|
-
|
722
|
-
|
723
|
-
|
724
|
-
|
725
|
-
|
726
|
-
|
727
|
-
|
728
|
-
|
729
|
-
|
730
|
-
|
731
|
-
|
732
|
-
|
733
|
-
|
734
|
-
|
735
|
-
|
736
|
-
|
737
|
-
|
738
|
-
|
739
|
-
|
740
|
-
|
741
|
-
|
742
|
-
undefined !== data.results[0].address_components[0]
|
743
|
-
) {
|
744
|
-
postal = data.results[0]
|
745
|
-
.address_components[data.results[0].address_components.length - 1]
|
746
|
-
.long_name;
|
747
|
-
if (postal) {
|
748
|
-
self.wrap.zipcode.val(postal.toString()).trigger('blur');
|
749
|
-
}
|
259
|
+
/**
|
260
|
+
* Method: Reset the selected items to default.
|
261
|
+
* @this {TWzipcode}
|
262
|
+
*/
|
263
|
+
reset: function (container, obj) {
|
264
|
+
var self = this,
|
265
|
+
wrap = self.wrap,
|
266
|
+
county = '',
|
267
|
+
list = {
|
268
|
+
'county': '<option value="">縣市</option>',
|
269
|
+
'district': '<option value="">鄉鎮市區</option>'
|
270
|
+
},
|
271
|
+
tpl = [];
|
272
|
+
|
273
|
+
switch (obj) {
|
274
|
+
case 'district':
|
275
|
+
wrap.district.html(list.district);
|
276
|
+
break;
|
277
|
+
default:
|
278
|
+
wrap.county.html(list.county);
|
279
|
+
wrap.district.html(list.district);
|
280
|
+
for (county in data) {
|
281
|
+
if ('undefined' !== typeof data[county]) {
|
282
|
+
tpl.push('<option value="' + county + '">' + county + '</option>');
|
283
|
+
}
|
750
284
|
}
|
751
|
-
|
752
|
-
|
285
|
+
$(tpl.join('')).appendTo(wrap.county);
|
286
|
+
break;
|
287
|
+
}
|
288
|
+
wrap.zipcode.val('');
|
753
289
|
},
|
754
|
-
|
755
|
-
|
290
|
+
/**
|
291
|
+
* Binding the event of the elements
|
292
|
+
* @this {TWzipcode}
|
293
|
+
*/
|
294
|
+
bindings: function () {
|
295
|
+
|
296
|
+
var self = this,
|
297
|
+
opts = self.options,
|
298
|
+
wrap = self.wrap,
|
299
|
+
dz = '',
|
300
|
+
dc = '',
|
301
|
+
dd = '';
|
302
|
+
|
303
|
+
// county
|
304
|
+
wrap.county.on('change.twzipcode', function () {
|
305
|
+
var val = $(this).val(),
|
306
|
+
district = '',
|
307
|
+
tpl = [];
|
308
|
+
|
309
|
+
wrap.district.empty();
|
310
|
+
|
311
|
+
if (val) {
|
312
|
+
if (true === opts.zipcodeIntoDistrict) {
|
313
|
+
for (district in data[val]) {
|
314
|
+
if ('undefined' !== typeof data[val][district]) {
|
315
|
+
tpl.push('<option value="' + district + '">');
|
316
|
+
tpl.push(data[val][district] + ' ' + district);
|
317
|
+
tpl.push('</option>');
|
318
|
+
}
|
319
|
+
}
|
320
|
+
} else {
|
321
|
+
for (district in data[val]) {
|
322
|
+
if ('undefined' !== typeof data[val][district]) {
|
323
|
+
tpl.push('<option value="' + district + '">');
|
324
|
+
tpl.push(district);
|
325
|
+
tpl.push('</option>');
|
326
|
+
}
|
327
|
+
}
|
328
|
+
}
|
329
|
+
wrap.district.append(tpl.join('')).trigger('change.twzipcode');
|
330
|
+
} else {
|
331
|
+
wrap.county.find('option:first').prop('selected', true);
|
332
|
+
self.reset('district');
|
333
|
+
}
|
334
|
+
// County callback binding
|
335
|
+
if ('function' === typeof opts.onCountySelect) {
|
336
|
+
opts.onCountySelect.call(this);
|
337
|
+
}
|
338
|
+
});
|
339
|
+
// District
|
340
|
+
wrap.district.on('change.twzipcode', function () {
|
341
|
+
var val = $(this).val();
|
342
|
+
if (wrap.county.val()) {
|
343
|
+
wrap.zipcode.val(data[wrap.county.val()][val]);
|
344
|
+
}
|
345
|
+
// District callback binding
|
346
|
+
if ('function' === typeof opts.onDistrictSelect) {
|
347
|
+
opts.onDistrictSelect.call(this);
|
348
|
+
}
|
349
|
+
});
|
350
|
+
// Zipcode
|
351
|
+
wrap.zipcode.on('keyup.twzipcode blur.twzipcode', function () {
|
352
|
+
|
353
|
+
var obj = $(this),
|
354
|
+
val = '',
|
355
|
+
i = '',
|
356
|
+
j = '';
|
357
|
+
obj.val(obj.val().replace(/[^0-9]/g, ''));
|
358
|
+
val = obj.val().toString();
|
359
|
+
|
360
|
+
if (3 === val.length) {
|
361
|
+
for (i in data) {
|
362
|
+
if ('undefined' !== typeof data[i]) {
|
363
|
+
for (j in data[i]) {
|
364
|
+
if ('undefined' !== typeof data[i][j] &&
|
365
|
+
val === data[i][j]
|
366
|
+
) {
|
367
|
+
wrap.county.val(i).trigger('change.twzipcode');
|
368
|
+
wrap.district.val(j).trigger('change.twzipcode');
|
369
|
+
break;
|
370
|
+
}
|
371
|
+
}
|
372
|
+
}
|
373
|
+
}
|
374
|
+
}
|
375
|
+
// Zipcode callback binding
|
376
|
+
if ('function' === typeof opts.onZipcodeKeyUp) {
|
377
|
+
opts.onZipcodeKeyUp.call(this);
|
378
|
+
}
|
379
|
+
});
|
380
|
+
|
381
|
+
dz = 'undefined' !== typeof opts.zipcodeSel ?
|
382
|
+
opts.zipcodeSel :
|
383
|
+
(
|
384
|
+
'undefined' !== typeof self.role.zipcode.data('value') ?
|
385
|
+
self.role.zipcode.data('value') :
|
386
|
+
opts.zipcodeSel
|
387
|
+
);
|
388
|
+
|
389
|
+
dc = 'undefined' !== typeof opts.countySel ?
|
390
|
+
opts.countySel :
|
391
|
+
(
|
392
|
+
'undefined' !== typeof self.role.county.data('value') ?
|
393
|
+
self.role.county.data('value') :
|
394
|
+
opts.countySel
|
395
|
+
);
|
396
|
+
|
397
|
+
dd = 'undefined' !== typeof opts.districtSel ?
|
398
|
+
opts.districtSel :
|
399
|
+
(
|
400
|
+
'undefined' !== typeof self.role.district.data('value') ?
|
401
|
+
self.role.district.data('value') :
|
402
|
+
opts.districtSel
|
403
|
+
);
|
404
|
+
|
405
|
+
// Default value
|
406
|
+
if (dc) {
|
407
|
+
self.wrap.county.val(dc).trigger('change.twzipcode');
|
408
|
+
if ('undefined' !== typeof data[dc][dd]) {
|
409
|
+
self.wrap.district.val(dd).trigger('change.twzipcode');
|
410
|
+
}
|
411
|
+
}
|
412
|
+
if (dz && 3 === dz.toString().length) {
|
413
|
+
self.wrap.zipcode.val(dz).trigger('blur.twzipcode');
|
414
|
+
}
|
756
415
|
},
|
757
|
-
|
758
|
-
|
759
|
-
|
760
|
-
|
761
|
-
|
762
|
-
|
763
|
-
|
764
|
-
|
765
|
-
|
416
|
+
/**
|
417
|
+
* Geolocation detect
|
418
|
+
* @this {TWzipcode}
|
419
|
+
*/
|
420
|
+
geoLocation: function () {
|
421
|
+
|
422
|
+
var self = this,
|
423
|
+
geolocation = navigator.geolocation,
|
424
|
+
options = {
|
425
|
+
'maximumAge': 600000,
|
426
|
+
'timeout': 3000,
|
427
|
+
'enableHighAccuracy': false
|
428
|
+
},
|
429
|
+
opts = self.options;
|
430
|
+
|
431
|
+
if (!geolocation) {
|
432
|
+
return;
|
433
|
+
}
|
766
434
|
|
767
|
-
|
768
|
-
|
769
|
-
|
770
|
-
|
771
|
-
|
772
|
-
|
773
|
-
|
435
|
+
geolocation.getCurrentPosition(
|
436
|
+
function (loc) {
|
437
|
+
|
438
|
+
var latlng = {};
|
439
|
+
if (('coords' in loc) &&
|
440
|
+
('latitude' in loc.coords) &&
|
441
|
+
('longitude' in loc.coords)
|
442
|
+
) {
|
443
|
+
latlng = [loc.coords.latitude, loc.coords.longitude];
|
444
|
+
$.getJSON(
|
445
|
+
'https://maps.googleapis.com/maps/api/geocode/json',
|
446
|
+
{
|
447
|
+
'key': opts.googleMapsKey,
|
448
|
+
'sensor': false,
|
449
|
+
'latlng': latlng.join(',')
|
450
|
+
},
|
451
|
+
function (data) {
|
452
|
+
var postal = '';
|
453
|
+
if (data &&
|
454
|
+
'undefined' !== typeof data.results &&
|
455
|
+
'undefined' !== typeof data.results[0].address_components &&
|
456
|
+
'undefined' !== typeof data.results[0].address_components[0]
|
457
|
+
) {
|
458
|
+
postal = data.results[0]
|
459
|
+
.address_components[data.results[0].address_components.length - 1]
|
460
|
+
.long_name;
|
461
|
+
if (postal) {
|
462
|
+
self.wrap.zipcode.val(postal.toString()).trigger('blur.twzipcode');
|
463
|
+
}
|
464
|
+
}
|
465
|
+
});
|
466
|
+
}
|
467
|
+
},
|
468
|
+
function (error) {
|
469
|
+
console.error(error);
|
470
|
+
},
|
471
|
+
options
|
472
|
+
);
|
774
473
|
},
|
775
|
-
|
776
|
-
|
777
|
-
|
778
|
-
|
779
|
-
|
780
|
-
|
781
|
-
|
782
|
-
|
783
|
-
|
784
|
-
|
785
|
-
|
786
|
-
|
787
|
-
|
788
|
-
|
789
|
-
|
790
|
-
|
791
|
-
|
792
|
-
|
793
|
-
|
794
|
-
|
795
|
-
|
796
|
-
|
797
|
-
|
798
|
-
|
799
|
-
|
800
|
-
|
801
|
-
|
802
|
-
|
803
|
-
|
804
|
-
|
805
|
-
|
806
|
-
|
807
|
-
|
808
|
-
|
809
|
-
|
810
|
-
|
811
|
-
|
812
|
-
|
813
|
-
|
814
|
-
|
815
|
-
|
816
|
-
|
817
|
-
|
818
|
-
|
819
|
-
|
820
|
-
|
474
|
+
/**
|
475
|
+
* twzipcode Initialize
|
476
|
+
* @this {TWzipcode}
|
477
|
+
*/
|
478
|
+
init: function () {
|
479
|
+
|
480
|
+
var self = this,
|
481
|
+
container = self.container,
|
482
|
+
opts = self.options,
|
483
|
+
role = {
|
484
|
+
county: container.find('[data-role=county]:first'),
|
485
|
+
district: container.find('[data-role=district]:first'),
|
486
|
+
zipcode: container.find('[data-role=zipcode]:first')
|
487
|
+
},
|
488
|
+
countyName = role.county.data('name') || opts.countyName,
|
489
|
+
districtName = role.district.data('name') || opts.districtName,
|
490
|
+
zipcodeName = role.zipcode.data('name') || opts.zipcodeName,
|
491
|
+
zipcodePlaceholder = role.zipcode.data('placeholder') || opts.zipcodePlaceholder,
|
492
|
+
readonly = role.zipcode.data('readonly') || opts.readonly;
|
493
|
+
|
494
|
+
// Elements create
|
495
|
+
$('<select/>')
|
496
|
+
.attr('name', countyName)
|
497
|
+
.addClass(role.county.data('style') || ('undefined' !== typeof opts.css[0] ? opts.css[0] : ''))
|
498
|
+
.appendTo(role.county.length ? role.county : container);
|
499
|
+
|
500
|
+
$('<select/>')
|
501
|
+
.attr('name', districtName)
|
502
|
+
.addClass(role.district.data('style') || ('undefined' !== typeof opts.css[1] ? opts.css[1] : ''))
|
503
|
+
.appendTo(role.district.length ? role.district : container);
|
504
|
+
|
505
|
+
$('<input/>')
|
506
|
+
.attr({'type': 'text', 'name': zipcodeName, 'placeholder': zipcodePlaceholder})
|
507
|
+
.prop('readonly', readonly)
|
508
|
+
.addClass(role.zipcode.data('style') || ('undefined' !== typeof opts.css[2] ? opts.css[2] : ''))
|
509
|
+
.appendTo(role.zipcode.length ? role.zipcode : container);
|
510
|
+
|
511
|
+
self.wrap = {
|
512
|
+
'county': container.find('select[name="' + countyName + '"]:first'),
|
513
|
+
'district': container.find('select[name="' + districtName + '"]:first'),
|
514
|
+
'zipcode': container.find('input[type=text][name="' + zipcodeName + '"]:first')
|
515
|
+
};
|
516
|
+
|
517
|
+
if (true === opts.zipcodeIntoDistrict) {
|
518
|
+
self.wrap.zipcode.hide();
|
519
|
+
}
|
821
520
|
|
822
|
-
|
823
|
-
|
824
|
-
|
825
|
-
|
826
|
-
|
827
|
-
|
828
|
-
|
829
|
-
|
830
|
-
case 'data':
|
831
|
-
case 'destroy':
|
832
|
-
case 'reset':
|
833
|
-
case 'serialize':
|
834
|
-
var result = {},
|
835
|
-
instance = {};
|
836
|
-
this.each(function() {
|
837
|
-
instance = $.data(this, 'twzipcode');
|
838
|
-
if (instance instanceof TWzipcode && 'function' === typeof instance[options]) {
|
839
|
-
result = instance[options].apply(instance, Array.prototype.slice.call(arguments, 1));
|
521
|
+
self.role = role;
|
522
|
+
// Reset the elements
|
523
|
+
self.reset();
|
524
|
+
// Elements events binding
|
525
|
+
self.bindings();
|
526
|
+
// Geolocation
|
527
|
+
if (true === opts.detect) {
|
528
|
+
self.geoLocation();
|
840
529
|
}
|
841
|
-
});
|
842
|
-
break;
|
843
|
-
}
|
844
|
-
return undefined !== result ? result : this;
|
845
|
-
} else {
|
846
|
-
return this.each(function() {
|
847
|
-
if (!$.data(this, 'twzipcode')) {
|
848
|
-
$.data(this, 'twzipcode', new TWzipcode(this, options));
|
849
530
|
}
|
850
|
-
|
851
|
-
|
852
|
-
|
531
|
+
};
|
532
|
+
/**
|
533
|
+
* jQuery twzipcode instance
|
534
|
+
* @param {Object} options Plugin settings
|
535
|
+
* @public
|
536
|
+
*/
|
537
|
+
$.fn.twzipcode = function (options) {
|
538
|
+
var instance = {},
|
539
|
+
result = [],
|
540
|
+
args = arguments,
|
541
|
+
id = 'twzipcode';
|
542
|
+
if ('string' === typeof options) {
|
543
|
+
this.each(function () {
|
544
|
+
instance = $.data(this, id);
|
545
|
+
if (instance instanceof TWzipcode && 'function' === typeof instance[options]) {
|
546
|
+
result = instance[options].apply(instance, Array.prototype.slice.call(args, 1));
|
547
|
+
}
|
548
|
+
});
|
549
|
+
return 'undefined' !== typeof result ? result : this;
|
550
|
+
} else {
|
551
|
+
return this.each(function () {
|
552
|
+
if (!$.data(this, id)) {
|
553
|
+
$.data(this, id, new TWzipcode(this, options));
|
554
|
+
}
|
555
|
+
});
|
556
|
+
}
|
557
|
+
};
|
853
558
|
|
854
|
-
}(jQuery, window)
|
559
|
+
})(window.jQuery || {}, window, document);
|
560
|
+
//#EOF
|