actions.js 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138
  1. (function () {
  2. var allSelect = document.querySelectorAll('.select');
  3. var allToDisplay = document.querySelectorAll('.toDisplay');
  4. var allToDisplayBig = document.querySelectorAll('.toDisplayBig');
  5. var allSubItems = document.querySelectorAll('.toDisplaySub');
  6. var allSubSelect = document.querySelectorAll('.subSelect');
  7. var allNoSubSelect = document.querySelectorAll('.noSubSelect');
  8. // Remove displayed subItems
  9. var removeAllSubItems = function () {
  10. for (var index = 0; index < allSubItems.length; index++) {
  11. allSubItems[index].style.display = 'none';
  12. }
  13. }
  14. // Remove displayed options
  15. var removeAllOptions = function () {
  16. removeAllSubItems();
  17. for (var index = 0; index < allToDisplay.length; index++) {
  18. var a = allToDisplay[index];
  19. if (a.style.display == 'block') {
  20. a.style.display = 'none';
  21. }
  22. }
  23. for (var index = 0; index < allToDisplayBig.length; index++) {
  24. var b = allToDisplayBig[index];
  25. if (b.style.display == 'block') {
  26. b.style.display = 'none';
  27. }
  28. }
  29. }
  30. // Remove displayed options
  31. window.addEventListener('click', function (evt) {
  32. removeAllOptions();
  33. });
  34. // Resize jsEditor and canvas when in mobile mode
  35. var jsEditor = document.getElementById('jsEditor');
  36. var canvasZone = document.getElementById('canvasZone');
  37. var navBar550 = document.getElementsByClassName('navBar550')[0];
  38. var reiszeBigJsEditor = function() {
  39. if(navBar550.offsetHeight > 0) {
  40. canvasZone.style.width = '40px';
  41. jsEditor.style.width = 'calc(100% - 40px)';
  42. }
  43. };
  44. var resizeBigCanvas = function() {
  45. if(navBar550.offsetHeight > 0) {
  46. jsEditor.style.width = '40px';
  47. canvasZone.style.width = 'calc(100% - 40px)';
  48. }
  49. };
  50. jsEditor.addEventListener('click', reiszeBigJsEditor);
  51. canvasZone.addEventListener('click', resizeBigCanvas);
  52. document.getElementById('runButton550').addEventListener('click', resizeBigCanvas);
  53. // Handle click on select elements
  54. for (var index = 0; index < allSelect.length; index++) {
  55. var s = allSelect[index];
  56. // Get child called to display
  57. var displayItems = function (e) {
  58. if (e.target.nodeName != "IMG") {
  59. e.preventDefault();
  60. e.stopPropagation();
  61. return;
  62. }
  63. var toDisplay = this.querySelector('.toDisplay');
  64. if (toDisplay) {
  65. if (toDisplay.style.display == 'block') {
  66. removeAllOptions();
  67. } else {
  68. removeAllOptions();
  69. toDisplay.style.display = 'block';
  70. }
  71. }
  72. toDisplay = this.querySelector('.toDisplayBig');
  73. if (toDisplay) {
  74. if (toDisplay.style.display == 'block') {
  75. removeAllOptions();
  76. } else {
  77. removeAllOptions();
  78. toDisplay.style.display = 'block';
  79. }
  80. }
  81. e.preventDefault();
  82. e.stopPropagation();
  83. }
  84. s.addEventListener('click', displayItems);
  85. }
  86. // Handle mouseover / click on subSelect
  87. var onSubselect = function (evt) {
  88. // If it's in mobile mode, avoid the "mouseenter" bug
  89. if(evt.type == "mouseenter" && navBar550.offsetHeight > 0) return;
  90. removeAllSubItems();
  91. var toDisplay = this.querySelector('.toDisplaySub');
  92. if (toDisplay)
  93. toDisplay.style.display = 'block';
  94. evt.preventDefault();
  95. evt.stopPropagation();
  96. };
  97. for (var index = 0; index < allSubSelect.length; index++) {
  98. var ss = allSubSelect[index];
  99. ss.addEventListener('click', onSubselect);
  100. ss.addEventListener('mouseenter', onSubselect);
  101. }
  102. for (var index = 0; index < allNoSubSelect.length; index++) {
  103. var ss = allNoSubSelect[index];
  104. ss.addEventListener('mouseenter', removeAllSubItems);
  105. }
  106. // Examples must remove all the other menus
  107. var examplesButton = document.getElementsByClassName("examplesButton");
  108. for (var i = 0; i < examplesButton.length; i++) {
  109. examplesButton[i].addEventListener("click", function () {
  110. removeAllOptions();
  111. });
  112. }
  113. // Handle click on subOptions
  114. clickOptionSub = function(evt) {
  115. evt.preventDefault();
  116. evt.stopPropagation();
  117. if(!navBar550.offsetHeight > 0) return; // If is not in mobile, this doesnt apply
  118. if(!this.classList) return;
  119. if (this.classList.contains('link')) {
  120. window.open(this.querySelector('a').href, '_new');
  121. }
  122. if (!this.classList.contains('subSelect') && this.parentNode.style.display == 'block') {
  123. this.parentNode.style.display = 'none'
  124. }
  125. }
  126. })();