Skip to content

Commit e669b00

Browse files
authored
Merge pull request #39 from JerrySmidt/3.1.3
3.1.3 - Update autocomplete library to 1.3.0
2 parents bd4c172 + ea584f8 commit e669b00

File tree

1 file changed

+27
-4
lines changed

1 file changed

+27
-4
lines changed

view/frontend/web/js/lib/postcode-eu-autocomplete-address.js

Lines changed: 27 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
* https://tldrlegal.com/l/mit
99
*
1010
* @author Postcode.nl
11-
* @version 1.2.3
11+
* @version 1.3.0
1212
*/
1313

1414
(function (global, factory) {
@@ -31,6 +31,7 @@
3131
const document = window.document,
3232
$ = function (selector) { return document.querySelectorAll(selector); },
3333
elementData = new WeakMap(),
34+
VERSION = '1.3.0',
3435
EVENT_NAMESPACE = 'autocomplete-',
3536
PRECISION_ADDRESS = 'Address',
3637
KEY_ESC = 'Escape',
@@ -174,6 +175,7 @@
174175
language: {
175176
writable: true,
176177
},
178+
177179
});
178180

179181
/**
@@ -672,6 +674,9 @@
672674
// Create options object that inherits from defaults.
673675
options = extend(Object.create(defaults), options);
674676

677+
// Make context lowercase as required by API.
678+
options.context = options.context.toLowerCase();
679+
675680
// Expose options.
676681
Object.defineProperty(this, 'options', {
677682
get: function () {
@@ -889,7 +894,7 @@
889894
return str;
890895
}
891896

892-
var i = 0,
897+
let i = 0,
893898
start = 0,
894899
end = 0,
895900
result = [],
@@ -1028,8 +1033,12 @@
10281033
},
10291034
});
10301035

1036+
if (false === element.hasAttribute('autocomplete'))
1037+
{
1038+
element.autocomplete = 'off';
1039+
}
1040+
10311041
element.spellcheck = false;
1032-
element.autocomplete = 'off';
10331042
element.setAttribute('aria-controls', liveRegion.id);
10341043
element.classList.add(options.cssPrefix + 'address-input');
10351044
element.classList.toggle(inputBlankClassName, element.value === '');
@@ -1164,13 +1173,22 @@
11641173

11651174
/**
11661175
* Search after input has stopped arriving for the amount of milliseconds specified by options.delay.
1176+
* Values of up to three characters have practically no delay because most of these queries will be served from cache.
11671177
*
11681178
* @param {HTMLElement} element - Associated input element.
11691179
*/
11701180
const searchDebounced = function (element)
11711181
{
11721182
window.clearTimeout(searchTimeoutId);
1173-
searchTimeoutId = window.setTimeout(search, options.delay, element);
1183+
1184+
let delay = 10;
1185+
1186+
if (element.value.length > 3)
1187+
{
1188+
delay = options.delay;
1189+
}
1190+
1191+
searchTimeoutId = window.setTimeout(search, delay, element);
11741192
}
11751193

11761194
/**
@@ -1247,5 +1265,10 @@
12471265
},
12481266
});
12491267

1268+
// Expose readonly version number.
1269+
Object.defineProperty(autocomplete, 'version', {
1270+
value: VERSION,
1271+
});
1272+
12501273
return autocomplete;
12511274
}));

0 commit comments

Comments
 (0)