Created
April 6, 2018 10:39
-
-
Save SilencerWeb/4ad54314ffec4d7f65a3b1cdf419721d to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var initEventListeners = function initEventListeners() { | |
addEventListener('.dropdown__header', 'click', slideDropdown); | |
addEventListener('.tabs__link', 'click', changeTab); | |
addEventListener('.form_subscribe', 'submit', handleSubscribeFormSubmit); | |
addEventListener('.form_buy-tokens', 'submit', handleBuyTokensFormSubmit); | |
addEventListener('.lang-nav__active', 'click', function (e) { | |
e.preventDefault(); | |
var langNav = e.target.closest('.lang-nav'); | |
langNav.classList.contains('lang-nav_opened') ? langNav.classList.remove('lang-nav_opened') : langNav.classList.add('lang-nav_opened'); | |
}); | |
addEventListener('.header__open-mobile-nav-btn', 'click', function (e) { | |
e.preventDefault(); | |
var body = document.querySelector('body'); | |
var mobileNav = document.querySelector('.mobile-nav'); | |
mobileNav.classList.add('mobile-nav_opened'); | |
body.style.overflow = 'hidden'; | |
}); | |
addEventListener(['.mobile-nav__close-btn', '.mobile-nav__main-nav a'], 'click', function (e) { | |
var body = document.querySelector('body'); | |
var mobileNav = document.querySelector('.mobile-nav'); | |
body.style.overflow = ''; | |
mobileNav.classList.remove('mobile-nav_opened'); | |
}); | |
addEventListener('.airdrop-button__close', 'click', function (e) { | |
e.preventDefault(); | |
document.querySelector('.airdrop-button').remove(); | |
}); | |
addEventListener('.tokens-guide__close', 'click', function (e) { | |
e.preventDefault(); | |
document.querySelector('.tokens-guide').remove(); | |
}); | |
addEventListener('.open-buy-tokens-modal', 'click', function (e) { | |
e.preventDefault(); | |
var isClient = Cookies.get('client'); | |
if (isClient) { | |
document.querySelector('body').style.overflow = 'hidden'; | |
document.querySelector('.overlay').classList.remove('overlay_hidden'); | |
document.querySelector('.modals-wrapper').classList.remove('modals-wrapper_hidden'); | |
document.querySelector('.modal_success').classList.remove('modal_hidden'); | |
} else { | |
document.querySelector('body').style.overflow = 'hidden'; | |
document.querySelector('.overlay').classList.remove('overlay_hidden'); | |
document.querySelector('.modals-wrapper').classList.remove('modals-wrapper_hidden'); | |
document.querySelector('.modal_buy-tokens').classList.remove('modal_hidden'); | |
} | |
checkVisibleModalHeight(); | |
gtag('event', 'buy-tokens', { 'event_category': 'user' }); | |
fbq('trackCustom', 'buy-tokens'); | |
}); | |
addEventListener('.modal_buy-tokens input[type="radio"]', 'change', function (e) { | |
e.preventDefault(); | |
var target = e.target; | |
if (target.value === 'over' && target.checked) { | |
target.closest('.form').classList.add('form_over'); | |
} else { | |
target.closest('.form').classList.remove('form_over'); | |
[].concat(_toConsumableArray(document.querySelectorAll('.modal_buy-tokens .form__personal-data .form__field'))).forEach(function (formField) { | |
formField.classList.remove('form__field_invalid'); | |
}); | |
[].concat(_toConsumableArray(document.querySelectorAll('.modal_buy-tokens .form__personal-data input'))).forEach(function (field) { | |
if (field.type === 'checkbox' || field.type === 'radio') { | |
if (field.type === 'radio' && field.value === 'less') { | |
field.checked = true; | |
} else { | |
field.checked = false; | |
} | |
field.removeEventListener('change', validateField); | |
} else { | |
field.value = ''; | |
field.removeEventListener('input', validateField); | |
} | |
}); | |
} | |
setTimeout(checkVisibleModalHeight, 50); | |
}); | |
addEventListener(['.modal__close', '.modal_success .btn_close'], 'click', function (e) { | |
e.preventDefault(); | |
var modal = e.target.closest('.modal'); | |
modal.classList.remove('modal_error'); | |
[].concat(_toConsumableArray(modal.querySelectorAll('.form__field'))).forEach(function (formField) { | |
formField.classList.remove('form__field_invalid'); | |
}); | |
[].concat(_toConsumableArray(modal.querySelectorAll('input'))).forEach(function (field) { | |
if (field.type === 'checkbox' || field.type === 'radio') { | |
if (field.type === 'radio' && field.value === 'less') { | |
field.checked = true; | |
} else { | |
field.checked = false; | |
} | |
field.removeEventListener('change', validateField); | |
} else { | |
if (field.id !== 'eth_address') { | |
field.value = ''; | |
field.removeEventListener('input', validateField); | |
} | |
} | |
}); | |
modal.querySelector('.form').classList.remove('form_over'); | |
document.querySelector('.modals-wrapper').classList.add('modals-wrapper_hidden'); | |
e.target.closest('.modal').classList.add('modal_hidden'); | |
document.querySelector('.overlay').classList.add('overlay_hidden'); | |
document.querySelector('body').style.overflow = ''; | |
}); | |
addEventListener(['.video__play', '.tokens-guide', '.intro__how-to'], 'click', function (e) { | |
e.preventDefault(); | |
if (e.target.classList.contains('tokens-guide__close')) return; | |
var target = e.target.closest('.tokens-guide') || e.target; | |
document.querySelector('#ytplayer').src = '' + target.dataset.video; | |
document.querySelector('body').style.overflow = 'hidden'; | |
document.querySelector('.overlay').classList.remove('overlay_hidden'); | |
document.querySelector('.video-modal-wrapper').classList.remove('video-modal-wrapper_hidden'); | |
}); | |
addEventListener('.video-modal__close', 'click', function (e) { | |
e.preventDefault(); | |
document.querySelector('#ytplayer').src = ''; | |
document.querySelector('body').style.overflow = ''; | |
document.querySelector('.overlay').classList.add('overlay_hidden'); | |
document.querySelector('.video-modal-wrapper').classList.add('video-modal-wrapper_hidden'); | |
}); | |
addEventListener('.modal_success .clipboard-btn', 'click', function (e) { | |
gtag('event', 'copy', { 'event_category': 'user' }); | |
fbq('trackCustom', 'copy'); | |
}); | |
window.onscroll = function (e) { | |
var header = document.querySelector('.header'); | |
if (window.pageYOffset > header.offsetHeight) { | |
header.classList.add('header_hidden'); | |
if (!header.classList.contains('header_sticky')) { | |
setTimeout(function () { | |
header.classList.add('header_sticky'); | |
}, 50); | |
} | |
} else { | |
header.classList.remove('header_sticky'); | |
if (header.classList.contains('header_hidden')) { | |
setTimeout(function () { | |
header.classList.remove('header_hidden'); | |
}, 50); | |
} | |
} | |
}; | |
document.addEventListener('click', function (e) { | |
var langNav = e.target.closest('.lang-nav'); | |
if (!langNav) { | |
document.querySelectorAll('.lang-nav').forEach(function (langNav) { | |
langNav.classList.remove('lang-nav_opened'); | |
}); | |
} | |
}); | |
onWindowResize(function () { | |
initAdvantagesSliders(); | |
initPeopleSliders(); | |
checkVisibleModalHeight(); | |
checkVideoModalHeight(); | |
}); | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment