actions.js 1.9 KB

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