diff options
author | ArthurHoaro <arthur@hoa.ro> | 2018-02-24 18:30:30 +0100 |
---|---|---|
committer | ArthurHoaro <arthur@hoa.ro> | 2018-03-26 19:29:20 +0200 |
commit | d42da5435024b4270d5abac11e6fcfa38354f3e9 (patch) | |
tree | cfd340e25ab7e1b88fe943541ce4f882a315617b /assets/vintage/js | |
parent | d78c23e00d3007c3fee8c3603acac00efc1ce14e (diff) | |
download | Shaarli-d42da5435024b4270d5abac11e6fcfa38354f3e9.tar.gz Shaarli-d42da5435024b4270d5abac11e6fcfa38354f3e9.tar.zst Shaarli-d42da5435024b4270d5abac11e6fcfa38354f3e9.zip |
Webpack / Rewrite all JS to ES6 Syntax
Diffstat (limited to 'assets/vintage/js')
-rw-r--r-- | assets/vintage/js/base.js | 56 |
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 @@ | |||
1 | window.onload = function () { | 1 | import Awesomplete from 'awesomplete'; |
2 | var continent = document.getElementById('continent'); | 2 | import '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) => { |
19 | function 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 | })(); | ||