main.js 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160
  1. window.addEventListener("load", function(event) {
  2. // Main SLider
  3. // Set height price block
  4. let priceBlockWrapper = document.querySelector('.price-block__slider');
  5. if(document.querySelector('.price-block__list--slider')) {
  6. let priceListHeight = document.querySelector('.price-block__list--slider').offsetHeight;
  7. priceBlockWrapper.style.height = priceListHeight + "px";
  8. }
  9. // Set height price block
  10. let allButtonsWrapper = document.querySelectorAll('.js-arrow');
  11. allButtonsWrapper.forEach(itemWrapper => {
  12. let wrapper = itemWrapper.closest('.slider');
  13. let allButtons = wrapper.querySelectorAll('.js-button-slider');
  14. let allItems = wrapper.querySelectorAll('.js-item-slider');
  15. let arrowNext = wrapper.querySelector('.js-arrow-slider-next');
  16. let arrowPrev = wrapper.querySelector('.js-arrow-slider-prev');
  17. if(arrowNext) {
  18. arrowNext.addEventListener('click', function(){
  19. let arctiveButton = wrapper.querySelector('.js-button-slider.active');
  20. if(arctiveButton.nextElementSibling.classList.contains('js-button-slider')) {
  21. arctiveButton.nextElementSibling.click();
  22. }else {
  23. wrapper.querySelector(".js-button-slider[data-index='1']").click();
  24. }
  25. });
  26. arrowPrev.addEventListener('click', function(){
  27. let arctiveButton = wrapper.querySelector('.js-button-slider.active');
  28. if(arctiveButton.previousElementSibling != null) {
  29. arctiveButton.previousElementSibling.click();
  30. }else {
  31. wrapper.querySelector(`.js-button-slider[data-index='${allButtons.length}']`).click();
  32. }
  33. });
  34. }
  35. allButtons.forEach(itemButton => {
  36. itemButton.addEventListener('click', function(){
  37. let dataIndex = itemButton.dataset.index;
  38. allButtons.forEach(item => {
  39. item.classList.remove('active');
  40. });
  41. allItems.forEach(item => {
  42. item.classList.remove('show');
  43. });
  44. this.classList.add('active');
  45. let activeElem = wrapper.querySelector(`.js-item-slider[data-index="${dataIndex}"]`);
  46. if(activeElem.classList.contains("price-block__list--slider")) {
  47. let heightBlock = activeElem.offsetHeight;
  48. priceBlockWrapper.style.height = heightBlock + "px";
  49. }
  50. activeElem.classList.add('show');
  51. });
  52. });
  53. });
  54. // /Main SLider
  55. // Popup
  56. let mainButton = document.querySelectorAll('.js-button');
  57. let overlay = document.querySelector('.overlay');
  58. let htmlOverflow = document.querySelector('html');
  59. for(var i = 0; mainButton.length > i; i++) {
  60. if(mainButton[i] !== null) {
  61. mainButton[i].addEventListener('click', function(){
  62. let getData = this.getAttribute('data-target');
  63. let popup = document.querySelector('.js-popup[data-target = ' + getData + ']');
  64. popup.classList.add('active');
  65. overlay.classList.add('active');
  66. htmlOverflow.classList.add('overflow');
  67. });
  68. }
  69. }
  70. document.addEventListener('click', function(e){
  71. let elem = e.target;
  72. if(elem.closest('.js-close')){
  73. let popupActive = document.querySelector('.js-popup.active');
  74. if(popupActive) {
  75. popupActive.classList.remove('active');
  76. overlay.classList.remove('active');
  77. htmlOverflow.classList.remove('overflow');
  78. }
  79. }
  80. });
  81. overlay.addEventListener('click', function(){
  82. let popupActive = document.querySelector('.js-popup.active');
  83. popupActive.classList.remove('active');
  84. overlay.classList.remove('active');
  85. htmlOverflow.classList.remove('overflow');
  86. });
  87. // //Popup
  88. // Check call back form
  89. let callBackButton = document.querySelector('.js-button-call-back');
  90. callBackButton.addEventListener('click', function() {
  91. let thanksPopup = document.querySelector('.js-call-back-popup');
  92. let callBackform = this.closest('.js-call-back-form');
  93. let callbackEmail = callBackform.querySelector('.js-call-back-email');
  94. let callbackEmailValue = callbackEmail.value;
  95. let chekEmail = callbackEmailValue.match(/@/);
  96. if(chekEmail && callbackEmailValue != "") {
  97. callbackEmail.classList.remove('error');
  98. thanksPopup.classList.add('active');
  99. overlay.classList.add('active');
  100. htmlOverflow.classList.add('overflow');
  101. }else {
  102. callbackEmail.classList.add('error');
  103. }
  104. });
  105. // //Check call back form
  106. // Staff block
  107. let staffWrapper = document.querySelector('.js-staff');
  108. let staffButton = document.querySelector('.js-button-staff');
  109. let allSraffItemsLength = document.querySelectorAll('.our-staff__item').length;
  110. if(staffWrapper) {
  111. if(allSraffItemsLength > 9 ) {
  112. staffButton.classList.add('show');
  113. }
  114. staffButton.addEventListener('click', function(){
  115. staffWrapper.classList.toggle('active');
  116. });
  117. }
  118. // Staff block
  119. });