-
Notifications
You must be signed in to change notification settings - Fork 446
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
10 changed files
with
3,214 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,104 @@ | ||
<!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/jquery.Thailand.min.css"> | ||
|
||
<style> | ||
a, h1, h2{ | ||
font-family: 'Kanit', sans-serif !important; | ||
line-height: 1.6em; | ||
} | ||
a{ | ||
font-size: 1.8em; | ||
} | ||
label{ | ||
display: block; | ||
} | ||
</style> | ||
|
||
</head> | ||
<body> | ||
|
||
<div class="uk-container uk-padding"> | ||
|
||
<h1>Auto Complete ที่อยู่ อย่างที่มันควรเป็น</h1> | ||
|
||
<div id="loader"> | ||
<div uk-spinner></div> รอสักครู่ กำลังโหลดฐานข้อมูล... | ||
</div> | ||
|
||
<div id="address" style="display:none;" uk-grid> | ||
|
||
<div class="uk-width-1-2@m"> | ||
<label> | ||
<h2>ตำบล</h2> | ||
<input name="district" class="uk-input uk-width-1-1" type="text"> | ||
</label> | ||
</div> | ||
|
||
<div class="uk-width-1-2@m"> | ||
<label> | ||
<h2>อำเภอ</h2> | ||
<input name="amphoe" class="uk-input uk-width-1-1" type="text"> | ||
</label> | ||
</div> | ||
|
||
<div class="uk-width-1-2@m"> | ||
<label> | ||
<h2>จังหวัด</h2> | ||
<input name="province" class="uk-input uk-width-1-1" type="text"> | ||
</label> | ||
</div> | ||
|
||
<div class="uk-width-1-2@m"> | ||
<label> | ||
<h2>รหัสไปรษีย์</h2> | ||
<input name="zipcode" class="uk-input uk-width-1-1" type="text"> | ||
</label> | ||
</div> | ||
|
||
</div> | ||
|
||
<div uk-grid> | ||
<div class="uk-width-1-2@m"></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> | ||
|
||
<script type="text/javascript" src="jquery.Thailand.js/dependencies/jszip.min.js"></script> | ||
<script type="text/javascript" src="jquery.Thailand.js/dependencies/JQL.min.js"></script> | ||
<script type="text/javascript" src="jquery.Thailand.js/dependencies/jszip-utils.min.js"></script> | ||
<script type="text/javascript" src="jquery.Thailand.js/dependencies/typeahead.bundle.js"></script> | ||
|
||
<script type="text/javascript" src="jquery.Thailand.js/jquery.Thailand.min.js"></script> | ||
|
||
<script type="text/javascript"> | ||
$.Thailand({ | ||
database: 'jquery.Thailand.js/db.zip', | ||
onComplete: function(){ | ||
$('#loader, #address').toggle(); | ||
} | ||
}); | ||
</script> | ||
|
||
</body> | ||
</html> |
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,290 @@ | ||
/** | ||
* @name JQL.js | ||
* @version 1.0.1 | ||
* @update Aug 20, 2016 | ||
* @author Earthchie http://www.earthchie.com/ | ||
* @license WTFPL v.2 - http://www.wtfpl.net/ | ||
**/ | ||
function JQL(obj){ | ||
if(typeof obj === 'string'){ | ||
obj = JSON.parse(obj); | ||
} | ||
this.data_source = obj; | ||
this.buffer = obj; | ||
this.focused_field = ''; | ||
this.options = []; | ||
this.size = false; | ||
|
||
for(var key in obj){ | ||
for(var field in obj[key]){ | ||
this.options.push(field); | ||
} | ||
break; | ||
} | ||
|
||
this.fetch = function(){ | ||
|
||
if(typeof this.options == 'object'){ | ||
var obj = {}; | ||
for(var i in this.buffer){ | ||
obj[i] = {}; | ||
for(var j in this.options){ | ||
var field = this.options[j]; | ||
if(this.buffer[i][field]){ | ||
obj[i][field] = this.buffer[i][field]; | ||
} | ||
} | ||
} | ||
|
||
this.buffer = obj; | ||
} | ||
|
||
if(this.size){ | ||
|
||
var temp = this.size.toString().split(','); | ||
|
||
var start = 0; | ||
var end = this.size; | ||
|
||
if(temp.length > 1 && temp[0] < temp[1]){ | ||
start = parseInt(temp[0]); | ||
end = start + parseInt(temp[1]); | ||
} | ||
|
||
var results = {}; | ||
for(var i = start; i < end; i++){ | ||
|
||
if(this.buffer[i]){ | ||
results[i] = this.buffer[i]; | ||
}else{ | ||
break; | ||
} | ||
} | ||
|
||
this.buffer = results; | ||
|
||
} | ||
|
||
return this.buffer; | ||
} | ||
|
||
this.new = function(obj){ | ||
this.data_source = obj; | ||
this.buffer = obj; | ||
} | ||
|
||
this.limit = function(limit){ | ||
this.size = limit; | ||
|
||
return this; | ||
} | ||
|
||
this.select = function(filters){ | ||
this.options = filters; | ||
|
||
if(typeof filters === 'string' && filters !== '*'){ | ||
this.options = filters.split(','); | ||
} | ||
|
||
this.buffer = this.data_source; | ||
this.size = false; | ||
return this; | ||
} | ||
|
||
this.where = function(field){ | ||
this.focused_field = field; | ||
|
||
return this; | ||
} | ||
|
||
// alias | ||
this.and = function(field){ | ||
return this.where(field); | ||
} | ||
|
||
// sets of conditions | ||
|
||
this.contains = function(str,caseSensitive){ | ||
if(caseSensitive == undefined){ | ||
caseSensitive == false; | ||
} | ||
var obj = this.buffer; | ||
this.buffer = []; | ||
|
||
for(var i in obj){ | ||
if(caseSensitive){ | ||
if(~obj[i][this.focused_field].indexOf(str)){ | ||
this.buffer.push(obj[i]); | ||
} | ||
}else{ | ||
if(~obj[i][this.focused_field].toLowerCase().indexOf(str.toLowerCase())){ | ||
this.buffer.push(obj[i]); | ||
} | ||
} | ||
} | ||
|
||
return this; | ||
} | ||
|
||
this.match = function(regex,options){ | ||
if(typeof regex === 'string' && regex !== ''){ | ||
options = options || 'ig'; | ||
|
||
regex = new RegExp(regex,options); | ||
|
||
var obj = this.buffer; | ||
this.buffer = []; | ||
|
||
for(var i in obj){ | ||
regex.lastIndex = 0; | ||
if(regex.exec(obj[i][this.focused_field])){ | ||
this.buffer.push(obj[i]); | ||
} | ||
} | ||
} | ||
return this; | ||
} | ||
|
||
this.equalTo = function(val){ | ||
var obj = this.buffer; | ||
this.buffer = []; | ||
|
||
for(var i in obj){ | ||
if(obj[i][this.focused_field] == val){ | ||
this.buffer.push(obj[i]); | ||
} | ||
} | ||
|
||
return this; | ||
} | ||
|
||
this.is = this.equalTo; | ||
|
||
this.in = function(vals){ | ||
var obj = this.buffer; | ||
this.buffer = []; | ||
|
||
for(var i in obj){ | ||
if(this.in_array(obj[i][this.focused_field],vals)){ | ||
this.buffer.push(obj[i]); | ||
} | ||
} | ||
|
||
return this; | ||
} | ||
|
||
this.moreThan = function(val){ | ||
var obj = this.buffer; | ||
this.buffer = []; | ||
|
||
for(var i in obj){ | ||
if(parseFloat(obj[i][this.focused_field]) > parseFloat(val)){ | ||
this.buffer.push(obj[i]); | ||
} | ||
} | ||
|
||
return this; | ||
} | ||
|
||
this.moreThanOrEqualTo = function(val){ | ||
var obj = this.buffer; | ||
this.buffer = []; | ||
|
||
for(var i in obj){ | ||
if(parseFloat(obj[i][this.focused_field]) >= parseFloat(val)){ | ||
this.buffer.push(obj[i]); | ||
} | ||
} | ||
|
||
return this; | ||
} | ||
|
||
this.lessThan = function(val){ | ||
var obj = this.buffer; | ||
this.buffer = []; | ||
|
||
for(var i in obj){ | ||
if(parseFloat(obj[i][this.focused_field]) < parseFloat(val)){ | ||
this.buffer.push(obj[i]); | ||
} | ||
} | ||
|
||
return this; | ||
} | ||
|
||
this.lessThanOrEqualTo = function(val){ | ||
var obj = this.buffer; | ||
this.buffer = []; | ||
|
||
for(var i in obj){ | ||
if(parseFloat(obj[i][this.focused_field]) <= parseFloat(val)){ | ||
this.buffer.push(obj[i]); | ||
} | ||
} | ||
|
||
return this; | ||
} | ||
|
||
// end - set of conditions | ||
|
||
// order | ||
|
||
this.orderBy = function(field, mode){ | ||
var sequence = 'asc'; | ||
var target = field.split(' '); | ||
var temp = target.pop(); | ||
|
||
if(temp && temp.toLowerCase() == 'desc'){ | ||
sequence = 'desc'; | ||
field = target.join(' '); | ||
} | ||
|
||
// prepare object | ||
var obj = []; | ||
for(var i in this.buffer){ | ||
obj.push([i,this.buffer[i][field]]); | ||
} | ||
|
||
if(mode == undefined && isNaN(obj[0][1])){ | ||
mode = 'string'; | ||
}else{ | ||
mode = 'numeric'; | ||
} | ||
|
||
if(mode == 'string'){ | ||
obj.sort(function(a, b){ | ||
if(a[1] < b[1]) return -1; | ||
if(a[1] > b[1]) return 1; | ||
return 0; | ||
}); | ||
}else{ | ||
obj.sort(function(a, b){ | ||
return a[1] - b[1]; | ||
}); | ||
} | ||
|
||
results = []; | ||
for(var i in obj){ | ||
results.push(this.buffer[obj[i][0]]); | ||
} | ||
|
||
this.buffer = results; | ||
if(sequence == 'desc'){ | ||
this.buffer = this.buffer.reverse(); | ||
} | ||
|
||
return this; | ||
} | ||
|
||
//helper | ||
this.in_array = function(val,list){ | ||
for(var i in list){ | ||
if(val == list[i]){ | ||
return true; | ||
} | ||
} | ||
|
||
return false; | ||
} | ||
|
||
} |
Oops, something went wrong.