aboutsummaryrefslogtreecommitdiffhomepage
path: root/assets/vintage/js/base.js
diff options
context:
space:
mode:
authorArthurHoaro <arthur@hoa.ro>2018-02-24 18:30:30 +0100
committerArthurHoaro <arthur@hoa.ro>2018-03-28 19:01:17 +0200
commita33c5653655215d3a6496807f15a896d4b85f070 (patch)
tree59bb872b5afeb3a810c30ae8d420c6b192de4bea /assets/vintage/js/base.js
parentb3375c7f86f35fce723185bb76d3b5f9c4ff7a07 (diff)
downloadShaarli-a33c5653655215d3a6496807f15a896d4b85f070.tar.gz
Shaarli-a33c5653655215d3a6496807f15a896d4b85f070.tar.zst
Shaarli-a33c5653655215d3a6496807f15a896d4b85f070.zip
Webpack / Rewrite all JS to ES6 Syntax
Diffstat (limited to 'assets/vintage/js/base.js')
-rw-r--r--assets/vintage/js/base.js56
1 files changed, 27 insertions, 29 deletions
diff --git a/assets/vintage/js/base.js b/assets/vintage/js/base.js
index 9bcc96fb..66830b59 100644
--- a/assets/vintage/js/base.js
+++ b/assets/vintage/js/base.js
@@ -1,32 +1,30 @@
1window.onload = function () { 1import Awesomplete from 'awesomplete';
2 var continent = document.getElementById('continent'); 2import 'awesomplete/awesomplete.css';
3 var city = document.getElementById('city');
4 if (continent != null && city != null) {
5 continent.addEventListener('change', function(event) {
6 hideTimezoneCities(city, continent.options[continent.selectedIndex].value, true);
7 });
8 hideTimezoneCities(city, continent.options[continent.selectedIndex].value, false);
9 }
10};
11 3
12/** 4(() => {
13 * Add the class 'hidden' to city options not attached to the current selected continent. 5 const awp = Awesomplete.$;
14 * 6 const autocompleteFields = document.querySelectorAll('input[data-multiple]');
15 * @param cities List of <option> elements 7 [...autocompleteFields].forEach((autocompleteField) => {
16 * @param currentContinent Current selected continent 8 const awesomplete = new Awesomplete(awp(autocompleteField));
17 * @param reset Set to true to reset the selected value 9 awesomplete.filter = (text, input) => Awesomplete.FILTER_CONTAINS(text, input.match(/[^ ]*$/)[0]);
18 */ 10 awesomplete.replace = (text) => {
19function hideTimezoneCities(cities, currentContinent, reset = false) { 11 const before = awesomplete.input.value.match(/^.+ \s*|/)[0];
20 var first = true; 12 awesomplete.input.value = `${before}${text} `;
21 [].forEach.call(cities, function(option) { 13 };
22 if (option.getAttribute('data-continent') != currentContinent) { 14 awesomplete.minChars = 1;
23 option.className = 'hidden'; 15
24 } else { 16 autocompleteField.addEventListener('input', () => {
25 option.className = ''; 17 const proposedTags = autocompleteField.getAttribute('data-list').replace(/,/g, '').split(' ');
26 if (reset === true && first === true) { 18 const reg = /(\w+) /g;
27 option.setAttribute('selected', 'selected'); 19 let match;
28 first = false; 20 while ((match = reg.exec(autocompleteField.value)) !== null) {
29 } 21 const id = proposedTags.indexOf(match[1]);
22 if (id !== -1) {
23 proposedTags.splice(id, 1);
30 } 24 }
25 }
26
27 awesomplete.list = proposedTags;
31 }); 28 });
32} 29 });
30})();