actions.js 2.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  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. }
  51. // Handle mouseover on subSelect
  52. var allSubItems = document.querySelectorAll('.toDisplaySub');
  53. var removeAllSubItems = function () {
  54. for (var index = 0; index < allSubItems.length; index++) {
  55. var tds = allSubItems[index];
  56. if (tds.style.display == 'block') {
  57. tds.style.display = 'none';
  58. }
  59. }
  60. }
  61. var allSubSelect = document.querySelectorAll('.subSelect');
  62. for (var index = 0; index < allSubSelect.length; index++) {
  63. var ss = allSubSelect[index];
  64. ss.addEventListener('mouseenter', function () {
  65. var toDisplay = this.querySelector('.toDisplaySub');
  66. if (toDisplay) {
  67. if (toDisplay.style.display == 'block') {
  68. toDisplay.style.display = 'none';
  69. } else {
  70. removeAllSubItems();
  71. toDisplay.style.display = 'block';
  72. }
  73. }
  74. })
  75. }
  76. })();