Skip to content

Commit

Permalink
Support Accents. Fix resize plugin with resize window
Browse files Browse the repository at this point in the history
  • Loading branch information
xdan committed Oct 10, 2014
1 parent 1de064f commit c8eb64d
Show file tree
Hide file tree
Showing 4 changed files with 181 additions and 50 deletions.
4 changes: 3 additions & 1 deletion autocompletelikegoogle.jquery.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "autocompletelikegoogle",
"version": "1.0.7",
"version": "1.0.8",
"title": "Autocomplete like Google",
"description": "Simple autocomplete like Google",
"keywords": [
Expand All @@ -10,6 +10,8 @@
"form",
"ui",
"input",
"accents",
"accents",
"jquery"
],
"author": {
Expand Down
3 changes: 2 additions & 1 deletion bower.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name":"autocompletelikegoogle",
"version":"1.0.7",
"version":"1.0.8",
"main": [
"jquery.autocomplete.js",
"jquery.autocomplete.css"
Expand All @@ -21,6 +21,7 @@
"form",
"ui",
"input",
"accents",
"jquery"
],
"dependencies": {
Expand Down
2 changes: 1 addition & 1 deletion index.html
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
</nav>
<div class="auto" style="margin-top:100px">
<h1 class="text-center">Autocomplete like Google <small>jQuery Plugin</small></h1>
<p class="desc">JQuery Autocomplete plugin is a lightweight simple and easy in settings autocomplete like Google</p>
<p class="desc">JQuery Autocomplete plugin is a lightweight simple and easy in settings autocomplete like Google. Accents support</p>
<p class="text-center">
<a id="local" class="btn btn-link" href="#local">Local</a>
<a class="btn btn-link" href="#remote">Remote</a>
Expand Down
222 changes: 175 additions & 47 deletions jquery.autocomplete.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,85 @@
/**
* @preserve jQuery Autocomplete plugin v1.0.7
* @preserve jQuery Autocomplete plugin v1.0.8
* @homepage http://xdsoft.net/jqplugins/autocomplete/
* (c) 2014, Chupurnov Valeriy <[email protected]>
*/
!function ($) {
'use strict';
var ARROWLEFT = 37,
ARROWRIGHT = 39,
ARROWUP = 38,
ARROWDOWN = 40,
TAB = 9,
CTRLKEY = 17,
SHIFTKEY = 16,
DEL = 46,
ENTER = 13,
ESC = 27,
BACKSPACE = 8,
AKEY = 65,
CKEY = 67,
VKEY = 86,
ZKEY = 90,
YKEY = 89,
defaultSetting = {},
currentInput = false,
ctrlDown = false,
shiftDown = false,
interval_for_visibility,
accent_map = {
'ẚ':'a','Á':'a','á':'a','À':'a','à':'a','Ă':'a','ă':'a','Ắ':'a','ắ':'a','Ằ':'a','ằ':'a','Ẵ':'a','ẵ':'a','Ẳ':'a',
'Ẫ':'a','ẫ':'a','Ẩ':'a','ẩ':'a','Ǎ':'a','ǎ':'a','Å':'a','å':'a','Ǻ':'a','ǻ':'a','Ä':'a','ä':'a','Ǟ':'a','ǟ':'a',
'Ã':'a','ã':'a','Ȧ':'a','ȧ':'a','Ǡ':'a','ǡ':'a','Ą':'a','ą':'a','Ā':'a','ā':'a','Ả':'a','ả':'a','Ȁ':'a','ȁ':'a',
'Ȃ':'a','ȃ':'a','Ạ':'a','ạ':'a','Ặ':'a','ặ':'a','Ậ':'a','ậ':'a','Ḁ':'a','ḁ':'a','Ⱥ':'a','ⱥ':'a','Ǽ':'a','ǽ':'a',
'Ǣ':'a','ǣ':'a','Ḃ':'b','ḃ':'b','Ḅ':'b','ḅ':'b','Ḇ':'b','ḇ':'b','Ƀ':'b','ƀ':'b','ᵬ':'b','Ɓ':'b','ɓ':'b','Ƃ':'b',
'ƃ':'b','Ć':'c','ć':'c','Ĉ':'c','ĉ':'c','Č':'c','č':'c','Ċ':'c','ċ':'c','Ç':'c','ç':'c','Ḉ':'c','ḉ':'c','Ȼ':'c',
'ȼ':'c','Ƈ':'c','ƈ':'c','ɕ':'c','Ď':'d','ď':'d','Ḋ':'d','ḋ':'d','Ḑ':'d','ḑ':'d','Ḍ':'d','ḍ':'d','Ḓ':'d','ḓ':'d',
'Ḏ':'d','ḏ':'d','Đ':'d','đ':'d','ᵭ':'d','Ɖ':'d','ɖ':'d','Ɗ':'d','ɗ':'d','Ƌ':'d','ƌ':'d','ȡ':'d','ð':'d','É':'e',
'Ə':'e','Ǝ':'e','ǝ':'e','é':'e','È':'e','è':'e','Ĕ':'e','ĕ':'e','Ê':'e','ê':'e','Ế':'e','ế':'e','Ề':'e','ề':'e',
'Ễ':'e','ễ':'e','Ể':'e','ể':'e','Ě':'e','ě':'e','Ë':'e','ë':'e','Ẽ':'e','ẽ':'e','Ė':'e','ė':'e','Ȩ':'e','ȩ':'e',
'Ḝ':'e','ḝ':'e','Ę':'e','ę':'e','Ē':'e','ē':'e','Ḗ':'e','ḗ':'e','Ḕ':'e','ḕ':'e','Ẻ':'e','ẻ':'e','Ȅ':'e','ȅ':'e',
'Ȇ':'e','ȇ':'e','Ẹ':'e','ẹ':'e','Ệ':'e','ệ':'e','Ḙ':'e','ḙ':'e','Ḛ':'e','ḛ':'e','Ɇ':'e','ɇ':'e','ɚ':'e','ɝ':'e',
'Ḟ':'f','ḟ':'f','ᵮ':'f','Ƒ':'f','ƒ':'f','Ǵ':'g','ǵ':'g','Ğ':'g','ğ':'g','Ĝ':'g','ĝ':'g','Ǧ':'g','ǧ':'g','Ġ':'g',
'ġ':'g','Ģ':'g','ģ':'g','Ḡ':'g','ḡ':'g','Ǥ':'g','ǥ':'g','Ɠ':'g','ɠ':'g','Ĥ':'h','ĥ':'h','Ȟ':'h','ȟ':'h','Ḧ':'h',
'ḧ':'h','Ḣ':'h','ḣ':'h','Ḩ':'h','ḩ':'h','Ḥ':'h','ḥ':'h','Ḫ':'h','ḫ':'h','H':'h','̱':'h','ẖ':'h','Ħ':'h','ħ':'h',
'Ⱨ':'h','ⱨ':'h','Í':'i','í':'i','Ì':'i','ì':'i','Ĭ':'i','ĭ':'i','Î':'i','î':'i','Ǐ':'i','ǐ':'i','Ï':'i','ï':'i',
'Ḯ':'i','ḯ':'i','Ĩ':'i','ĩ':'i','İ':'i','i':'i','Į':'i','į':'i','Ī':'i','ī':'i','Ỉ':'i','ỉ':'i','Ȉ':'i','ȉ':'i',
'Ȋ':'i','ȋ':'i','Ị':'i','ị':'i','Ḭ':'i','ḭ':'i','I':'i','ı':'i','Ɨ':'i','ɨ':'i','Ĵ':'j','ĵ':'j','J':'j','̌':'j',
'ǰ':'j','ȷ':'j','Ɉ':'j','ɉ':'j','ʝ':'j','ɟ':'j','ʄ':'j','Ḱ':'k','ḱ':'k','Ǩ':'k','ǩ':'k','Ķ':'k','ķ':'k','Ḳ':'k',
'ḳ':'k','Ḵ':'k','ḵ':'k','Ƙ':'k','ƙ':'k','Ⱪ':'k','ⱪ':'k','Ĺ':'a','ĺ':'l','Ľ':'l','ľ':'l','Ļ':'l','ļ':'l','Ḷ':'l',
'ḷ':'l','Ḹ':'l','ḹ':'l','Ḽ':'l','ḽ':'l','Ḻ':'l','ḻ':'l','Ł':'l','ł':'l','̣':'l','Ŀ':'l',
'ŀ':'l','Ƚ':'l','ƚ':'l','Ⱡ':'l','ⱡ':'l','Ɫ':'l','ɫ':'l','ɬ':'l','ɭ':'l','ȴ':'l','Ḿ':'m','ḿ':'m','Ṁ':'m','ṁ':'m',
'Ṃ':'m','ṃ':'m','ɱ':'m','Ń':'n','ń':'n','Ǹ':'n','ǹ':'n','Ň':'n','ň':'n','Ñ':'n','ñ':'n','Ṅ':'n','ṅ':'n','Ņ':'n',
'ņ':'n','Ṇ':'n','ṇ':'n','Ṋ':'n','ṋ':'n','Ṉ':'n','ṉ':'n','Ɲ':'n','ɲ':'n','Ƞ':'n','ƞ':'n','ɳ':'n','ȵ':'n','N':'n',
'̈':'n','n':'n','Ó':'o','ó':'o','Ò':'o','ò':'o','Ŏ':'o','ŏ':'o','Ô':'o','ô':'o','Ố':'o','ố':'o','Ồ':'o',
'ồ':'o','Ỗ':'o','ỗ':'o','Ổ':'o','ổ':'o','Ǒ':'o','ǒ':'o','Ö':'o','ö':'o','Ȫ':'o','ȫ':'o','Ő':'o','ő':'o','Õ':'o',
'õ':'o','Ṍ':'o','ṍ':'o','Ṏ':'o','ṏ':'o','Ȭ':'o','ȭ':'o','Ȯ':'o','ȯ':'o','Ȱ':'o','ȱ':'o','Ø':'o','ø':'o','Ǿ':'o',
'ǿ':'o','Ǫ':'o','ǫ':'o','Ǭ':'o','ǭ':'o','Ō':'o','ō':'o','Ṓ':'o','ṓ':'o','Ṑ':'o','ṑ':'o','Ỏ':'o','ỏ':'o','Ȍ':'o',
'ȍ':'o','Ȏ':'o','ȏ':'o','Ơ':'o','ơ':'o','Ớ':'o','ớ':'o','Ờ':'o','ờ':'o','Ỡ':'o','ỡ':'o','Ở':'o','ở':'o','Ợ':'o',
'ợ':'o','Ọ':'o','ọ':'o','Ộ':'o','ộ':'o','Ɵ':'o','ɵ':'o','Ṕ':'p','ṕ':'p','Ṗ':'p','ṗ':'p','Ᵽ':'p','Ƥ':'p','ƥ':'p',
'P':'p','̃':'p','p':'p','ʠ':'q','Ɋ':'q','ɋ':'q','Ŕ':'r','ŕ':'r','Ř':'r','ř':'r','Ṙ':'r','ṙ':'r','Ŗ':'r',
'ŗ':'r','Ȑ':'r','ȑ':'r','Ȓ':'r','ȓ':'r','Ṛ':'r','ṛ':'r','Ṝ':'r','ṝ':'r','Ṟ':'r','ṟ':'r','Ɍ':'r','ɍ':'r','ᵲ':'r',
'ɼ':'r','Ɽ':'r','ɽ':'r','ɾ':'r','ᵳ':'r','ß':'s','Ś':'s','ś':'s','Ṥ':'s','ṥ':'s','Ŝ':'s','ŝ':'s','Š':'s','š':'s',
'Ṧ':'s','ṧ':'s','Ṡ':'s','ṡ':'s','ẛ':'s','Ş':'s','ş':'s','Ṣ':'s','ṣ':'s','Ṩ':'s','ṩ':'s','Ș':'s','ș':'s','ʂ':'s',
'S':'s','̩':'s','s':'s','Þ':'t','þ':'t','Ť':'t','ť':'t','T':'t','ẗ':'t','Ṫ':'t','ṫ':'t','Ţ':'t','ţ':'t','Ṭ':'t',
'ṭ':'t','Ț':'t','ț':'t','Ṱ':'t','ṱ':'t','Ṯ':'t','ṯ':'t','Ŧ':'t','ŧ':'t','Ⱦ':'t','ⱦ':'t','ᵵ':'t',
'ƫ':'t','Ƭ':'t','ƭ':'t','Ʈ':'t','ʈ':'t','ȶ':'t','Ú':'u','ú':'u','Ù':'u','ù':'u','Ŭ':'u','ŭ':'u','Û':'u','û':'u',
'Ǔ':'u','ǔ':'u','Ů':'u','ů':'u','Ü':'u','ü':'u','Ǘ':'u','ǘ':'u','Ǜ':'u','ǜ':'u','Ǚ':'u','ǚ':'u','Ǖ':'u','ǖ':'u',
'Ű':'u','ű':'u','Ũ':'u','ũ':'u','Ṹ':'u','ṹ':'u','Ų':'u','ų':'u','Ū':'u','ū':'u','Ṻ':'u','ṻ':'u','Ủ':'u','ủ':'u',
'Ȕ':'u','ȕ':'u','Ȗ':'u','ȗ':'u','Ư':'u','ư':'u','Ứ':'u','ứ':'u','Ừ':'u','ừ':'u','Ữ':'u','ữ':'u','Ử':'u','ử':'u',
'Ự':'u','ự':'u','Ụ':'u','ụ':'u','Ṳ':'u','ṳ':'u','Ṷ':'u','ṷ':'u','Ṵ':'u','ṵ':'u','Ʉ':'u','ʉ':'u','Ṽ':'v','ṽ':'v',
'Ṿ':'v','ṿ':'v','Ʋ':'v','ʋ':'v','Ẃ':'w','ẃ':'w','Ẁ':'w','ẁ':'w','Ŵ':'w','ŵ':'w','W':'w','̊':'w','ẘ':'w','Ẅ':'w',
'ẅ':'w','Ẇ':'w','ẇ':'w','Ẉ':'w','ẉ':'w','Ẍ':'x','ẍ':'x','Ẋ':'x','ẋ':'x','Ý':'y','ý':'y','Ỳ':'y','ỳ':'y','Ŷ':'y',
'ŷ':'y','Y':'y','ẙ':'y','Ÿ':'y','ÿ':'y','Ỹ':'y','ỹ':'y','Ẏ':'y','ẏ':'y','Ȳ':'y','ȳ':'y','Ỷ':'y','ỷ':'y',
'Ỵ':'y','ỵ':'y','ʏ':'y','Ɏ':'y','ɏ':'y','Ƴ':'y','ƴ':'y','Ź':'z','ź':'z','Ẑ':'z','ẑ':'z','Ž':'z','ž':'z','Ż':'z',
'ż':'z','Ẓ':'z','ẓ':'z','Ẕ':'z','ẕ':'z','Ƶ':'z','ƶ':'z','Ȥ':'z','ȥ':'z','ʐ':'z','ʑ':'z','Ⱬ':'z','ⱬ':'z','Ǯ':'z',
'ǯ':'z','ƺ':'z','2':'2','6':'6','B':'B','F':'F','J':'J','N':'N','R':'R','V':'V','Z':'Z','b':'b','f':'f','j':'j',
'n':'n','r':'r','v':'v','z':'z','1':'1','5':'5','9':'9','A':'A','E':'E','I':'I','M':'M','Q':'Q','U':'U','Y':'Y',
'a':'a','e':'e','i':'i','m':'m','q':'q','u':'u','y':'y','0':'0','4':'4','8':'8','D':'D','H':'H','L':'L','P':'P',
'T':'T','X':'X','d':'d','h':'h','l':'l','p':'p','t':'t','x':'x','3':'3','7':'7','C':'C','G':'G','K':'K','O':'O',
'S':'S','W':'W','c':'c','g':'g','k':'k','o':'o','s':'s','w':'w','ẳ':'a','Â':'a','â':'a','Ấ':'a','ấ':'a','Ầ':'a','ầ':'a'
};

if (window.getComputedStyle === undefined) {
window.getComputedStyle = (function () {
function getPixelSize(element, style, property, fontSize) {
Expand Down Expand Up @@ -78,26 +153,7 @@
return getComputedStyle;
}(this));
}
var ARROWLEFT = 37,
ARROWRIGHT = 39,
ARROWUP = 38,
ARROWDOWN = 40,
TAB = 9,
CTRLKEY = 17,
SHIFTKEY = 16,
DEL = 46,
ENTER = 13,
ESC = 27,
BACKSPACE = 8,
AKEY = 65,
CKEY = 67,
VKEY = 86,
ZKEY = 90,
YKEY = 89,
defaultSetting = {},
currentInput = false,
ctrlDown = false,
shiftDown = false;


$(document)
.on('keydown.xdsoftctrl', function (e) {
Expand All @@ -116,7 +172,20 @@
ctrlDown = false;
}
});


function accentReplace (s) {
if (!s) { return ''; }
var ret = '',i;
for (i=0; i < s.length; i+=1) {
ret += accent_map[s.charAt(i)] || s.charAt(i);
}
return ret;
}

function escapeRegExp (str) {
return str.replace(/[\-\[\]\/\{\}\(\)\*\+\?\.\\\^\$\|]/g, "\\$&");
}

function getCaretPosition(input) {
if (!input) {
return;
Expand Down Expand Up @@ -378,7 +447,10 @@
closeOnBlur: true,

autoselect: false,


accents: true,
replaceAccentsForRemote: true,

limit: 20,

timeoutUpdate: 10,
Expand All @@ -388,7 +460,10 @@
},

replace: [
function( url,query ){
function (url, query) {
if (this.replaceAccentsForRemote) {
query = accentReplace(query);
}
return url.replace('%QUERY%',encodeURIComponent(query));
}
],
Expand All @@ -403,7 +478,6 @@

for(var i in items){
value = __safe.call(this,'getValue',source,[items[i],source]);
// right side equal
if( __safe.call(this,'equal',source,[value,query,source],false) ){
return items[i];
}
Expand All @@ -414,22 +488,24 @@
],

valid:[
function ( value,query ){
try{
return value.toLowerCase().indexOf(query.toLowerCase())!=-1;
}catch( e ){
console.log(e);
}
function (value, query) {
if (this.accents) {
value = accentReplace(value);
query = accentReplace(query);
}
return value.toLowerCase().indexOf(query.toLowerCase())!=-1;

}
],

filter:[
function ( items,query,source ){
var results = [],value = '';
for(var i in items){
value = isset(items[i][this.get('valueKey',source)])?items[i][this.get('valueKey',source)]:items[i].toString();
if( __safe.call(this,'valid',source,[value,query]) )
function (items, query, source) {
var results = [], value = '',i;
for (i = 0;i < items.length;i += 1) {
value = isset(items[i][this.get('valueKey', source)]) ? items[i][this.get('valueKey', source)] : items[i].toString();
if (__safe.call(this, 'valid', source, [value, query])) {
results.push(items[i]);
}
}
return results;
}
Expand All @@ -452,12 +528,40 @@
],

render:[
function( item,source,pid,query ){
var value = isset(item[this.get('valueKey',source)])?item[this.get('valueKey',source)]:item.toString(),
title = (isset(item[this.get('titleKey',source)])?item[this.get('titleKey',source)]:value)+'';
function (item, source, pid, query) {
var value = isset(item[this.get('valueKey', source)]) ? item[this.get('valueKey', source)] : item.toString(),
title = (isset(item[this.get('titleKey', source)]) ? item[this.get('titleKey', source)] : value) + '',
_value = '',
_query = '',
_title = '',
hilite_hints = '',
highlighted = '',
c, h, i,
spos = 0;

if( this.highlight )
title = title.replace(RegExp('('+query.replace(/([\[\]\\(\)])/g,'\\$1')+')','i'),'<b>$1</b>');
if (this.highlight) {
if (!this.accents) {
title = title.replace(new RegExp('('+escapeRegExp(query)+')','i'),'<b>$1</b>');
}else{
_title = accentReplace(title).toLowerCase().replace(/[<>]+/g, ''),
_query = accentReplace(query).toLowerCase().replace(/[<>]+/g, '');

hilite_hints = _title.replace(new RegExp(escapeRegExp(_query), 'g'), '<'+_query+'>');
for (i=0;i < hilite_hints.length;i += 1) {
c = title.charAt(spos);
h = hilite_hints.charAt(i);
if (h === '<') {
highlighted += '<b>';
} else if (h === '>') {
highlighted += '</b>';
} else {
spos += 1;
highlighted += c;
}
}
title = highlighted;
}
}

return '<div '+(value==query?'class="active"':'')+' data-value="'+encodeURIComponent(value)+'">'
+title+
Expand Down Expand Up @@ -487,8 +591,8 @@

$box
.css({
'display':$(that).css('display'),
'width':$(that).css('width')
'display':$input.css('display'),
'width':$input.css('width')
});

if( options.style )
Expand Down Expand Up @@ -708,7 +812,10 @@
.on('updateHelperPosition.xdsoft',function(){
clearTimeout(timerUpdate);
timerUpdate = setTimeout(function(){

$box.css({
'display':$input.css('display'),
'width':$input.css('width')
});
$dropdown.css($.extend(true,{
left:$input.position().left,
top:$input.position().top+parseInt($input.css('marginTop'))+parseInt($input[0].offsetHeight),
Expand Down Expand Up @@ -784,9 +891,30 @@
.append($hint);
}
},options.timeoutUpdate||1);
})
.trigger('updateHelperPosition.xdsoft')

});

if ($input.is(':visible')) {
$input
.trigger('updateHelperPosition.xdsoft');
} else {
interval_for_visibility = setInterval(function () {
if ($input.is(':visible')) {
$input
.trigger('updateHelperPosition.xdsoft');
clearInterval(interval_for_visibility);
}
},100);
}

$(window).on('resize',function () {
$box.css({
'width':'auto'
});
$input
.trigger('updateHelperPosition.xdsoft');
})

$input
.on('close.xdsoft',function(){
if( !iOpen )
return;
Expand Down

0 comments on commit c8eb64d

Please sign in to comment.