tw_zipcode 1.5.2 → 1.7.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +49 -40
- data/lib/tw_zipcode/version.rb +1 -1
- data/tw_zipcode.gemspec +1 -1
- data/vendor/assets/javascripts/tw_zipcode.js +838 -350
- data/vendor/assets/javascripts/tw_zipcode.min.js +32 -1
- metadata +13 -13
@@ -1,366 +1,854 @@
|
|
1
|
+
/*jshint unused:false */
|
1
2
|
/**
|
2
|
-
*
|
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
|
-
* 輕鬆地建立多組台灣郵遞區號下拉清單,讀取快速、完全不需使用資料庫。
|
3
|
+
* jQuery TWzipcode plugin
|
10
4
|
* http://app.essoduke.org/twzipcode/
|
5
|
+
* Copyright 2015 essoduke.org, Licensed MIT.
|
11
6
|
*
|
12
|
-
*
|
13
|
-
*
|
7
|
+
* Changelog
|
8
|
+
* -------------------------------
|
9
|
+
* 因應員林鎮改制為員林市、頭份鎮改制為頭份市。
|
14
10
|
*
|
15
|
-
*
|
16
|
-
*
|
17
|
-
*
|
11
|
+
* @author essoduke.org
|
12
|
+
* @version 1.7.1
|
13
|
+
* @license MIT License
|
14
|
+
* Last modified: 2015-08-12 16:22:13+08:00
|
18
15
|
*/
|
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
|
-
|
124
|
-
|
125
|
-
|
16
|
+
;
|
17
|
+
(function($, window, undefined) {
|
18
|
+
|
19
|
+
'use strict';
|
20
|
+
|
21
|
+
// Zipcode JSON data
|
22
|
+
var data = {
|
23
|
+
'基隆市': {
|
24
|
+
'仁愛區': '200',
|
25
|
+
'信義區': '201',
|
26
|
+
'中正區': '202',
|
27
|
+
'中山區': '203',
|
28
|
+
'安樂區': '204',
|
29
|
+
'暖暖區': '205',
|
30
|
+
'七堵區': '206'
|
31
|
+
},
|
32
|
+
'台北市': {
|
33
|
+
'中正區': '100',
|
34
|
+
'大同區': '103',
|
35
|
+
'中山區': '104',
|
36
|
+
'松山區': '105',
|
37
|
+
'大安區': '106',
|
38
|
+
'萬華區': '108',
|
39
|
+
'信義區': '110',
|
40
|
+
'士林區': '111',
|
41
|
+
'北投區': '112',
|
42
|
+
'內湖區': '114',
|
43
|
+
'南港區': '115',
|
44
|
+
'文山區': '116'
|
45
|
+
},
|
46
|
+
'新北市': {
|
47
|
+
'萬里區': '207',
|
48
|
+
'金山區': '208',
|
49
|
+
'板橋區': '220',
|
50
|
+
'汐止區': '221',
|
51
|
+
'深坑區': '222',
|
52
|
+
'石碇區': '223',
|
53
|
+
'瑞芳區': '224',
|
54
|
+
'平溪區': '226',
|
55
|
+
'雙溪區': '227',
|
56
|
+
'貢寮區': '228',
|
57
|
+
'新店區': '231',
|
58
|
+
'坪林區': '232',
|
59
|
+
'烏來區': '233',
|
60
|
+
'永和區': '234',
|
61
|
+
'中和區': '235',
|
62
|
+
'土城區': '236',
|
63
|
+
'三峽區': '237',
|
64
|
+
'樹林區': '238',
|
65
|
+
'鶯歌區': '239',
|
66
|
+
'三重區': '241',
|
67
|
+
'新莊區': '242',
|
68
|
+
'泰山區': '243',
|
69
|
+
'林口區': '244',
|
70
|
+
'蘆洲區': '247',
|
71
|
+
'五股區': '248',
|
72
|
+
'八里區': '249',
|
73
|
+
'淡水區': '251',
|
74
|
+
'三芝區': '252',
|
75
|
+
'石門區': '253'
|
76
|
+
},
|
77
|
+
'宜蘭縣': {
|
78
|
+
'宜蘭市': '260',
|
79
|
+
'頭城鎮': '261',
|
80
|
+
'礁溪鄉': '262',
|
81
|
+
'壯圍鄉': '263',
|
82
|
+
'員山鄉': '264',
|
83
|
+
'羅東鎮': '265',
|
84
|
+
'三星鄉': '266',
|
85
|
+
'大同鄉': '267',
|
86
|
+
'五結鄉': '268',
|
87
|
+
'冬山鄉': '269',
|
88
|
+
'蘇澳鎮': '270',
|
89
|
+
'南澳鄉': '272',
|
90
|
+
'釣魚台列嶼': '290'
|
91
|
+
},
|
92
|
+
'新竹市': {
|
93
|
+
'東區': '300',
|
94
|
+
'北區': '300',
|
95
|
+
'香山區': '300'
|
96
|
+
},
|
97
|
+
'新竹縣': {
|
98
|
+
'竹北市': '302',
|
99
|
+
'湖口鄉': '303',
|
100
|
+
'新豐鄉': '304',
|
101
|
+
'新埔鎮': '305',
|
102
|
+
'關西鎮': '306',
|
103
|
+
'芎林鄉': '307',
|
104
|
+
'寶山鄉': '308',
|
105
|
+
'竹東鎮': '310',
|
106
|
+
'五峰鄉': '311',
|
107
|
+
'橫山鄉': '312',
|
108
|
+
'尖石鄉': '313',
|
109
|
+
'北埔鄉': '314',
|
110
|
+
'峨嵋鄉': '315'
|
111
|
+
},
|
112
|
+
'桃園市': {
|
113
|
+
'中壢區': '320',
|
114
|
+
'平鎮區': '324',
|
115
|
+
'龍潭區': '325',
|
116
|
+
'楊梅區': '326',
|
117
|
+
'新屋區': '327',
|
118
|
+
'觀音區': '328',
|
119
|
+
'桃園區': '330',
|
120
|
+
'龜山區': '333',
|
121
|
+
'八德區': '334',
|
122
|
+
'大溪區': '335',
|
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
|
126
482
|
};
|
483
|
+
/**
|
484
|
+
* DOM of selector
|
485
|
+
* @type {Object}
|
486
|
+
*/
|
487
|
+
this.container = $(container);
|
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 = {
|
127
500
|
|
128
|
-
|
129
|
-
var methods = {
|
130
|
-
|
131
|
-
// Initialize
|
132
|
-
init: function (options) {
|
133
|
-
|
134
|
-
return this.each(function () {
|
135
|
-
|
136
|
-
// Default settings
|
137
|
-
var opts = $.extend({
|
138
|
-
detect: false, //v1.4
|
139
|
-
countyName: 'county',
|
140
|
-
districtName: 'district',
|
141
|
-
zipcodeName: 'zipcode',
|
142
|
-
countySel: '',
|
143
|
-
districtSel: '',
|
144
|
-
zipcodeSel: '',
|
145
|
-
readonly: false,
|
146
|
-
onCountySelect: null, //v1.5
|
147
|
-
onDistrictSelect: null, //v1.5
|
148
|
-
onZipcodeKeyUp: null, //v1.5
|
149
|
-
css: []
|
150
|
-
}, options),
|
151
|
-
self = $(this),
|
152
|
-
tpl = [],
|
153
|
-
wrap = {},
|
154
|
-
county = {},
|
155
|
-
opt = ['<option value="">縣市</option>', '<option value="">鄉鎮市區</option>'],
|
156
|
-
// Data property
|
157
|
-
role = {
|
158
|
-
county: self.find('[data-role="county"]:first'),
|
159
|
-
district: self.find('[data-role="district"]:first'),
|
160
|
-
zipcode: self.find('[data-role="zipcode"]:first')
|
161
|
-
};
|
162
|
-
|
163
|
-
// Elements create
|
164
|
-
$('<select/>')
|
165
|
-
.attr({'name': opts.countyName, 'id': opts.countyName})
|
166
|
-
.addClass(role.county.data('style') || (undefined !== opts.css[0] ? opts.css[0] : ''))
|
167
|
-
.appendTo(role.county.length ? role.county : this);
|
168
|
-
|
169
|
-
$('<select/>')
|
170
|
-
.attr({'name': opts.districtName, 'id': opts.districtName})
|
171
|
-
.addClass(role.district.data('style') || (undefined !== opts.css[1] ? opts.css[1] : ''))
|
172
|
-
.appendTo(role.district.length ? role.district : this);
|
173
|
-
|
174
|
-
$('<input/>')
|
175
|
-
.attr({'type': 'text', 'name': opts.zipcodeName, 'id': opts.zipcodeName})
|
176
|
-
.prop('readonly', opts.readonly)
|
177
|
-
.addClass(role.zipcode.data('style') || (undefined !== opts.css[2] ? opts.css[2] : ''))
|
178
|
-
.appendTo(role.zipcode.length ? role.zipcode : this);
|
179
|
-
|
180
|
-
// Elements collection
|
181
|
-
wrap.selector = {
|
182
|
-
county: 'select[name="' + opts.countyName + '"][id="' + opts.countyName + '"]:first',
|
183
|
-
district: 'select[name="' + opts.districtName + '"][id="' + opts.districtName + '"]:first',
|
184
|
-
zipcode: 'input[type=text][name="' + opts.zipcodeName + '"][id="' + opts.zipcodeName + '"]:first'
|
185
|
-
};
|
186
|
-
wrap.county = self.find(wrap.selector.county);
|
187
|
-
wrap.district = self.find(wrap.selector.district);
|
188
|
-
wrap.zipcode = self.find(wrap.selector.zipcode);
|
189
|
-
|
190
|
-
// Fill up the county list
|
191
|
-
$(opt[0]).appendTo(wrap.county);
|
192
|
-
$(opt[1]).appendTo(wrap.district);
|
193
|
-
|
194
|
-
for (county in data) {
|
195
|
-
if (data.hasOwnProperty(county)) {
|
196
|
-
tpl.push('<option value="');
|
197
|
-
tpl.push(county);
|
198
|
-
tpl.push('">');
|
199
|
-
tpl.push(county);
|
200
|
-
tpl.push('</option>');
|
201
|
-
}
|
202
|
-
}
|
501
|
+
VERSION: '1.7.1',
|
203
502
|
|
204
|
-
|
205
|
-
|
206
|
-
|
207
|
-
|
208
|
-
|
209
|
-
|
210
|
-
|
211
|
-
|
212
|
-
|
213
|
-
|
214
|
-
|
215
|
-
|
216
|
-
|
217
|
-
|
218
|
-
|
219
|
-
|
220
|
-
|
221
|
-
|
222
|
-
|
223
|
-
|
224
|
-
|
225
|
-
|
226
|
-
|
227
|
-
|
228
|
-
|
229
|
-
|
230
|
-
|
231
|
-
|
232
|
-
|
233
|
-
|
234
|
-
|
235
|
-
|
236
|
-
|
237
|
-
|
238
|
-
|
239
|
-
|
240
|
-
|
241
|
-
|
242
|
-
|
243
|
-
|
244
|
-
|
245
|
-
|
246
|
-
|
247
|
-
|
248
|
-
|
249
|
-
|
250
|
-
|
251
|
-
|
252
|
-
|
253
|
-
|
254
|
-
|
255
|
-
|
256
|
-
|
257
|
-
|
258
|
-
|
259
|
-
|
260
|
-
|
261
|
-
|
262
|
-
|
263
|
-
|
264
|
-
|
265
|
-
|
266
|
-
|
267
|
-
|
268
|
-
|
269
|
-
|
270
|
-
|
271
|
-
|
272
|
-
|
273
|
-
|
274
|
-
|
275
|
-
|
276
|
-
|
277
|
-
|
278
|
-
|
279
|
-
|
280
|
-
|
281
|
-
|
282
|
-
|
283
|
-
|
284
|
-
|
285
|
-
|
286
|
-
|
287
|
-
|
288
|
-
|
289
|
-
|
290
|
-
|
291
|
-
|
292
|
-
|
293
|
-
|
294
|
-
|
295
|
-
|
296
|
-
|
297
|
-
|
298
|
-
|
299
|
-
|
300
|
-
|
301
|
-
|
302
|
-
|
303
|
-
|
304
|
-
|
305
|
-
|
306
|
-
|
307
|
-
|
308
|
-
|
309
|
-
|
310
|
-
|
311
|
-
|
312
|
-
|
313
|
-
|
314
|
-
|
315
|
-
|
316
|
-
|
317
|
-
|
318
|
-
|
319
|
-
|
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}
|
515
|
+
*/
|
516
|
+
serialize: function() {
|
517
|
+
var result = [],
|
518
|
+
obj = {},
|
519
|
+
ele = {},
|
520
|
+
s = {};
|
521
|
+
obj = this.container.find('select,input');
|
522
|
+
if (obj.length) {
|
523
|
+
obj.each(function() {
|
524
|
+
ele = $(this);
|
525
|
+
result.push(ele.attr('name') + '=' + ele.val());
|
526
|
+
});
|
527
|
+
} else {
|
528
|
+
$(this).children().each(function() {
|
529
|
+
s = $(this);
|
530
|
+
result.push(s.attr('name') + '=' + s.val());
|
531
|
+
});
|
532
|
+
}
|
533
|
+
return result.join('&');
|
534
|
+
},
|
535
|
+
|
536
|
+
/**
|
537
|
+
* Method: Destroy the container.
|
538
|
+
* @this {twzipcode}
|
539
|
+
*/
|
540
|
+
destroy: function() {
|
541
|
+
$.data(this.container.get(0), 'twzipcode', null);
|
542
|
+
if (this.container.length) {
|
543
|
+
return this.container.empty().off('change keyup blur');
|
544
|
+
}
|
545
|
+
},
|
546
|
+
|
547
|
+
/**
|
548
|
+
* Method: Reset the selected items to default.
|
549
|
+
* @this {twzipcode}
|
550
|
+
*/
|
551
|
+
reset: function(container, obj) {
|
552
|
+
var self = this,
|
553
|
+
wrap = self.wrap,
|
554
|
+
county = {},
|
555
|
+
list = {
|
556
|
+
'county': '<option value="">縣市</option>',
|
557
|
+
'district': '<option value="">鄉鎮市區</option>'
|
558
|
+
},
|
559
|
+
tpl = [];
|
560
|
+
|
561
|
+
switch (obj) {
|
562
|
+
case 'district':
|
563
|
+
wrap.district.empty().html(list.district);
|
564
|
+
break;
|
565
|
+
default:
|
566
|
+
wrap.county.empty().html(list.county);
|
567
|
+
wrap.district.empty().html(list.district);
|
568
|
+
for (county in data) {
|
569
|
+
if (_hasOwnProperty(data, county)) {
|
570
|
+
tpl.push('<option value="' + county + '">' + county + '</option>');
|
571
|
+
}
|
572
|
+
}
|
573
|
+
$(tpl.join('')).appendTo(wrap.county);
|
574
|
+
break;
|
575
|
+
}
|
576
|
+
wrap.zipcode.val('');
|
577
|
+
},
|
578
|
+
|
579
|
+
/**
|
580
|
+
* Binding the event of the elements
|
581
|
+
* @this {twzipcode}
|
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
|
+
}
|
608
|
+
}
|
609
|
+
} else {
|
610
|
+
for (district in data[val]) {
|
611
|
+
if (_hasOwnProperty(data[val], district)) {
|
612
|
+
tpl.push('<option value="' + district + '">');
|
613
|
+
tpl.push(district);
|
614
|
+
tpl.push('</option>');
|
615
|
+
}
|
616
|
+
}
|
617
|
+
}
|
618
|
+
wrap.district.append(tpl.join('')).trigger('change');
|
619
|
+
} else {
|
620
|
+
wrap.county.find('option:first').prop('selected', true);
|
621
|
+
self.reset('district');
|
622
|
+
}
|
623
|
+
// County callback binding
|
624
|
+
if ('function' === typeof opts.onCountySelect) {
|
625
|
+
opts.onCountySelect.call(this, wrap.county);
|
626
|
+
}
|
627
|
+
});
|
628
|
+
// District
|
629
|
+
wrap.district.on('change', function() {
|
630
|
+
var val = $(this).val();
|
631
|
+
if (wrap.county.val()) {
|
632
|
+
wrap.zipcode.val(data[wrap.county.val()][val]);
|
633
|
+
}
|
634
|
+
// District callback binding
|
635
|
+
if ('function' === typeof opts.onDistrictSelect) {
|
636
|
+
opts.onDistrictSelect.call(this, wrap.district);
|
637
|
+
}
|
638
|
+
});
|
639
|
+
// Zipcode
|
640
|
+
wrap.zipcode.on('keyup blur', function() {
|
641
|
+
var obj = $(this),
|
642
|
+
val = '',
|
643
|
+
i = '',
|
644
|
+
j = '';
|
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
|
+
}
|
320
658
|
}
|
321
|
-
|
659
|
+
}
|
660
|
+
}
|
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
|
322
716
|
},
|
717
|
+
opts = self.options;
|
323
718
|
|
324
|
-
|
325
|
-
|
326
|
-
|
327
|
-
|
328
|
-
|
329
|
-
|
330
|
-
|
331
|
-
|
719
|
+
if (!geolocation) {
|
720
|
+
return;
|
721
|
+
}
|
722
|
+
|
723
|
+
geolocation.getCurrentPosition(
|
724
|
+
function(loc) {
|
725
|
+
var latlng = {};
|
726
|
+
if (('coords' in loc) &&
|
727
|
+
('latitude' in loc.coords) &&
|
728
|
+
('longitude' in loc.coords)
|
729
|
+
) {
|
730
|
+
latlng = [loc.coords.latitude, loc.coords.longitude];
|
731
|
+
$.getJSON(
|
732
|
+
'https://maps.googleapis.com/maps/api/geocode/json', {
|
733
|
+
'key': opts.googleMapsKey,
|
734
|
+
'sensor': false,
|
735
|
+
'latlng': latlng.join(',')
|
736
|
+
},
|
737
|
+
function(data) {
|
738
|
+
var postal = '';
|
739
|
+
if (data &&
|
740
|
+
_hasOwnProperty(data, 'results') &&
|
741
|
+
_hasOwnProperty(data.results[0], 'address_components') &&
|
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
|
+
}
|
750
|
+
}
|
751
|
+
});
|
752
|
+
}
|
332
753
|
},
|
333
|
-
|
334
|
-
|
335
|
-
return this.each(function () {
|
336
|
-
$(this).find('select:first').children('option:first').prop('selected', true).trigger('change');
|
337
|
-
});
|
754
|
+
function(error) {
|
755
|
+
//console.error(error);
|
338
756
|
},
|
757
|
+
options
|
758
|
+
);
|
759
|
+
},
|
339
760
|
|
340
|
-
|
341
|
-
|
342
|
-
|
343
|
-
|
344
|
-
|
345
|
-
if (sel.length) {
|
346
|
-
sel.each(function () {
|
347
|
-
ele = $(this);
|
348
|
-
result.push(ele.attr('name') + '=' + ele.val());
|
349
|
-
});
|
350
|
-
} else {
|
351
|
-
$(this).children().each(function () {
|
352
|
-
s = $(this);
|
353
|
-
result.push(s.attr('name') + '=' + s.val());
|
354
|
-
});
|
355
|
-
}
|
356
|
-
});
|
357
|
-
return result.join('&');
|
358
|
-
}
|
359
|
-
};
|
761
|
+
/**
|
762
|
+
* twzipcode Initialize
|
763
|
+
* @this {twzipcode}
|
764
|
+
*/
|
765
|
+
init: function() {
|
360
766
|
|
361
|
-
|
362
|
-
|
363
|
-
|
364
|
-
|
767
|
+
var self = this,
|
768
|
+
container = self.container,
|
769
|
+
opts = self.options,
|
770
|
+
role = {
|
771
|
+
county: container.find('[data-role=county]:first'),
|
772
|
+
district: container.find('[data-role=district]:first'),
|
773
|
+
zipcode: container.find('[data-role=zipcode]:first')
|
774
|
+
},
|
775
|
+
countyName = role.county.data('name') || opts.countyName,
|
776
|
+
districtName = role.district.data('name') || opts.districtName,
|
777
|
+
zipcodeName = role.zipcode.data('name') || opts.zipcodeName,
|
778
|
+
readonly = role.zipcode.data('readonly') || opts.readonly;
|
779
|
+
|
780
|
+
// Elements create
|
781
|
+
$('<select/>')
|
782
|
+
.attr('name', countyName)
|
783
|
+
.addClass(role.county.data('style') || (undefined !== opts.css[0] ? opts.css[0] : ''))
|
784
|
+
.appendTo(role.county.length ? role.county : container);
|
785
|
+
|
786
|
+
$('<select/>')
|
787
|
+
.attr('name', districtName)
|
788
|
+
.addClass(role.district.data('style') || (undefined !== opts.css[1] ? opts.css[1] : ''))
|
789
|
+
.appendTo(role.district.length ? role.district : container);
|
790
|
+
|
791
|
+
$('<input/>')
|
792
|
+
.attr({
|
793
|
+
'type': 'text',
|
794
|
+
'name': zipcodeName
|
795
|
+
})
|
796
|
+
.prop('readonly', readonly)
|
797
|
+
.addClass(role.zipcode.data('style') || (undefined !== opts.css[2] ? opts.css[2] : ''))
|
798
|
+
.appendTo(role.zipcode.length ? role.zipcode : container);
|
799
|
+
|
800
|
+
self.wrap = {
|
801
|
+
'county': container.find('select[name="' + countyName + '"]:first'),
|
802
|
+
'district': container.find('select[name="' + districtName + '"]:first'),
|
803
|
+
'zipcode': container.find('input[type=text][name="' + zipcodeName + '"]:first')
|
804
|
+
};
|
805
|
+
|
806
|
+
if (true === opts.zipcodeIntoDistrict) {
|
807
|
+
self.wrap.zipcode.hide();
|
808
|
+
}
|
809
|
+
|
810
|
+
self.role = role;
|
811
|
+
// Reset the elements
|
812
|
+
self.reset();
|
813
|
+
// Elements events binding
|
814
|
+
self.bindings();
|
815
|
+
// Geolocation
|
816
|
+
if (true === opts.detect) {
|
817
|
+
self.geoLocation();
|
818
|
+
}
|
819
|
+
}
|
820
|
+
};
|
821
|
+
|
822
|
+
/**
|
823
|
+
* jQuery twzipcode instance
|
824
|
+
* @param {Object} options Plugin settings
|
825
|
+
* @public
|
826
|
+
*/
|
827
|
+
$.fn.twzipcode = function(options) {
|
828
|
+
if ('string' === typeof options) {
|
829
|
+
switch (options) {
|
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));
|
840
|
+
}
|
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
|
+
}
|
850
|
+
});
|
851
|
+
}
|
852
|
+
};
|
365
853
|
|
366
|
-
}(jQuery));
|
854
|
+
}(jQuery, window));
|