actions.js 3.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  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. var displayItems = 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. s.addEventListener('click', displayItems);
  50. // Handle mouseover on subSelect
  51. var allSubItems = document.querySelectorAll('.toDisplaySub');
  52. var removeAllSubItems = function () {
  53. for (var index = 0; index < allSubItems.length; index++) {
  54. var tds = allSubItems[index];
  55. if (tds.style.display == 'block') {
  56. tds.style.display = 'none';
  57. }
  58. }
  59. }
  60. var allSubSelect = document.querySelectorAll('.subSelect');
  61. for (var index = 0; index < allSubSelect.length; index++) {
  62. var ss = allSubSelect[index];
  63. ss.addEventListener('mouseenter', function () {
  64. var toDisplay = this.querySelector('.toDisplaySub');
  65. if (toDisplay) {
  66. if (toDisplay.style.display == 'block') {
  67. toDisplay.style.display = 'none';
  68. } else {
  69. removeAllSubItems();
  70. toDisplay.style.display = 'block';
  71. }
  72. }
  73. })
  74. }
  75. }
  76. document.querySelector('#safemodeToggle').addEventListener('click', function () {
  77. this.classList.toggle('checked');
  78. if (this.classList.contains('checked')) {
  79. this.innerHTML = 'Safe mode <i class="fa fa-check-square" aria-hidden="true"></i>';
  80. } else {
  81. this.innerHTML = 'Safe mode <i class="fa fa-square-o" aria-hidden="true"></i>';
  82. }
  83. })
  84. })();