actions.js 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. (function () {
  2. var allSelect = document.querySelectorAll('.select');
  3. var allToDisplay = document.querySelectorAll('.toDisplay');
  4. var allToDisplayBig = document.querySelectorAll('.toDisplayBig');
  5. var removeAllOptions = function () {
  6. for (var index = 0; index < allToDisplay.length; index++) {
  7. var a = allToDisplay[index];
  8. if (a.style.display == 'block') {
  9. a.style.display = 'none';
  10. }
  11. }
  12. for (var index = 0; index < allToDisplayBig.length; index++) {
  13. var b = allToDisplayBig[index];
  14. if (b.style.display == 'block') {
  15. b.style.display = 'none';
  16. }
  17. }
  18. }
  19. // Remove displayed options
  20. window.addEventListener('click', function () {
  21. removeAllOptions();
  22. });
  23. // Handle click on select elements
  24. for (var index = 0; index < allSelect.length; index++) {
  25. var s = allSelect[index];
  26. // Get child called to display
  27. s.addEventListener('click', function (e) {
  28. var toDisplay = this.querySelector('.toDisplay');
  29. if (toDisplay) {
  30. if (toDisplay.style.display == 'block') {
  31. toDisplay.style.display = 'none';
  32. } else {
  33. removeAllOptions();
  34. toDisplay.style.display = 'block';
  35. }
  36. }
  37. toDisplay = this.querySelector('.toDisplayBig');
  38. if (toDisplay) {
  39. if (toDisplay.style.display == 'block') {
  40. toDisplay.style.display = 'none';
  41. } else {
  42. removeAllOptions();
  43. toDisplay.style.display = 'block';
  44. }
  45. }
  46. e.preventDefault();
  47. e.stopPropagation();
  48. });
  49. }
  50. document.querySelector('#safemodeToggle').addEventListener('click', function () {
  51. this.classList.toggle('checked');
  52. if (this.classList.contains('checked')) {
  53. this.innerHTML = 'Safe mode <i class="fa fa-check-square" aria-hidden="true"></i>';
  54. } else {
  55. this.innerHTML = 'Safe mode <i class="fa fa-square-o" aria-hidden="true"></i>';
  56. }
  57. })
  58. })();