diff options
author | ArthurHoaro <arthur@hoa.ro> | 2017-04-03 19:23:30 +0200 |
---|---|---|
committer | ArthurHoaro <arthur@hoa.ro> | 2017-04-04 18:44:24 +0200 |
commit | 49bc541d7973bd86776441eb072e66d01b368e68 (patch) | |
tree | 5b126e82881ff7d88291bac32b96e0bc3e3340ec /tpl/vintage/js | |
parent | a07373135e08d182314847bb7dfc5a0246610d06 (diff) | |
download | Shaarli-49bc541d7973bd86776441eb072e66d01b368e68.tar.gz Shaarli-49bc541d7973bd86776441eb072e66d01b368e68.tar.zst Shaarli-49bc541d7973bd86776441eb072e66d01b368e68.zip |
Apply the new timezone template variables to the vintage theme
Diffstat (limited to 'tpl/vintage/js')
-rw-r--r-- | tpl/vintage/js/shaarli.js | 32 |
1 files changed, 32 insertions, 0 deletions
diff --git a/tpl/vintage/js/shaarli.js b/tpl/vintage/js/shaarli.js new file mode 100644 index 00000000..9bcc96fb --- /dev/null +++ b/tpl/vintage/js/shaarli.js | |||
@@ -0,0 +1,32 @@ | |||
1 | window.onload = function () { | ||
2 | var continent = document.getElementById('continent'); | ||
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 | |||
12 | /** | ||
13 | * Add the class 'hidden' to city options not attached to the current selected continent. | ||
14 | * | ||
15 | * @param cities List of <option> elements | ||
16 | * @param currentContinent Current selected continent | ||
17 | * @param reset Set to true to reset the selected value | ||
18 | */ | ||
19 | function hideTimezoneCities(cities, currentContinent, reset = false) { | ||
20 | var first = true; | ||
21 | [].forEach.call(cities, function(option) { | ||
22 | if (option.getAttribute('data-continent') != currentContinent) { | ||
23 | option.className = 'hidden'; | ||
24 | } else { | ||
25 | option.className = ''; | ||
26 | if (reset === true && first === true) { | ||
27 | option.setAttribute('selected', 'selected'); | ||
28 | first = false; | ||
29 | } | ||
30 | } | ||
31 | }); | ||
32 | } | ||