forked from earthchie/jquery.Thailand.js
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.html
executable file
·192 lines (158 loc) · 8.71 KB
/
index.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
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
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
<!DOCTYPE html>
<html lang="th">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>jquery.Thailand.js</title>
<link rel="stylesheet" href="https://fonts.googleapis.com/css?family=Kanit">
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/uikit/3.0.0-beta.20/css/uikit.css">
<link rel="stylesheet" href="./jquery.Thailand.js/dist/jquery.Thailand.min.css">
<style>
a, h1, h2, .h2{
font-family: 'Kanit', sans-serif !important;
line-height: 1.6em;
}
a{
font-size: 1.4em;
}
label{
font-size: 1.6em;
display: block;
}
</style>
<script>
(function (i, s, o, g, r, a, m) {
i['GoogleAnalyticsObject'] = r;
i[r] = i[r] || function () {
(i[r].q = i[r].q || []).push(arguments)
}, i[r].l = 1 * new Date();
a = s.createElement(o), m = s.getElementsByTagName(o)[0];
a.async = 1;
a.src = g;
m.parentNode.insertBefore(a, m)
})(window, document, 'script', 'https://www.google-analytics.com/analytics.js', 'ga');
ga('create', 'UA-33058582-1', 'auto', {
'name': 'Main'
});
ga('Main.send', 'event', 'jquery.Thailand.js', 'GitHub', 'Visit');
</script>
</head>
<body>
<div class="uk-container uk-padding">
<!-- DEMO 1 -->
<h1>Auto Complete ที่อยู่ อย่างที่มันควรเป็น</h1>
<div id="loader">
<div uk-spinner></div> รอสักครู่ กำลังโหลดฐานข้อมูล...
</div>
<form id="demo1" class="demo" style="display:none;" autocomplete="off" uk-grid >
<div class="uk-width-1-2@m">
<label class="h2">ตำบล / แขวง</label>
<input name="district" class="uk-input uk-width-1-1" type="text">
</div>
<div class="uk-width-1-2@m">
<label class="h2">อำเภอ / เขต</label>
<input name="amphoe" class="uk-input uk-width-1-1" type="text">
</div>
<div class="uk-width-1-2@m">
<label class="h2">จังหวัด</label>
<input name="province" class="uk-input uk-width-1-1" type="text">
</div>
<div class="uk-width-1-2@m">
<label class="h2">รหัสไปรษณีย์</label>
<input name="zipcode" class="uk-input uk-width-1-1" type="text">
</div>
</form>
<!-- END DEMO 1 -->
<!-- DEMO 2 -->
<hr>
<h2>ใหม่! โหมดค้นหา</h2>
<form id="demo2" class="demo" style="display:none;" autocomplete="off">
<label class="h2">ค้นหาที่อยู่ของคุณ</label>
<small>ลองกรอกอย่างใดอย่างหนึ่ง ตำบล, อำเภอ, จังหวัด หรือ รหัสไปรษณีย์</small>
<input name="search" class="uk-input uk-width-1-1" type="text">
<div id="demo2-output" class="uk-margin"></div>
</form>
<!-- END DEMO 2 -->
<div uk-grid>
<div class="uk-width-1-2@m">
<a href="https://medium.com/@earthchie/ระบบ-auto-complete-ที่อยู่ไทย-อย่างที่มันควรเป็น-27360185d86a" target="_blank">
<span class="svgIcon svgIcon--logoNew svgIcon--45px is-flushLeft">
<svg class="svgIcon-use" width="45" height="45" viewBox="-17 18 45 45" data-multipart="true">
<path fill="#d0d2d3" d="M11.525 28.078c-.472-.225-.858.002-.858.506v20.044l8.616 4.113c.948.46 1.717.14 1.717-.7v-19.3a.22.22 0 0 0-.124-.19l-9.35-4.46v-.01z"></path>
<path fill="#a6a8ab" d="M.333 43.696l9.83-15.247c.278-.43.89-.6 1.36-.38l9.364 4.47c.06.03.082.1.047.15L10.666 48.63.333 43.698v-.002z"></path>
<path fill="#808184" d="M-8.57 28.35c-.786-.375-1.053-.096-.592.62L.333 43.696l10.333 4.932L.356 32.635a.156.156 0 0 0-.06-.054l-8.866-4.23z"></path>
<path fill="#58595b" d="M.333 52.033c0 .84-.643 1.22-1.43.844l-8.045-3.84c-.472-.224-.858-.82-.858-1.325V28.89c0-.672.515-.976 1.145-.675l9.133 4.36a.092.092 0 0 1 .055.084v19.37z"></path>
</svg>
</span>
อ่านแนวคิด
</a>
</div>
<div class="uk-width-1-2@m uk-text-right">
<a href="https://github.com/earthchie/jquery.Thailand.js" target="_blank">
<svg aria-hidden="true" class="octicon octicon-mark-github" height="32" version="1.1" viewBox="0 0 16 16" width="32">
<path fill-rule="evenodd" d="M8 0C3.58 0 0 3.58 0 8c0 3.54 2.29 6.53 5.47 7.59.4.07.55-.17.55-.38 0-.19-.01-.82-.01-1.49-2.01.37-2.53-.49-2.69-.94-.09-.23-.48-.94-.82-1.13-.28-.15-.68-.52-.01-.53.63-.01 1.08.58 1.23.82.72 1.21 1.87.87 2.33.66.07-.52.28-.87.51-1.07-1.78-.2-3.64-.89-3.64-3.95 0-.87.31-1.59.82-2.15-.08-.2-.36-1.02.08-2.12 0 0 .67-.21 2.2.82.64-.18 1.32-.27 2-.27.68 0 1.36.09 2 .27 1.53-1.04 2.2-.82 2.2-.82.44 1.1.16 1.92.08 2.12.51.56.82 1.27.82 2.15 0 3.07-1.87 3.75-3.65 3.95.29.25.54.73.54 1.48 0 1.07-.01 1.93-.01 2.2 0 .21.15.46.55.38A8.013 8.013 0 0 0 16 8c0-4.42-3.58-8-8-8z"></path>
</svg>
Fork me on GitHub
</a>
</div>
</div>
</div>
<script type="text/javascript" src="https://code.jquery.com/jquery-3.2.1.min.js" integrity="sha256-hwg4gsxgFZhOsEEamdOYGBf13FyQuiTwlAQgxVSNgt4=" crossorigin="anonymous"></script>
<script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/uikit/3.0.0-beta.20/js/uikit.min.js"></script>
<!-- dependencies for zip mode -->
<script type="text/javascript" src="./jquery.Thailand.js/dependencies/zip.js/zip.js"></script>
<!-- / dependencies for zip mode -->
<script type="text/javascript" src="./jquery.Thailand.js/dependencies/JQL.min.js"></script>
<script type="text/javascript" src="./jquery.Thailand.js/dependencies/typeahead.bundle.js"></script>
<script type="text/javascript" src="./jquery.Thailand.js/dist/jquery.Thailand.min.js"></script>
<script type="text/javascript">
/******************\
* DEMO 1 *
\******************/
// demo 1: load database from json. if your server is support gzip. we recommended to use this rather than zip.
// for more info check README.md
$.Thailand({
database: './jquery.Thailand.js/database/db.json',
$district: $('#demo1 [name="district"]'),
$amphoe: $('#demo1 [name="amphoe"]'),
$province: $('#demo1 [name="province"]'),
$zipcode: $('#demo1 [name="zipcode"]'),
onDataFill: function(data){
console.info('Data Filled', data);
},
onLoad: function(){
console.info('Autocomplete is ready!');
$('#loader, .demo').toggle();
}
});
// watch on change
$('#demo1 [name="district"]').change(function(){
console.log('ตำบล', this.value);
});
$('#demo1 [name="amphoe"]').change(function(){
console.log('อำเภอ', this.value);
});
$('#demo1 [name="province"]').change(function(){
console.log('จังหวัด', this.value);
});
$('#demo1 [name="zipcode"]').change(function(){
console.log('รหัสไปรษณีย์', this.value);
});
/******************\
* DEMO 2 *
\******************/
// demo 2: load database from zip. for those who doesn't have server that supported gzip.
// for more info check README.md
$.Thailand({
database: './jquery.Thailand.js/database/db.zip',
$search: $('#demo2 [name="search"]'),
onDataFill: function(data){
console.log(data)
var html = '<b>ที่อยู่:</b> ตำบล' + data.district + ' อำเภอ' + data.amphoe + ' จังหวัด' + data.province + ' ' + data.zipcode;
$('#demo2-output').prepend('<div class="uk-alert-warning" uk-alert><a class="uk-alert-close" uk-close></a>' + html + '</div>');
}
});
</script>
</body>
</html>