🐛 N°1822 fix for the autocomplete on IE.

Support of some accents (western languages) on IE, complete support of
all unicode accents on browsers supporting String.normalize.
This commit is contained in:
Denis Flaven
2018-12-04 15:07:46 +01:00
parent 3fa0cbf0fe
commit 53e532cbaf

View File

@@ -473,8 +473,14 @@
function matchSubset(s, sub) {
if (!options.matchCase)
s = s.toLowerCase().normalize('NFD').replace(/[\u0300-\u036f]/g, "");
sub = sub.toLowerCase().normalize('NFD').replace(/[\u0300-\u036f]/g, "");
if (typeof s.normalize === 'function'){
s = s.toLowerCase().normalize('NFD').replace(/[\u0300-\u036f]/g, "");
sub = sub.toLowerCase().normalize('NFD').replace(/[\u0300-\u036f]/g, "");
}
else {
s = ie_normalize(s.toLowerCase());
sub = ie_normalize(sub.toLowerCase());
}
var i = s.indexOf(sub);
if (options.matchContains === "word"){
i = s.toLowerCase().search("\\b" + sub.toLowerCase());
@@ -482,7 +488,24 @@
if (i === -1) return false;
return i === 0 || options.matchContains;
};
function ie_normalize(s)
{
//Cheap replacement for normalize on IE. Works only on a (small) subset of what's possible in unicode
var r = s.toLowerCase();
r = r.replace(new RegExp(/[àáâãäå]/g),"a");
r = r.replace(new RegExp(/æ/g),"ae");
r = r.replace(new RegExp(/ç/g),"c");
r = r.replace(new RegExp(/[èéêë]/g),"e");
r = r.replace(new RegExp(/[ìíîï]/g),"i");
r = r.replace(new RegExp(/ñ/g),"n");
r = r.replace(new RegExp(/[òóôõö]/g),"o");
r = r.replace(new RegExp(/œ/g),"oe");
r = r.replace(new RegExp(/[ùúûü]/g),"u");
r = r.replace(new RegExp(/[ýÿ]/g),"y");
return r;
}
function add(q, value) {
if (length > options.cacheLength){
flush();