Commit 72e23f8a authored by Simon's avatar Simon

Merge branch 'autocomplete-update' into dev

parents 038d9863 a57e9877
...@@ -34,6 +34,10 @@ ...@@ -34,6 +34,10 @@
background: #fff; background: #fff;
} }
.awesomplete mark {
background: none;
}
.awesomplete > ul:empty { .awesomplete > ul:empty {
display: none; display: none;
} }
This diff is collapsed.
This source diff could not be displayed because it is too large. You can view the blob instead.
...@@ -22,6 +22,43 @@ const swiper = new Swiper('.c-feedbacks--inner', { ...@@ -22,6 +22,43 @@ const swiper = new Swiper('.c-feedbacks--inner', {
} }
}); });
const lisp = (str) => {
var symbols = {
'ą': 'a',
'č': 'c',
'ę': 'e',
'ė': 'e',
'į': 'i',
'š': 's',
'ų': 'u',
'ū': 'u',
'ž': 'z',
'ā': 'a',
'ē': 'e',
'ģ': 'g',
'ī': 'i',
'ķ': 'k',
'ļ': 'l',
'ņ': 'n',
'õ': 'o',
'ä': 'a',
'ö': 'o',
'ü': 'u'
};
str = str.trim();
str = str.toLowerCase();
str = str.replace(/[ąčęėįšųūžāēģīķļņõäöü]/g, (s) => {
return symbols[s];
});
return str;
};
const autocomplete = (str) => { const autocomplete = (str) => {
const node = document.getElementById(str); const node = document.getElementById(str);
const arrow = document.querySelector('.js-toggle--' + str); const arrow = document.querySelector('.js-toggle--' + str);
...@@ -46,7 +83,10 @@ const autocomplete = (str) => { ...@@ -46,7 +83,10 @@ const autocomplete = (str) => {
const box = new Awesomplete(node, { const box = new Awesomplete(node, {
minChars: 0, minChars: 0,
maxItems: 1000, maxItems: 1000,
sort: false sort: false,
filter: function (text, input) {
return lisp(text).indexOf(lisp(input)) !== -1;
}
}); });
node.addEventListener('input', () => { node.addEventListener('input', () => {
...@@ -68,6 +108,18 @@ const autocomplete = (str) => { ...@@ -68,6 +108,18 @@ const autocomplete = (str) => {
} }
}); });
node.addEventListener('blur', () => {
const suggestion = (Array.isArray(box.suggestions) && box.suggestions.length === 1) ? box.suggestions[0] : null;
if (!suggestion) {
return;
}
if (lisp(node.value) === lisp(suggestion.value)) {
node.value = suggestion.value;
}
});
node.addEventListener('awesomplete-selectcomplete', () => { node.addEventListener('awesomplete-selectcomplete', () => {
node.blur(); node.blur();
if (clear) { if (clear) {
...@@ -130,7 +182,9 @@ if (node) { ...@@ -130,7 +182,9 @@ if (node) {
minChars: 0, minChars: 0,
maxItems: 1000, maxItems: 1000,
sort: false, sort: false,
filter: function (text, input) {
return lisp(text).indexOf(lisp(input)) !== -1;
},
replace: function (suggestion) { replace: function (suggestion) {
this.input.value = suggestion.label; this.input.value = suggestion.label;
...@@ -143,6 +197,22 @@ if (node) { ...@@ -143,6 +197,22 @@ if (node) {
node.addEventListener('focus', () => { node.addEventListener('focus', () => {
nodeBox.evaluate(); nodeBox.evaluate();
}); });
node.addEventListener('blur', () => {
const suggestion = (Array.isArray(nodeBox.suggestions) && nodeBox.suggestions.length === 1) ? nodeBox.suggestions[0] : null;
if (!suggestion) {
return;
}
if (lisp(node.value) === lisp(suggestion.label)) {
node.value = suggestion.label;
if (cityID) {
cityID.value = suggestion.value;
}
}
});
} }
if (window.NodeList && !NodeList.prototype.forEach) { if (window.NodeList && !NodeList.prototype.forEach) {
......
This diff is collapsed.
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment