aboutsummaryrefslogtreecommitdiffhomepage
path: root/tpl/default/js/shaarli.js
diff options
context:
space:
mode:
Diffstat (limited to 'tpl/default/js/shaarli.js')
-rw-r--r--tpl/default/js/shaarli.js55
1 files changed, 37 insertions, 18 deletions
diff --git a/tpl/default/js/shaarli.js b/tpl/default/js/shaarli.js
index 30d8ed6f..714420b7 100644
--- a/tpl/default/js/shaarli.js
+++ b/tpl/default/js/shaarli.js
@@ -76,9 +76,12 @@ window.onload = function () {
76 } 76 }
77 } 77 }
78 78
79 document.getElementById('menu-toggle').addEventListener('click', function (e) { 79 var menuToggle = document.getElementById('menu-toggle');
80 toggleMenu(); 80 if (menuToggle != null) {
81 }); 81 menuToggle.addEventListener('click', function (e) {
82 toggleMenu();
83 });
84 }
82 85
83 window.addEventListener(WINDOW_CHANGE_EVENT, closeMenu); 86 window.addEventListener(WINDOW_CHANGE_EVENT, closeMenu);
84 })(this, this.document); 87 })(this, this.document);
@@ -300,21 +303,6 @@ window.onload = function () {
300 } 303 }
301 304
302 /** 305 /**
303 * TimeZome select
304 * FIXME! way too hackish
305 */
306 var toRemove = document.getElementById('timezone-remove');
307 if (toRemove != null) {
308 var firstSelect = toRemove.getElementsByTagName('select')[0];
309 var secondSelect = toRemove.getElementsByTagName('select')[1];
310 toRemove.parentNode.removeChild(toRemove);
311 var toAdd = document.getElementById('timezone-add');
312 var newTimezone = '<span class="timezone-continent">Continent ' + firstSelect.outerHTML + '</span>';
313 newTimezone += ' <span class="timezone-country">Country ' + secondSelect.outerHTML + '</span>';
314 toAdd.innerHTML = newTimezone;
315 }
316
317 /**
318 * Awesomplete trigger. 306 * Awesomplete trigger.
319 */ 307 */
320 var tags = document.getElementById('lf_tags'); 308 var tags = document.getElementById('lf_tags');
@@ -366,6 +354,15 @@ window.onload = function () {
366 } 354 }
367 }); 355 });
368 }); 356 });
357
358 var continent = document.getElementById('continent');
359 var city = document.getElementById('city');
360 if (continent != null && city != null) {
361 continent.addEventListener('change', function(event) {
362 hideTimezoneCities(city, continent.options[continent.selectedIndex].value, true);
363 });
364 hideTimezoneCities(city, continent.options[continent.selectedIndex].value, false);
365 }
369}; 366};
370 367
371function activateFirefoxSocial(node) { 368function activateFirefoxSocial(node) {
@@ -391,3 +388,25 @@ function activateFirefoxSocial(node) {
391 var activate = new CustomEvent("ActivateSocialFeature"); 388 var activate = new CustomEvent("ActivateSocialFeature");
392 node.dispatchEvent(activate); 389 node.dispatchEvent(activate);
393} 390}
391
392/**
393 * Add the class 'hidden' to city options not attached to the current selected continent.
394 *
395 * @param cities List of <option> elements
396 * @param currentContinent Current selected continent
397 * @param reset Set to true to reset the selected value
398 */
399function hideTimezoneCities(cities, currentContinent, reset = false) {
400 var first = true;
401 [].forEach.call(cities, function(option) {
402 if (option.getAttribute('data-continent') != currentContinent) {
403 option.className = 'hidden';
404 } else {
405 option.className = '';
406 if (reset === true && first === true) {
407 option.setAttribute('selected', 'selected');
408 first = false;
409 }
410 }
411 });
412}